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

Feature: Dark Mode #441

Merged
merged 19 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
941c2f2
feat: add dark mode
tran-christian Aug 21, 2023
aff6ed7
feat(darkmode): minor styling update for darkmode
tran-christian Aug 22, 2023
6ed0714
feat(darkmode): added working light and dark mode with persistent sta…
tran-christian Aug 23, 2023
e3106f1
chore(darkmode): remove next-themes
tran-christian Aug 23, 2023
26e6e5c
chore(darkmode): remove random function
tran-christian Aug 23, 2023
356a6da
feat(darkmode): remove unused type
tran-christian Aug 24, 2023
6c3bdf2
fix(dark mode): redesigned mobile nav and login to accomodate dark mode
tran-christian Oct 10, 2023
289966d
fix(dark mode): added skeleton for component flash that would occur f…
tran-christian Oct 10, 2023
6383503
fix(dark mode): fixing user component flash when logged in
tran-christian Oct 10, 2023
d7cb335
feat(dark mode): default user profile pics
tran-christian Oct 10, 2023
5f70cc1
chore(merge main): merge branch 'main' into dark-mode
tran-christian Oct 10, 2023
7265616
fix(dark mode): fix dark mode in form editor and other areas
tran-christian Oct 10, 2023
e9b65e9
Merge branch 'main' into dark-mode
tran-christian Aug 15, 2024
8a951de
fix(merge main): merge main
tran-christian Aug 15, 2024
b36e973
fix(navbar): update import
tran-christian Aug 15, 2024
5053d35
fix(navbar): update theme config and navbar
tran-christian Aug 15, 2024
fc894df
fix(login): update media query for desktop
tran-christian Aug 15, 2024
6e3b3b4
style(everywhere): dark mode style updates
tran-christian Aug 15, 2024
b8c37a7
fix(about): fix missing 1
tran-christian Aug 15, 2024
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
27 changes: 27 additions & 0 deletions context/ColorContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { TContextProviderProps } from '@context/types';
import { Experimental_CssVarsProvider as CssVarsProvider, experimental_extendTheme as extendTheme } from '@mui/material/styles';
import { getDesignTokens } from '@src/theme';

const { palette: lightPalette } = getDesignTokens('light');
const { palette: darkPalette } = getDesignTokens('dark');
export const theme = extendTheme({
cssVarPrefix:'omshub',
colorSchemes:{
light:{
palette: lightPalette
},
dark:{
palette: darkPalette
}
}
})

export const ColorProvider = ({ children }: TContextProviderProps) => {


return (
<CssVarsProvider theme={theme} defaultMode="system" disableTransitionOnChange>
{children}
</CssVarsProvider>
);
};
7 changes: 4 additions & 3 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ module.exports = {
appId: process.env.APP_ID,
measurementId: process.env.MEASUREMENT_ID,
},
transpilePackages: ['@mui/system', '@mui/material', '@mui/icons-material'],
transpilePackages: ['@mui/system', '@mui/material', '@mui/icons-material'],
modularizeImports: {
'@mui/material/?(((\\w*)?/?)*)': {
transform: '@mui/material/{{ matches.[1] }}/{{member}}',
'@mui/material/!(styles)/?*': {
transform: '@mui/material/{{path}}/{{member}}',
skipDefaultConversion: true,
},
'@mui/icons-material/?(((\\w*)?/?)*)': {
transform: '@mui/icons-material/{{ matches.[1] }}/{{member}}',
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@
"@emotion/cache": "^11.10.5",
"@emotion/react": "^11.11.1",
"@emotion/server": "^11.4.0",
"@emotion/styled": "^11.10.5",
"@emotion/styled": "^11.11.0",
"@fontsource/roboto": "^5.0.8",
"@mui/icons-material": "^5.11.11",
"@mui/material": "^5.14.2",
"@mui/material": "^5.14.5",
"@mui/x-data-grid": "^6.6.0",
"@toast-ui/react-editor": "^3.2.2",
"firebase": "^9.15.0",
Expand Down
22 changes: 15 additions & 7 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
import { AlertBar } from '@components/AlertBar';
import { AlertContextProvider } from '@context/AlertContext';
import { AuthContextProvider } from '@context/AuthContext';
import { ColorProvider } from '@context/ColorContext';
import { MenuContextProvider } from '@context/MenuContext';
import { CacheProvider, EmotionCache } from '@emotion/react';
import CssBaseline from '@mui/material/CssBaseline';
import { ThemeProvider } from '@mui/material/styles';
import { NavBar } from '@src/components/NavBar';
import createEmotionCache from '@src/createEmotionCache';
import theme from '@src/theme';
import type { NextPage } from 'next';
import { AppProps } from 'next/app';
import Head from 'next/head';
import type { ReactElement, ReactNode } from 'react';

// Client-side cache, shared for the whole session of the user in the browser.
const clientSideEmotionCache = createEmotionCache();

export type NextPageWithLayout<P = {}, IP = P> = NextPage<P, IP> & {
getLayout?: (page: ReactElement) => ReactNode

Check notice on line 19 in pages/_app.tsx

View check run for this annotation

codefactor.io / CodeFactor

pages/_app.tsx#L19

'page' is defined but never used. (no-unused-vars)
Fixed Show fixed Hide fixed
}
interface MyAppProps extends AppProps {
Component: NextPageWithLayout
emotionCache?: EmotionCache;
fallback: object;
}
Expand All @@ -23,26 +28,29 @@
Component,
emotionCache = clientSideEmotionCache,
pageProps,
}: MyAppProps) => (
}: MyAppProps) => {


return (
<CacheProvider value={emotionCache}>
<ColorProvider>
<AlertContextProvider>
<AuthContextProvider>
<Head>
<meta name='viewport' content='initial-scale=1, width=device-width' />
<title>OMSHub</title>
</Head>
<ThemeProvider theme={theme}>
<CssBaseline />
<MenuContextProvider>
<NavBar />
<AlertBar />
</MenuContextProvider>
<Component {...pageProps} />
</ThemeProvider>
{<Component {...pageProps} />}
{/* <Copyright /> */}
</AuthContextProvider>
</AlertContextProvider>
</ColorProvider>
</CacheProvider>
);
)};

