-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
153 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import * as Eff from 'effect' | ||
import * as React from 'react' | ||
|
||
import * as Assistant from 'components/Assistant' | ||
import * as XML from 'utils/XML' | ||
|
||
import type { BucketListingResult } from './requests' | ||
|
||
export function useListingContext(data: $TSFixMe) { | ||
const msg = React.useMemo( | ||
() => | ||
Eff.pipe( | ||
data.case({ | ||
Ok: (res: BucketListingResult) => Eff.Option.some(Eff.Either.right(res)), | ||
Err: () => Eff.Option.some(Eff.Either.left('Error fetching listing data')), | ||
_: () => Eff.Option.none(), | ||
}) as Eff.Option.Option<Eff.Either.Either<BucketListingResult, string>>, | ||
Eff.Option.map( | ||
Eff.Either.match({ | ||
onLeft: (err) => [err], | ||
onRight: (res) => [ | ||
res.truncated ? 'The listing is truncated' : null, | ||
res.dirs.length ? XML.tag('prefixes', {}, ...res.dirs) : null, | ||
res.files.length | ||
? XML.tag( | ||
'objects', | ||
{}, | ||
...res.files.map((o) => | ||
JSON.stringify({ | ||
key: o.key, | ||
size: o.size, | ||
modified: o.modified.toISOString(), | ||
}), | ||
), | ||
) | ||
: null, | ||
], | ||
}), | ||
), | ||
Eff.Option.map((children: XML.Children) => | ||
XML.tag('listing-data', {}, ...children).toString(), | ||
), | ||
), | ||
[data], | ||
) | ||
|
||
Assistant.Context.usePushContext({ | ||
markers: { listingReady: Eff.Option.isSome(msg) }, | ||
messages: Eff.Option.toArray(msg), | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters