-
Notifications
You must be signed in to change notification settings - Fork 0
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
50 changed files
with
1,551 additions
and
694 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
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,33 @@ | ||
// TODO: straight copy of the same file in the UI package | ||
import { Locale, useLocation } from '@custom/schema'; | ||
|
||
const locales = Object.values(Locale); | ||
export const defaultLocale: Locale = 'en'; | ||
|
||
export function isLocale(input: any): input is Locale { | ||
return locales.includes(input); | ||
} | ||
|
||
/** | ||
* Extract the current locale from the path prefix. | ||
*/ | ||
export function useLocale() { | ||
const [{ pathname }] = useLocation(); | ||
const prefix = pathname.split('/')[1]; | ||
return isLocale(prefix) ? prefix : defaultLocale; | ||
} | ||
|
||
type Localized = { locale: Locale }; | ||
|
||
/** | ||
* Select the most appropriate of localization from a list of options. | ||
*/ | ||
export function useLocalized<T extends Localized>( | ||
options?: Array<T | undefined>, | ||
): T | undefined { | ||
const locale = useLocale(); | ||
return ( | ||
options?.filter((option) => option?.locale === locale).pop() || | ||
options?.filter((option) => option?.locale === defaultLocale).pop() | ||
); | ||
} |
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 |
---|---|---|
@@ -1,48 +1,8 @@ | ||
import { | ||
OperationExecutor as UntypedOperationExecutor, | ||
useExecutor as untypedUseExecutor, | ||
} from '@amazeelabs/executors'; | ||
import { PropsWithChildren } from 'react'; | ||
|
||
import type { | ||
export * from './generated/index.js'; | ||
export * from '@amazeelabs/scalars'; | ||
export * from '@amazeelabs/executors'; | ||
export type { | ||
AnyOperationId, | ||
OperationResult, | ||
OperationVariables, | ||
} from './generated/index.js'; | ||
|
||
export * from './generated/index.js'; | ||
export * from '@amazeelabs/scalars'; | ||
|
||
export * from './locale.js'; | ||
|
||
type Executor<OperationId extends AnyOperationId> = | ||
| OperationResult<OperationId> | ||
| (( | ||
id: OperationId, | ||
variables: OperationVariables<OperationId>, | ||
) => OperationResult<OperationId> | Promise<OperationResult<OperationId>>); | ||
|
||
type VariablesMatcher<OperationId extends AnyOperationId> = | ||
| Partial<OperationVariables<OperationId>> | ||
| ((vars: OperationVariables<OperationId>) => boolean); | ||
|
||
export function OperationExecutor<OperationId extends AnyOperationId>( | ||
props: PropsWithChildren<{ | ||
id?: OperationId; | ||
variables?: VariablesMatcher<OperationVariables<OperationId>>; | ||
executor: Executor<OperationId>; | ||
}>, | ||
) { | ||
return UntypedOperationExecutor(props); | ||
} | ||
|
||
export function useExecutor<OperationId extends AnyOperationId>( | ||
id: OperationId, | ||
variables?: OperationVariables<OperationId>, | ||
): | ||
| OperationResult<OperationId> | ||
| (( | ||
variables?: OperationVariables<OperationId>, | ||
) => Promise<OperationResult<OperationId>>) { | ||
return untypedUseExecutor(id, variables); | ||
} | ||
} from '@amazeelabs/codegen-operation-ids'; |
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
Oops, something went wrong.