Skip to content

Commit 93f85b3

Browse files
committed
update after some feedbacks
1 parent 78946f8 commit 93f85b3

File tree

7 files changed

+168
-96
lines changed

7 files changed

+168
-96
lines changed

src/app/Document.tsx

+6-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
77

88
import { Providers } from '@/app/Providers';
99
import { Viewport } from '@/components/Viewport';
10-
import { EnvHint } from '@/features/devtools/EnvHint';
10+
import { env } from '@/env.mjs';
11+
import { AppHint } from '@/features/devtools/AppHint';
1112
import { useLocale } from '@/lib/i18n/useLocale';
1213
import { TrpcProvider } from '@/lib/trpc/TrpcProvider';
1314
import theme, { COLOR_MODE_STORAGE_KEY } from '@/theme';
@@ -65,8 +66,10 @@ export const Document = ({ children }: { children: ReactNode }) => {
6566
<Providers>
6667
<TrpcProvider>
6768
<Viewport>{children}</Viewport>
68-
<EnvHint />
69-
<ReactQueryDevtools initialIsOpen={false} />
69+
<AppHint />
70+
{env.NEXT_PUBLIC_DEV_TOOLS_ENABLED && (
71+
<ReactQueryDevtools initialIsOpen={false} />
72+
)}
7073
</TrpcProvider>
7174
</Providers>
7275
</body>

src/app/layout.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Metadata } from 'next';
44

55
import { Document } from '@/app/Document';
66
import { NextLoader } from '@/app/NextLoader';
7-
import { getEnvHintTitlePrefix } from '@/features/devtools/EnvHint';
7+
import { getEnvHintTitlePrefix } from '@/features/devtools/AppHint';
88