export default MyApp;
25 changes: 15 additions & 10 deletions pages/_document.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import * as React from 'react';
import Document, { Html, Head, Main, NextScript } from 'next/document';
import createEmotionServer from '@emotion/server/create-instance';
import theme from '@src/theme';
import { getInitColorSchemeScript, useTheme } from '@mui/material/styles';
import createEmotionCache from '@src/createEmotionCache';
import Document, { Head, Html, Main, NextScript } from 'next/document';
import React from 'react';

export default class MyDocument extends Document {
render() {

export default function MyDocument(props:any){

const theme = useTheme()
return (
<Html lang='en'>
<Head>
Expand All @@ -17,20 +19,20 @@ export default class MyDocument extends Document {
href='https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap'
/>
{/* Inject MUI styles first to match with the prepend: true configuration. */}
{(this.props as any).emotionStyleTags}
{(props as any).emotionStyleTags}
</Head>
<body>
{getInitColorSchemeScript()}
<Main />
<NextScript />
</body>
</Html>
);
}
}

// `getInitialProps` belongs to `_document` (instead of `_app`),
// it's compatible with static-site generation (SSG).
MyDocument.getInitialProps = async (ctx) => {
MyDocument.getInitialProps = async (ctx:any) => {
// Resolution order
//
// On the server:
Expand Down Expand Up @@ -63,7 +65,7 @@ MyDocument.getInitialProps = async (ctx) => {
ctx.renderPage = () =>
originalRenderPage({
enhanceApp: (App: any) =>
function EnhanceApp(props) {
function EnhanceApp(props:any) {
return <App emotionCache={cache} {...props} />;
},
});
Expand All @@ -83,6 +85,9 @@ MyDocument.getInitialProps = async (ctx) => {

return {
...initialProps,
emotionStyleTags,
styles: [
...React.Children.toArray(initialProps.styles),
...emotionStyleTags,
],
};
};
23 changes: 12 additions & 11 deletions pages/course/[courseid].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ const CourseId: NextPage<CoursePageProps> = ({
alignItems: 'center',
}}
>
<Typography variant='h4' color='text.secondary' gutterBottom>
<Typography variant='h4' color='inherit' gutterBottom>
{courseData?.name}
</Typography>
{courseData && courseData?.url && (
Expand All @@ -224,7 +224,7 @@ const CourseId: NextPage<CoursePageProps> = ({
}}
>
<LinkIcon />
<Typography variant='subtitle1' color='text.secondary'>
<Typography variant='subtitle1' color='inherit'>
{'Course Website'}
</Typography>
</Box>
Expand All @@ -242,16 +242,15 @@ const CourseId: NextPage<CoursePageProps> = ({
justifyContent='center'
>
<Grid item xs={12} lg={4}>
<Card variant='outlined' sx={{ padding: '5 30' }}>
<Card variant='outlined' sx={{ padding: '5 30', color: 'inherit' }}>
<CardContent>
<Typography
sx={{ fontSize: 14 }}
color='text.secondary'
gutterBottom
>
{`Average Workload`}
</Typography>
<Typography variant='h5'>
<Typography variant='h5' sx={{color: 'inherit'}}>
{roundNumber(Number(courseData?.avgWorkload), 1) +
' hrs/wk'}
</Typography>
Expand All @@ -270,8 +269,11 @@ const CourseId: NextPage<CoursePageProps> = ({
>
<CardContent>
<Typography
sx={{ fontSize: 14 }}
color='text.secondary'
sx={{ fontSize: 14,
color: mapRatingToColorInverted(
Number(courseData?.avgDifficulty),
),
}}
gutterBottom
>
{`Average Difficulty`}
Expand Down Expand Up @@ -303,8 +305,7 @@ const CourseId: NextPage<CoursePageProps> = ({
>
<CardContent>
<Typography
sx={{ fontSize: 14 }}
color='text.secondary'
sx={{ fontSize: 14, color: mapRatingToColor(Number(courseData.avgOverall)) }}
gutterBottom
>
{`Average Overall`}
Expand Down Expand Up @@ -395,7 +396,7 @@ const CourseId: NextPage<CoursePageProps> = ({
<>
<Typography
variant='h3'
color='text.secondary'
color='inherit'
style={{ textAlign: 'center' }}
gutterBottom
>
Expand Down Expand Up @@ -440,7 +441,7 @@ const CourseId: NextPage<CoursePageProps> = ({
autoHideDuration={6000}
onClose={handleClose}
action={
<Button color='secondary' size='small' onClick={handleClose}>
<Button color='inherit' size='small' onClick={handleClose}>
Close
</Button>
}
Expand Down
11 changes: 7 additions & 4 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const Home: NextPage<HomePageProps> = ({ allCourseData }) => {
minWidth: isDesktop ? 50 : 300,
renderCell: (params: GridRenderCellParams) => (
<Tooltip title={`View review page for ${params.row.courseId}`}>
<Link href='/course/[courseid]' as={`/course/${params.row.courseId}`}>
<Link color='secondary' href='/course/[courseid]' as={`/course/${params.row.courseId}`}>
{params.row.name}
</Link>
</Tooltip>
Expand Down Expand Up @@ -118,17 +118,20 @@ const Home: NextPage<HomePageProps> = ({ allCourseData }) => {
rows={courses}
columns={columns}
loading={!allCourseData}
components={{ Toolbar: GridToolbar }}
slots={{ toolbar : GridToolbar }}
sx={{ borderRadius: '25px', padding: '20px 10px' }}
columnVisibilityModel={{
isDeprecated: false,
aliases: false,
}}
componentsProps={{
slotProps={{
toolbar: {
printOptions: { disableToolbarButton: true },
disableDensitySelector: true,
showQuickFilter: true,
quickFilterProps: { debounceMs: 500 },
sx:{

}
},
}}
initialState={{
Expand Down
39 changes: 20 additions & 19 deletions src/components/FormEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useTheme } from '@mui/material/styles';
import '@toast-ui/editor/dist/toastui-editor.css';
import { Editor } from '@toast-ui/react-editor';
import DOMPurify from 'isomorphic-dompurify';
Expand All @@ -13,32 +14,32 @@ export default function FormEditor({
onChange: any;
}) {
const editorRef = useRef<Editor>(null);

const theme = useTheme();
function handleChange() {
const dirty = editorRef?.current
? editorRef?.current.getInstance().getMarkdown()
: '';
const clean = DOMPurify.sanitize(dirty, { FORBID_TAGS: ['img'] });
onChange(clean);
}

return (
<Editor
height='auto'
initialValue={initialValue}
onChange={handleChange}
initialEditType='wysiwyg'
previewStyle='vertical'
ref={editorRef}
useCommandShortcut={true}
toolbarItems={[
['heading', 'bold', 'italic', 'strike'],
['hr', 'quote'],
['ul', 'ol', 'task', 'indent', 'outdent'],
['table', 'link'],
['code', 'codeblock'],
]}
customHTMLSanitizer={DOMPurify.sanitize}
/>
<Editor
height='auto'
initialValue={initialValue}
onChange={handleChange}
initialEditType='wysiwyg'
previewStyle='vertical'
ref={editorRef}
theme={`${theme.palette.mode}`}
useCommandShortcut={true}
toolbarItems={[
['heading', 'bold', 'italic', 'strike'],
['hr', 'quote'],
['ul', 'ol', 'task', 'indent', 'outdent'],
['table', 'link'],
['code', 'codeblock'],
]}
customHTMLSanitizer={DOMPurify.sanitize}
/>
);
}
Loading
Loading