tangled
alpha
login
or
join now
cosmik.network
/
semble
43
fork
atom
A social knowledge tool for researchers built on ATProto
43
fork
atom
overview
issues
13
pulls
pipelines
feat: dark mode
Pouria Delfanazari
4 months ago
09debb9d
2465984c
+52
-11
2 changed files
expand all
collapse all
unified
split
src
webapp
features
profile
components
profileMenu
ProfileMenu.tsx
providers
mantine.tsx
+51
-10
src/webapp/features/profile/components/profileMenu/ProfileMenu.tsx
···
6
6
Menu,
7
7
Image,
8
8
Button,
9
9
+
useMantineColorScheme,
10
10
+
useComputedColorScheme,
9
11
} from '@mantine/core';
10
12
import useMyProfile from '../../lib/queries/useMyProfile';
11
13
import CosmikLogo from '@/assets/cosmik-logo-full.svg';
12
14
import CosmikLogoWhite from '@/assets/cosmik-logo-full-white.svg';
13
13
-
import { MdBugReport } from 'react-icons/md';
15
15
+
import {
16
16
+
MdBugReport,
17
17
+
MdDarkMode,
18
18
+
MdLightMode,
19
19
+
MdAutoAwesome,
20
20
+
} from 'react-icons/md';
14
21
import { useAuth } from '@/hooks/useAuth';
15
22
import { useRouter } from 'next/navigation';
16
23
import Link from 'next/link';
17
24
import { IoMdLogOut } from 'react-icons/io';
18
25
import { useNavbarContext } from '@/providers/navbar';
19
26
import { BiSolidUserCircle } from 'react-icons/bi';
20
20
-
import { useColorScheme } from '@mantine/hooks';
21
27
22
28
export default function ProfileMenu() {
23
29
const router = useRouter();
24
24
-
const colorScheme = useColorScheme();
25
30
const { toggleMobile } = useNavbarContext();
26
31
const { data, error, isPending } = useMyProfile();
27
32
const { logout } = useAuth();
33
33
+
34
34
+
const { colorScheme, setColorScheme } = useMantineColorScheme();
35
35
+
const computedColorScheme = useComputedColorScheme('light', {
36
36
+
getInitialValueInEffect: true,
37
37
+
});
28
38
29
39
const handleLogout = async () => {
30
40
try {
···
35
45
}
36
46
};
37
47
48
48
+
const handleThemeToggle = () => {
49
49
+
const nextScheme =
50
50
+
colorScheme === 'light'
51
51
+
? 'dark'
52
52
+
: colorScheme === 'dark'
53
53
+
? 'auto'
54
54
+
: 'light';
55
55
+
56
56
+
setColorScheme(nextScheme);
57
57
+
};
58
58
+
38
59
if (isPending || !data) {
39
39
-
return <Skeleton w={38} h={38} radius={'md'} ml={4} />;
60
60
+
return <Skeleton w={38} h={38} radius="md" ml={4} />;
40
61
}
41
62
42
63
if (error) {
···
49
70
<Menu.Target>
50
71
<Button
51
72
variant="subtle"
52
52
-
color={colorScheme === 'dark' ? 'gray' : 'dark'}
53
53
-
fz={'md'}
54
54
-
radius={'md'}
73
73
+
color={computedColorScheme === 'dark' ? 'gray' : 'dark'}
74
74
+
fz="md"
75
75
+
radius="md"
55
76
size="lg"
56
77
px={3}
57
57
-
fullWidth={true}
78
78
+
fullWidth
58
79
justify="start"
59
80
leftSection={<Avatar src={data.avatarUrl} />}
60
81
>
61
82
{data.name}
62
83
</Button>
63
84
</Menu.Target>
85
85
+
64
86
<Menu.Dropdown>
65
87
<Menu.Item
66
88
component={Link}
···
92
114
93
115
<Menu.Divider />
94
116
117
117
+
{/*<Menu.Item
118
118
+
color="gray"
119
119
+
leftSection={
120
120
+
colorScheme === 'auto' ? (
121
121
+
<MdAutoAwesome />
122
122
+
) : computedColorScheme === 'dark' ? (
123
123
+
<MdDarkMode />
124
124
+
) : (
125
125
+
<MdLightMode />
126
126
+
)
127
127
+
}
128
128
+
closeMenuOnClick={false}
129
129
+
onClick={handleThemeToggle}
130
130
+
>
131
131
+
Theme: {colorScheme}
132
132
+
</Menu.Item>*/}
133
133
+
95
134
<Menu.Item
96
135
component="a"
97
136
href="https://cosmik.network/"
···
99
138
>
100
139
<Image
101
140
src={
102
102
-
colorScheme === 'dark' ? CosmikLogoWhite.src : CosmikLogo.src
141
141
+
computedColorScheme === 'dark'
142
142
+
? CosmikLogoWhite.src
143
143
+
: CosmikLogo.src
103
144
}
104
145
alt="Cosmik logo"
105
105
-
w={'auto'}
146
146
+
w="auto"
106
147
h={24}
107
148
/>
108
149
</Menu.Item>
+1
-1
src/webapp/providers/mantine.tsx
···
12
12
13
13
export default function MantineProvider(props: Props) {
14
14
return (
15
15
-
<BaseProvider theme={theme}>
15
15
+
<BaseProvider theme={theme} defaultColorScheme="light">
16
16
<Notifications position="bottom-right" />
17
17
{props.children}
18
18
</BaseProvider>