implemented identity, updated session, added 'workings' list
added paginated querying, added 'common'
This commit is contained in:
parent
027deba422
commit
6ada519e06
36 changed files with 1422 additions and 279 deletions
|
|
@ -1,3 +1,52 @@
|
|||
// interface UseIdentityProps {}
|
||||
import { ApolloError, ApolloQueryResult, gql, OperationVariables, useQuery } from '@apollo/client';
|
||||
import { Identity, IdentityRootQuery } from '@generated/types';
|
||||
import { createContext, useContext } from 'react';
|
||||
|
||||
// export function useIdentity(props: UseIdentityProps) {}
|
||||
export interface IdentityContext {
|
||||
data: Identity;
|
||||
refetch: () => void;
|
||||
}
|
||||
|
||||
export const IdentityContext = createContext<IdentityContext | null>(null);
|
||||
export const IdentityProvider = IdentityContext.Provider;
|
||||
|
||||
export function useIdentity(): IdentityContext | null {
|
||||
const identityContext = useContext(IdentityContext);
|
||||
if (identityContext == null) return null;
|
||||
return identityContext;
|
||||
}
|
||||
|
||||
export function useIdentityQuery({ skip }: { skip?: boolean }): {
|
||||
data: IdentityRootQuery | undefined;
|
||||
loading: boolean;
|
||||
error: ApolloError | undefined;
|
||||
refetch: (
|
||||
variables?: Partial<OperationVariables> | undefined
|
||||
) => Promise<ApolloQueryResult<IdentityRootQuery>>;
|
||||
} {
|
||||
const { data, loading, error, refetch } = useQuery<IdentityRootQuery>(query, {
|
||||
skip
|
||||
});
|
||||
return {
|
||||
data,
|
||||
loading,
|
||||
error,
|
||||
refetch
|
||||
};
|
||||
}
|
||||
|
||||
const query = gql`
|
||||
query IdentityRoot {
|
||||
identity {
|
||||
id
|
||||
email
|
||||
isDarkTheme
|
||||
user {
|
||||
id
|
||||
username
|
||||
createdAt
|
||||
updatedAt
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue