Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: basic recoil dev tools #1061

Merged
merged 1 commit into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions frontend/src/components/RecoilDevTools/RecoilDevTools.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { useRecoilCallback } from 'recoil';
import Icon from '../icons/Icon';
import Button from '../Primitives/Button';

const RecoilDevTools = () => {
const getAtomValues = async (snapshot: any) => {
// eslint-disable-next-line no-console
console.log('Atom Values:');
const state: any = {};
// eslint-disable-next-line no-restricted-syntax
for (const node of snapshot.getNodes_UNSTABLE()) {
// eslint-disable-next-line no-await-in-loop
const value = await snapshot.getPromise(node);
state[node.key] = value;
}
// eslint-disable-next-line no-console
console.log(state);
};

const dumpRecoilState = useRecoilCallback(
({ snapshot }) =>
async () =>
getAtomValues(snapshot),
[],
);

return (
<Button
isIcon
css={{ position: 'fixed', bottom: '$58', left: '$12' }}
size="lg"
onClick={dumpRecoilState}
>
<Icon name="settings" css={{ color: '$secondaryDark' }} />
</Button>
);
};

export default RecoilDevTools;
4 changes: 3 additions & 1 deletion frontend/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import globalStyles from '@/styles/globals';

import Sprite from '@/components/icons/Sprite';
import Toast, { ToastProvider, ToastViewport } from '@/components/Primitives/Toast';
import { JWT_EXPIRATION_TIME } from '@/utils/constants';
import { JWT_EXPIRATION_TIME, RECOIL_DEV_TOOLS } from '@/utils/constants';
import { ROUTES } from '@/utils/routes';
import { Session } from 'next-auth';
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
import RecoilDevTools from '@/components/RecoilDevTools/RecoilDevTools';

type NextPageWithLayout<P = {}, IP = P> = NextPage<P, IP> & {
getLayout?: (page: ReactElement) => ReactNode;
Expand Down Expand Up @@ -56,6 +57,7 @@ function Root({
<RecoilRoot>
{getLayout(<Component {...pageProps} />)}
<Toast />
{RECOIL_DEV_TOOLS && <RecoilDevTools />}
</RecoilRoot>
<ToastViewport
css={{
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export const REFRESH_TOKEN_ERROR = 'REFRESH_TOKEN_ERROR';

export const MIN_MEMBERS = 4;

export const RECOIL_DEV_TOOLS = true;

// -------------------------------

export const ONE_SECOND = 1000;
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.