Skip to content

Commit 16e89c2

Browse files
authored
Merge pull request #1427 from rit-construct-makerspace/cowsed/themefixes
Theme editing and deletion
2 parents 20cf260 + 215d4de commit 16e89c2

10 files changed

Lines changed: 150 additions & 152 deletions

File tree

client/eslint.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ export default tseslint.config(
1414
ecmaVersion: 2020,
1515
globals: globals.browser,
1616
parserOptions: {
17-
project: "./tsconfig.json"
17+
project: "./tsconfig.json",
18+
tsconfigRootDir: import.meta.dirname
1819
},
1920

2021
},

client/src/pages/site-settings/ManageThemePage.tsx

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
import { useMutation, useQuery } from "@apollo/client/react";
22
import { Button, LinearProgress, Stack, Typography } from "@mui/material";
3-
import { GET_THEME, MARK_DEFAULT_THEME, UPDATE_THEME } from "../../queries/themeQueries";
3+
import { GET_THEME, GET_THEMES, MARK_DEFAULT_THEME, UPDATE_THEME } from "../../queries/themeQueries";
44
import { useNavigate, useParams } from "react-router-dom";
55
import { ServerThemeData } from "../../types/site_settings/MakeTheme";
66
import SaveIcon from '@mui/icons-material/Save';
77
import NotInterestedIcon from '@mui/icons-material/NotInterested';
88
import { toast } from "react-toastify";
99
import { useMakeTheme } from "../../common/MakeThemeProvider";
10-
1110
import StarIcon from '@mui/icons-material/Star';
1211
import ThemeEditor from "./ThemeEditor";
12+
import { ComponentProps } from "react";
1313

