-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Apps query client connection and save calculation action (#82)
* feat: connect to graasp-app-api * feat: save calc action on equality * fix: setup api for cypress tests to add appcontext and databse * fix: use sdk factories for member and item * fix: add default values for setupApi cy command for db and app context
- Loading branch information
Showing
15 changed files
with
386 additions
and
20 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,11 @@ | ||
import { Member, MemberFactory } from '@graasp/sdk'; | ||
|
||
const ANNA = MemberFactory({ name: 'anna', email: '[email protected]' }); | ||
const BOB = MemberFactory({ name: 'bob', email: '[email protected]' }); | ||
|
||
export const MEMBERS: { [key: string]: Member } = { | ||
ANNA, | ||
BOB, | ||
}; | ||
|
||
export const CURRENT_MEMBER = MEMBERS.ANNA; |
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,7 @@ | ||
import { AppItemFactory } from '@graasp/sdk'; | ||
import { MEMBERS } from './members'; | ||
|
||
export const MOCK_APP_ITEM = AppItemFactory({ | ||
name: 'calc1', | ||
creator: MEMBERS.ANNA, | ||
}); |
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,11 @@ | ||
declare global { | ||
interface Window { | ||
appContext: LocalContext; | ||
Cypress: boolean; | ||
database: Database; | ||
apiErrors: object; | ||
katex: katex; | ||
} | ||
} | ||
|
||
export {}; |
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,18 +1,57 @@ | ||
import { I18nextProvider } from 'react-i18next'; | ||
import { ThemeProvider } from '@mui/material/styles'; | ||
import { ToastContainer } from 'react-toastify'; | ||
import { theme } from '@graasp/ui'; | ||
import { Loader, theme } from '@graasp/ui'; | ||
import 'react-toastify/dist/ReactToastify.css'; | ||
import { | ||
GraaspContextDevTool, | ||
WithLocalContext, | ||
WithTokenContext, | ||
useObjectState, | ||
} from '@graasp/apps-query-client'; | ||
import { QueryClientProvider, hooks, queryClient } from '@/config/queryClient'; | ||
import { defaultMockContext, mockMembers } from '@/mocks/db'; | ||
import i18nConfig from '../config/i18n'; | ||
import App from './App'; | ||
|
||
const Root = (): JSX.Element => ( | ||
<ThemeProvider theme={theme}> | ||
<I18nextProvider i18n={i18nConfig}> | ||
<App /> | ||
<ToastContainer /> | ||
</I18nextProvider> | ||
</ThemeProvider> | ||
); | ||
const Root = (): JSX.Element => { | ||
const [mockContext, setMockContext] = useObjectState(defaultMockContext); | ||
|
||
return ( | ||
<ThemeProvider theme={theme}> | ||
<I18nextProvider i18n={i18nConfig}> | ||
<QueryClientProvider client={queryClient}> | ||
<ToastContainer /> | ||
<WithLocalContext | ||
defaultValue={window.Cypress ? window.appContext : mockContext} | ||
LoadingComponent={<Loader />} | ||
useGetLocalContext={hooks.useGetLocalContext} | ||
useAutoResize={hooks.useAutoResize} | ||
onError={(e) => { | ||
console.error('An error occurred while fetching the context.', e); | ||
}} | ||
> | ||
<WithTokenContext | ||
LoadingComponent={<Loader />} | ||
useAuthToken={hooks.useAuthToken} | ||
onError={() => { | ||
console.error('An error occurred while requesting the token.'); | ||
}} | ||
> | ||
<App /> | ||
{import.meta.env.DEV && ( | ||
<GraaspContextDevTool | ||
members={mockMembers} | ||
context={mockContext} | ||
setContext={setMockContext} | ||
/> | ||
)} | ||
</WithTokenContext> | ||
</WithLocalContext> | ||
</QueryClientProvider> | ||
</I18nextProvider> | ||
</ThemeProvider> | ||
); | ||
}; | ||
|
||
export default Root; |
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,29 @@ | ||
import { configureQueryClient } from '@graasp/apps-query-client'; | ||
|
||
import { API_HOST, GRAASP_APP_KEY, MOCK_API } from './env'; | ||
|
||
const { | ||
queryClient, | ||
QueryClientProvider, | ||
hooks, | ||
API_ROUTES, | ||
mutations, | ||
ReactQueryDevtools, | ||
} = configureQueryClient({ | ||
API_HOST, | ||
refetchOnWindowFocus: !import.meta.env.DEV, | ||
keepPreviousData: true, | ||
// avoid refetching when same data are closely fetched | ||
staleTime: 1000, // ms | ||
GRAASP_APP_KEY, | ||
isStandalone: MOCK_API, | ||
}); | ||
|
||
export { | ||
ReactQueryDevtools, | ||
queryClient, | ||
QueryClientProvider, | ||
hooks, | ||
mutations, | ||
API_ROUTES, | ||
}; |
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.