-
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
1 parent
610de48
commit 8d3ea71
Showing
109 changed files
with
664 additions
and
563 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
12 changes: 2 additions & 10 deletions
12
src/providers/auth-provider.tsx → src/context/auth-provider.tsx
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
File renamed without changes.
File renamed without changes.
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,95 @@ | ||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
import { Dispatch, SetStateAction, createContext } from 'react' | ||
import { | ||
addRecipe, | ||
addRecipeVariables, | ||
NotificationCount, | ||
RecipeInput, | ||
RecipeFilter, | ||
Sort, | ||
Me_me_data, | ||
} from '@greeneggs/types/graphql' | ||
import { ISteps } from '@greeneggs/screens/add-recipe/use-steps' | ||
import { IForm } from '@greeneggs/ui/form' | ||
import { UseFieldArrayReturn } from 'react-hook-form' | ||
import { ApolloQueryResult, OperationVariables } from '@apollo/client' | ||
|
||
export type Token = string | undefined | null | ||
export type SetToken = Dispatch<SetStateAction<Token>> | undefined | ||
export interface AddRecipeContextInterface { | ||
form?: IForm<RecipeInput, addRecipe, addRecipeVariables> | ||
steps?: ISteps | ||
categoriesFieldArray?: UseFieldArrayReturn<RecipeInput, 'categories', 'id'> | ||
ingredientsFieldArray?: UseFieldArrayReturn<RecipeInput, 'ingredients', 'id'> | ||
stepsFieldArray?: UseFieldArrayReturn<RecipeInput, 'steps', 'id'> | ||
allergiesFieldArray?: UseFieldArrayReturn<RecipeInput, 'allergies', 'id'> | ||
dietsFieldArray?: UseFieldArrayReturn<RecipeInput, 'diets', 'id'> | ||
} | ||
|
||
export interface NotificationState { | ||
unreadCount: number | ||
} | ||
|
||
export const defaultNotificationState: NotificationState = { | ||
unreadCount: 0, | ||
} | ||
|
||
export interface NotificationContextInterface { | ||
notificationState: NotificationState | ||
setNotificationState?: (notificationState: NotificationState) => void | ||
refetchNotificationState?: ( | ||
variables?: Partial<OperationVariables> | undefined | ||
) => Promise<ApolloQueryResult<NotificationCount>> | ||
} | ||
|
||
export interface SearchState { | ||
query?: string | ||
filter: RecipeFilter | ||
sort: Sort | ||
} | ||
|
||
export type Me = Me_me_data | undefined | ||
export type SetMe = ((me: Me) => void) | undefined | ||
|
||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
export const UserContext = createContext({ | ||
me: undefined as Me, | ||
setMe: undefined as SetMe, | ||
}) | ||
|
||
export const defaultSearchState: SearchState = { | ||
query: undefined, | ||
filter: { | ||
ingredients: undefined, | ||
categories: undefined, | ||
allergies: undefined, | ||
diets: undefined, | ||
cookTime: undefined, | ||
user: undefined, | ||
}, | ||
sort: Sort.RELEVANT, | ||
} | ||
|
||
export interface ISearchContext { | ||
searchState: SearchState | ||
setSearchState?: (searchState: SearchState) => void | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
export const SearchContext = createContext<ISearchContext>({ | ||
searchState: defaultSearchState, | ||
setSearchState: undefined, | ||
}) | ||
|
||
export const NotificationContext = createContext<NotificationContextInterface>({ | ||
notificationState: defaultNotificationState, | ||
setNotificationState: undefined, | ||
refetchNotificationState: undefined, | ||
}) | ||
|
||
export const AddRecipeContext = createContext<AddRecipeContextInterface>({}) | ||
|
||
export const AuthContext = createContext({ | ||
token: undefined as Token, | ||
setToken: undefined as SetToken, | ||
}) |
28 changes: 3 additions & 25 deletions
28
...providers/notification-state-provider.tsx → src/context/notification-state-provider.tsx
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,13 @@ | ||
/** | ||
* Author: Edward Jones | ||
*/ | ||
import React, { useState, PropsWithChildren } from 'react' | ||
import { defaultSearchState, SearchContext, SearchState } from './index' | ||
/** | ||
* Provider that lets all child components access the search state, including query, sorting and filtering. | ||
*/ | ||
export function SearchStateProvider({ children }: PropsWithChildren<object>) { | ||
const [searchState, setSearchState] = useState<SearchState>(defaultSearchState) | ||
|
||
return <SearchContext.Provider value={{ searchState, setSearchState }}>{children}</SearchContext.Provider> | ||
} |
14 changes: 3 additions & 11 deletions
14
src/providers/user-state-provider.tsx → src/context/user-state-provider.tsx
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 was deleted.
Oops, something went wrong.
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.