1414
export default function ManageThemePage() {
1515
const { themeKey } = useParams<{ themeKey: string }>();
1616
const navigate = useNavigate();
1717
const makeTheme = useMakeTheme();
1818

19-
const [updateTheme] = useMutation(UPDATE_THEME, { refetchQueries: ["GetThemes"], awaitRefetchQueries: true });
20-
const [markDefaultTheme] = useMutation(MARK_DEFAULT_THEME, { refetchQueries: ["GetThemes"], awaitRefetchQueries: true });
19+
type ThemeEditorProps = ComponentProps<typeof ThemeEditor>;
20+
21+
const [updateTheme] = useMutation(UPDATE_THEME, { refetchQueries: [{ query: GET_THEMES, variables: {} }, { query: GET_THEME, variables: { key: themeKey } }], awaitRefetchQueries: true });
22+
const [markDefaultTheme] = useMutation(MARK_DEFAULT_THEME, { refetchQueries: [{ query: GET_THEMES, variables: {} }, GET_THEME], awaitRefetchQueries: true });
2123

2224
const themeResult = useQuery(GET_THEME, {
2325
variables: { key: themeKey },
@@ -28,15 +30,17 @@ export default function ManageThemePage() {
2830
muiThemeOptions: JSON.parse(themeResult.data?.getTheme.muiThemeOptions)
2931
} : undefined;
3032

33+
const updatedTheme = currentTheme
34+
3135
async function handleUpdateTheme() {
3236
try {
3337
await updateTheme({
3438
variables: {
3539
key: themeKey,
36-
themeName: themeName,
37-
title: siteTitle,
38-
muiThemeOptions: JSON.stringify(muiThemeOptions),
39-
logo: logo
40+
themeName: updatedTheme.themeName,
41+
title: updatedTheme.title,
42+
muiThemeOptions: JSON.stringify(updatedTheme.muiThemeOptions),
43+
logo: updatedTheme.logo
4044
}
4145
})
4246
toast.success(`Updated Theme!`)
@@ -58,6 +62,36 @@ export default function ManageThemePage() {
5862
}
5963
}
6064

65+
async function themeChanged(theme: ThemeEditorProps) {
66+
updatedTheme.logo = theme.logo
67+
updatedTheme.muiThemeOptions = {
68+
palette: {
69+
primary: {
70+
main: theme.primary
71+
},
72+
secondary: {
73+
main: theme.secondary
74+
},
75+
error: {
76+
main: theme.error,
77+
},
78+
warning: {
79+
main: theme.warning
80+
},
81+
info: {
82+
main: theme.info
83+
},
84+
success: {
85+
main: theme.success
86+
},
87+
mode: theme.mode == "light" ? "light" : "dark"
88+
}
89+
}
90+
updatedTheme.themeName = theme.themeName
91+
updatedTheme.title = theme.siteTitle
92+
93+
}
94+
6195
return (
6296
<Stack alignItems={"center"} spacing={3}>
6397
<title>{`Edit Theme | ${makeTheme.title}`}</title>
@@ -94,8 +128,10 @@ export default function ManageThemePage() {
94128
</Stack>
95129
{currentTheme
96130
? <ThemeEditor
131+
onChange={themeChanged}
132+
themeKey={currentTheme.key}
97133
themeName={currentTheme.themeName}
98-
siteTitle={currentTheme.themeName}
134+
siteTitle={currentTheme.title}
99135
logo={currentTheme.logo}
100136

101137
primary={currentTheme.muiThemeOptions.palette?.primary.main}

client/src/pages/site-settings/NewThemePage.tsx

Lines changed: 7 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Alert, AppBar, Box, Button, Card, createTheme, Paper, Stack, TextField, ThemeOptions, ThemeProvider, ToggleButton, ToggleButtonGroup, Tooltip, Typography } from "@mui/material";
1+
import { AppBar, Box, Button, Card, createTheme, Paper, Stack, TextField, ThemeOptions, ThemeProvider, ToggleButton, ToggleButtonGroup, Tooltip, Typography } from "@mui/material";
22
import { useNavigate } from "react-router-dom";
33
import NotInterestedIcon from '@mui/icons-material/NotInterested';
44
import { useState } from "react";
@@ -7,10 +7,11 @@ import styled from "styled-components";
77
import { makeCDNLink } from "../../common/ImageFinder";
88
import AddIcon from '@mui/icons-material/Add';
99
import { useMutation } from "@apollo/client/react";
10-
import { CREATE_THEME } from "../../queries/themeQueries";
10+
import { CREATE_THEME, GET_THEMES } from "../../queries/themeQueries";
1111
import { toast } from "react-toastify";
1212
import { useMakeTheme } from "../../common/MakeThemeProvider";
1313
import AnnouncementIcon from '@mui/icons-material/Announcement';
14+
import ThemePreview from "./ThemePreview";
1415

1516
const StyledImg = styled.img`
1617
padding: 12px;
@@ -22,7 +23,7 @@ const StyledImg = styled.img`
2223
export default function NewThemePage() {
2324
const navigate = useNavigate();
2425

25-
const [createMakeTheme] = useMutation(CREATE_THEME, { refetchQueries: ["GetThemes"], awaitRefetchQueries: true });
26+
const [createMakeTheme] = useMutation(CREATE_THEME, { refetchQueries: [{ query: GET_THEMES, variables: {}} ], awaitRefetchQueries: true });
2627

2728
const makeTheme = useMakeTheme();
2829

@@ -76,9 +77,9 @@ export default function NewThemePage() {
7677
},
7778
});
7879

79-
async function handleCreateTheme() {
80+
function handleCreateTheme() {
8081
try {
81-
await createMakeTheme({
82+
createMakeTheme({
8283
variables: {
8384
themeName: themeName,
8485
title: siteTitle,
@@ -236,122 +237,7 @@ export default function NewThemePage() {
236237
onChange={(e) => setSuccess(e.target.value)}
237238
/>
238239
</Stack>
239-
<Stack direction={"row"} spacing={2}>
240-
<Stack spacing={1} width={"100%"}>
241-
<Typography variant="subtitle1">Primary Example</Typography>
242-
<Button
243-
variant="contained"
244-
color="primary"
245-
>
246-
I'm a Button!
247-
</Button>
248-
<Button
249-
variant="outlined"
250-
color="primary"
251-
>
252-
I'm a Button!
253-
</Button>
254-
</Stack>
255-
<Stack spacing={1} width={"100%"}>
256-
<Typography variant="subtitle1">Secondary Example</Typography>
257-
<Button
258-
variant="contained"
259-
color="secondary"
260-
>
261-
I'm a Button!
262-
</Button>
263-
<Button
264-
variant="outlined"
265-
color="secondary"
266-
>
267-
I'm a Button!
268-
</Button>
269-
</Stack>
270-
<Stack spacing={1} width={"100%"}>
271-
<Typography variant="subtitle1">Error Example</Typography>
272-
<Button
273-
variant="contained"
274-
color="error"
275-
>
276-
I'm a Button!
277-
</Button>
278-
<Button
279-
variant="outlined"
280-
color="error"
281-
>
282-
I'm a Button!
283-
</Button>
284-
<Alert
285-
variant="filled"
286-
severity="error"
287-
>
288-
Error!
289-
</Alert>
290-
</Stack>
291-
<Stack spacing={1} width={"100%"}>
292-
<Typography variant="subtitle1">Warning Example</Typography>
293-
<Button
294-
variant="contained"
295-
color="warning"
296-
>
297-
I'm a Button!
298-
</Button>
299-
<Button
300-
variant="outlined"
301-
color="warning"
302-
>
303-
I'm a Button!
304-
</Button>
305-
<Alert
306-
variant="filled"
307-
severity="warning"
308-
>
309-
Warning!
310-
</Alert>
311-
</Stack>
312-
<Stack spacing={1} width={"100%"}>
313-
<Typography variant="subtitle1">Info Example</Typography>
314-
<Button
315-
variant="contained"
316-
color="info"
317-
>
318-
I'm a Button!
319-
</Button>
320-
<Button
321-
variant="outlined"
322-
color="info"
323-
>
324-
I'm a Button!
325-
</Button>
326-
<Alert
327-
variant="filled"
328-
severity="info"
329-
>
330-
Info!
331-
</Alert>
332-
</Stack>
333-
<Stack spacing={1} width={"100%"}>
334-
<Typography variant="subtitle1">Success Example</Typography>
335-
<Button
336-
variant="contained"
337-
color="success"
338-
>
339-
I'm a Button!
340-
</Button>
341-
<Button
342-
variant="outlined"
343-
color="success"
344-
>
345-
I'm a Button!
346-
</Button>
347-
<Alert
348-
variant="filled"
349-
severity="success"
350-
>
351-
Success!
352-
</Alert>
353-
</Stack>
354-
</Stack>
240+
<ThemePreview />
355241
</Stack>
356242
</Stack>
357243
</Paper>

client/src/pages/site-settings/ThemeEditor.tsx

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { AppBar, Box, Card, createTheme, PaletteMode, Paper, Stack, TextField, ThemeOptions, ThemeProvider, ToggleButton, ToggleButtonGroup, Tooltip, Typography } from "@mui/material";
2-
import { useState } from "react";
2+
import { useEffect, useState } from "react";
33
import ThemePreview from "./ThemePreview";
44
import FileUploadButton from "../../common/FileUploadButton";
55
import { makeCDNLink } from "../../common/ImageFinder";
@@ -15,6 +15,8 @@ const StyledImg = styled.img`
1515
`;
1616

1717
interface ThemeEditorProps {
18+
onChange: (theme: ThemeEditorProps) => void
19+
themeKey: string
1820
themeName: string;
1921
siteTitle: string;
2022
logo: string;
@@ -42,6 +44,32 @@ export default function ThemeEditor(props: ThemeEditorProps) {
4244
const [success, setSuccess] = useState(props.success);
4345
const [mode, setMode] = useState(props.mode);
4446

47+
48+
useEffect(() => {
49+
const new_props: ThemeEditorProps = {
50+
onChange: props.onChange,
51+
themeKey: props.themeKey,
52+
53+
themeName: themeName,
54+
siteTitle: siteTitle,
55+
logo: logo,
56+
primary: primary,
57+
secondary: secondary,
58+
error: error,
59+
warning: warning,
60+
info: info,
61+
success: success,
62+
mode: mode,
63+
}
64+
65+
if (props.onChange) {
66+
props.onChange(new_props)
67+
}
68+
69+
}, [props, themeName, siteTitle, logo, primary, secondary, error, warning, info, success, mode
70+
]);
71+
72+
4573
const muiThemeOptions: ThemeOptions = {
4674
palette: {
4775
primary: {

0 commit comments

Comments
 (0)