-
Notifications
You must be signed in to change notification settings - Fork 2
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
1 parent
d5c38a8
commit acf7461
Showing
8 changed files
with
108 additions
and
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { fetchQuery, graphql } from "@flowdev/relay"; | ||
import { useAsyncLoader } from "../useAsyncLoader"; | ||
import { environment } from "../relay/environment"; | ||
import { getStoreUtilsGetQuery } from "../relay/__generated__/getStoreUtilsGetQuery.graphql"; | ||
|
||
export const getStoreUtils = (defaultSlug: string) => { | ||
/** The pluginSlug is optional. You can pass `null` if you want to get an item from flow (e.g. theme). */ | ||
const get = async (keys?: string[], pluginSlug?: string | null) => { | ||
const data = await fetchQuery<getStoreUtilsGetQuery>( | ||
environment, | ||
graphql` | ||
query getStoreUtilsGetQuery($input: QueryStoreItemsInput!) { | ||
storeItems(input: $input) { | ||
key | ||
value | ||
} | ||
} | ||
`, | ||
{ | ||
input: { | ||
keys, | ||
pluginSlug: pluginSlug === undefined ? defaultSlug : pluginSlug, | ||
}, | ||
} | ||
).toPromise(); | ||
return Object.fromEntries(data?.storeItems.map((item) => [item.key, item.value]) ?? []); | ||
}; | ||
|
||
return { | ||
get, | ||
useStore: (keys?: string[], pluginSlug?: string) => { | ||
return useAsyncLoader(async () => { | ||
return get(keys, pluginSlug); | ||
}); | ||
}, | ||
}; | ||
}; |
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