99
export const metadata: Metadata = {
1010
title: {

src/env.mjs

+11
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ export const env = createEnv({
6262
value ??
6363
(process.env.NODE_ENV === 'development' ? 'warning' : 'success')
6464
),
65+
NEXT_PUBLIC_DEV_TOOLS_ENABLED: z
66+
.enum(['true', 'false'])
67+
.optional()
68+
.transform((value) => {
69+
if (value) {
70+
return value === 'true';
71+
}
72+
73+
return process.env.NODE_ENV === 'development' ? true : false;
74+
}),
6575
NEXT_PUBLIC_NODE_ENV: zNodeEnv(),
6676
},
6777

@@ -83,6 +93,7 @@ export const env = createEnv({
8393
NEXT_PUBLIC_ENV_COLOR_SCHEME: process.env.NEXT_PUBLIC_ENV_COLOR_SCHEME,
8494
NEXT_PUBLIC_ENV_NAME: process.env.NEXT_PUBLIC_ENV_NAME,
8595
NEXT_PUBLIC_ENV_EMOJI: process.env.NEXT_PUBLIC_ENV_EMOJI,
96+
NEXT_PUBLIC_DEV_TOOLS_ENABLED: process.env.NEXT_PUBLIC_DEV_TOOLS_ENABLED,
8697
NEXT_PUBLIC_IS_DEMO: process.env.NEXT_PUBLIC_IS_DEMO,
8798
NEXT_PUBLIC_NODE_ENV: process.env.NODE_ENV,
8899
},

src/features/devtools/AppHint.tsx

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import { Box, HStack, Text, useDisclosure } from '@chakra-ui/react';
2+
import { LuPencilRuler } from 'react-icons/lu';
3+
4+
import { env } from '@/env.mjs';
5+
import { DevToolsDrawer } from '@/features/devtools/DevToolsDrawer';
6+
7+
export const getEnvHintTitlePrefix = () => {
8+
if (env.NEXT_PUBLIC_ENV_EMOJI) return `${env.NEXT_PUBLIC_ENV_EMOJI} `;
9+
if (env.NEXT_PUBLIC_ENV_NAME) return `[${env.NEXT_PUBLIC_ENV_NAME}] `;
10+
return '';
11+
};
12+
13+
export const AppHint = () => {
14+
if (!env.NEXT_PUBLIC_ENV_NAME && !env.NEXT_PUBLIC_DEV_TOOLS_ENABLED) {
15+
return null;
16+
}
17+
18+
return (
19+
<Box
20+
zIndex="9999"
21+
position="fixed"
22+
top="0"
23+
insetStart="0"
24+
insetEnd="0"
25+
h="2px"
26+
bg={`${env.NEXT_PUBLIC_ENV_COLOR_SCHEME}.400`}
27+
>
28+
<HStack
29+
position="fixed"
30+
top="0"
31+
insetStart="4"
32+
fontSize="0.6rem"
33+
fontWeight="bold"
34+
alignItems="start"
35+
>
36+
{env.NEXT_PUBLIC_ENV_NAME && <EnvHint />}
37+
{env.NEXT_PUBLIC_DEV_TOOLS_ENABLED && <DevToolsHint />}
38+
</HStack>
39+
</Box>
40+
);
41+
};
42+
43+
const EnvHint = () => {
44+
return (
45+
<Text
46+
bg={`${env.NEXT_PUBLIC_ENV_COLOR_SCHEME}.400`}
47+
color={`${env.NEXT_PUBLIC_ENV_COLOR_SCHEME}.900`}
48+
px="1"
49+
borderBottomStartRadius="sm"
50+
borderBottomEndRadius="sm"
51+
textTransform="uppercase"
52+
>
53+
{env.NEXT_PUBLIC_ENV_NAME}
54+
</Text>
55+
);
56+
};
57+
const DevToolsHint = () => {
58+
const devToolsDrawer = useDisclosure();
59+
60+
return (
61+
<>
62+
<Text
63+
as="button"
64+
onClick={devToolsDrawer.onToggle}
65+
bg={`${env.NEXT_PUBLIC_ENV_COLOR_SCHEME}.400`}
66+
color={`${env.NEXT_PUBLIC_ENV_COLOR_SCHEME}.900`}
67+
px="1"
68+
py="0.5"
69+
borderBottomStartRadius="sm"
70+
borderBottomEndRadius="sm"
71+
textTransform="uppercase"
72+
>
73+
<LuPencilRuler />
74+
</Text>
75+
<DevToolsDrawer disclosure={devToolsDrawer} />
76+
</>
77+
);
78+
};
+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
'use client';
2+
3+
import {
4+
Checkbox,
5+
Drawer,
6+
DrawerBody,
7+
DrawerCloseButton,
8+
DrawerContent,
9+
DrawerHeader,
10+
FormControl,
11+
FormLabel,
12+
Radio,
13+
RadioGroup,
14+
Stack,
15+
Wrap,
16+
useColorMode,
17+
useDisclosure,
18+
} from '@chakra-ui/react';
19+
import { useTranslation } from 'react-i18next';
20+
21+
import { AVAILABLE_LANGUAGES } from '@/lib/i18n/constants';
22+
23+
export const DevToolsDrawer = ({
24+
disclosure,
25+
}: {
26+
disclosure: ReturnType<typeof useDisclosure>;
27+
}) => {
28+
const { colorMode, setColorMode } = useColorMode();
29+
30+
const { t, i18n } = useTranslation(['common']);
31+
32+
return (
33+
<Drawer
34+
onClose={disclosure.onClose}
35+
isOpen={disclosure.isOpen}
36+
size="xs"
37+
placement="left"
38+
>
39+
<DrawerContent>
40+
<DrawerCloseButton />
41+
<DrawerHeader>Development panel</DrawerHeader>
42+
<DrawerBody>
43+
<Stack spacing={6}>
44+
<Checkbox
45+
isChecked={colorMode === 'dark'}
46+
onChange={(e) =>
47+
setColorMode(e.target.checked ? 'dark' : 'light')
48+
}
49+
>
50+
Dark mode
51+
</Checkbox>
52+
<FormControl>
53+
<FormLabel>Language</FormLabel>
54+
<RadioGroup
55+
value={i18n.language}
56+
onChange={(newValue) => i18n.changeLanguage(newValue)}
57+
>
58+
<Wrap spacing={4}>
59+
{AVAILABLE_LANGUAGES.map((language) => (
60+
<Radio key={language.key} value={language.key}>
61+
{t(`common:languages.${language.key}`)}
62+
</Radio>
63+
))}
64+
</Wrap>
65+
</RadioGroup>
66+
</FormControl>
67+
</Stack>
68+
</DrawerBody>
69+
</DrawerContent>
70+
</Drawer>
71+
);
72+
};

src/features/devtools/EnvHint.tsx

-52
This file was deleted.

src/features/devtools/EnvHintDevPopover.tsx

-40
This file was deleted.

0 commit comments

Comments
 (0)