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: add update form #437

Merged
merged 47 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
ff3c770
fix: improved dev container speed
tran-christian Aug 9, 2023
893766b
fix: minor configuration change for dev container and update to script
tran-christian Aug 9, 2023
4c3edd1
feat: added update form
tran-christian Aug 16, 2023
9a3bb94
chore: merge main
tran-christian Aug 16, 2023
e5a53b9
feat: fixed space issue with update form
tran-christian Aug 17, 2023
7152ac1
fix: fix conflict and removed unused dependencies
tran-christian Aug 18, 2023
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
13ed84b
chore(merge darkmode branch): merge darkmode branch to update form br…
tran-christian Oct 12, 2023
335a2c0
fix(light mode styling): fix light mode styling text
tran-christian Oct 12, 2023
8ed558b
chore(main): merge main
tran-christian Aug 15, 2024
f696ef3
fix(reviewcard): fix style flash when reloading page
tran-christian Aug 16, 2024
2eb7c31
fix(markdown): add other markdown plugins and formatted files
tran-christian Aug 16, 2024
703c733
fix(profile micon): fix get calling profile icon
tran-christian Aug 16, 2024
7704fa8
chore(types): extract generic type `TNullable` to avoid redundancy
awpala Aug 16, 2024
28abca6
chore: simplify backend imports
awpala Aug 16, 2024
9b6ed9f
fix(devcontainer): revert setting to make user `root` the default
awpala Aug 16, 2024
d974188
chore(Dockerfile): minor cleanup and commenting
awpala Aug 16, 2024
c067ac2
fix(devcontainer): fix dependency install and add name `omshub-websit…
awpala Aug 16, 2024
9730323
chore(devcontainer): fix formatting
awpala Aug 16, 2024
58ca4a6
chore(devcontainer): update VS Code extensions
awpala Aug 16, 2024
bd86764
chore(devcontainer): rearrange position of property
awpala Aug 16, 2024
5e6355a
fix(AuthContext): remove email from local storage on logout
awpala Aug 16, 2024
cca3255
chore(example.env): clarify examples for env var `TZ`
awpala Aug 16, 2024
bdd4de4
chore(devcontainer): add caching for firebase emulator JAR files
awpala Aug 17, 2024
c787c08
fix: darkmode
tran-christian Aug 18, 2024
9cddb30
chore(fmt): format files
tran-christian Aug 18, 2024
8b302f2
fix(reviewform): update nullable types
tran-christian Aug 18, 2024
321a281
chore(tiptap): remove unused tiptap file
tran-christian Aug 18, 2024
8cb585b
chore: fix usage of `TNullable` type
awpala Aug 19, 2024
1b2a026
chore: merge 'origin/main' into update-form
awpala Aug 19, 2024
14d69ef
fix(labeler): fix filename
awpala Aug 19, 2024
ad40323
fix(labeler): update filepath for config
awpala Aug 19, 2024
d46007c
fix: correct labeler GitHub Actions workflow
awpala Aug 19, 2024
cadb967
fix(labeler): fix filename
awpala Aug 19, 2024
d6b50d1
chore(label): rename labeler to label
tran-christian Aug 20, 2024
93216a7
fix(label): checkout code for labeler.yml
tran-christian Aug 20, 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
6 changes: 3 additions & 3 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,6 @@
},
// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "./.devcontainer/scripts/start.sh",
// Change to `"node"` to connect as non-root user instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "root"
}
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
// "remoteUser": "node"
}
1 change: 1 addition & 0 deletions example.env
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID=
# firebase emulator suite vars
NEXT_PUBLIC_IS_EMULATOR_MODE= # <true | false>
NEXT_PUBLIC_FIRESTORE_EMULATOR_HOST= # <localhost:8080> -- ref: https://stackoverflow.com/a/66790889
TZ= # <America/Chicago> -- Use same timezone as local to match NodeJS/Emulator to it
2 changes: 2 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

module.exports = {
reactStrictMode: true,

env: {
baseUrl: process.env.BASE_URL,
apiKey: process.env.API_KEY,
Expand All @@ -14,6 +15,7 @@ module.exports = {
},
compiler:{
removeConsole: true,
styledComponents: true,
},
transpilePackages: ['@mui/system', '@mui/material', '@mui/icons-material','@mui/styles'],
};
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"npm": "please-use-yarn"
},
"scripts": {
"dev": "NODE_OPTIONS='--inspect' next dev",
"dev": "cross-env NODE_OPTIONS='--inspect' next dev",
"build": "next build",
"build-sitemap": "next-sitemap",
"start": "next start",
Expand Down Expand Up @@ -46,9 +46,6 @@
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-hook-form": "^7.45.2",
"react-markdown": "^8.0.5",
"rehype-raw": "^6.1.1",
"remark-gfm": "^3.0.1",
"string-width": "^6.1.0",
"swr": "^2.2.4",
"tsconfig-paths-webpack-plugin": "^4.0.0"
Expand Down
219 changes: 105 additions & 114 deletions pages/course/[courseid].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import {
roundNumber,
} from '@src/utilities';
import type { NextPage } from 'next';
import { useRouter } from 'next/router';
import React, { useEffect, useState } from 'react';
import useSWR, { useSWRConfig } from 'swr';

Expand Down Expand Up @@ -69,19 +68,24 @@ const CourseId: NextPage<CoursePageProps> = ({
defaultSemesterToggles,
defaultReviews,
}) => {
const router = useRouter();
const {
courseId: courseId,
name: courseName,
numReviews: courseNumReviews,
url: courseUrl,
avgWorkload: courseAvgWorkload,
avgDifficulty: courseAvgDifficulty,
avgOverall: courseAvgOverall,
} = courseData;
const [loading, setLoading] = useState<boolean>(false);
const [snackBarOpen, setSnackBarOpen] = useState<boolean>(false);
const [snackBarMessage, setSnackBarMessage] = useState<string>('');
const [reviewModalOpen, setReviewModalOpen] = useState(false);
const handleReviewModalOpen = () => setReviewModalOpen(true);
const handleReviewModalClose = () => setReviewModalOpen(false);

const authContext = useAuth();
let user: FirebaseAuthUser | null = null;
if (authContext) {
({ user } = authContext);
}
const authContext : any | null = useAuth();
const user: FirebaseAuthUser | null = authContext.user;

const theme = useTheme();

Expand All @@ -95,8 +99,6 @@ const CourseId: NextPage<CoursePageProps> = ({
useState<TPayloadReviews>(defaultReviews);
const orientation = useMediaQuery('(min-width:600px)');

const path = router.asPath.split('/');
const courseId = path[path.length - 1] as TCourseId;
const { mutate } = useSWRConfig();
const { data: course_reviews } = useSWR(
`/course/${courseId}/${selectedYear}/${selectedSemester}`,
Expand All @@ -118,9 +120,7 @@ const CourseId: NextPage<CoursePageProps> = ({
enabled: true,
name: 'Copy Course Name',
clickAction: () => {
navigator.clipboard.writeText(
`${courseData?.courseId}: ${courseData?.name}`,
);
navigator.clipboard.writeText(`${courseId}: ${courseName}`);
setSnackBarMessage('Copied Course Name to Clipboard');
setSnackBarOpen(true);
},
Expand Down Expand Up @@ -160,11 +160,6 @@ const CourseId: NextPage<CoursePageProps> = ({

setSnackBarOpen(false);
};
useEffect(() => {
if (courseData?.numReviews) {
setLoading(false);
}
}, [courseData]);
useEffect(() => {
if (course_reviews) {
setCourseReviews(course_reviews);
Expand Down Expand Up @@ -217,10 +212,10 @@ const CourseId: NextPage<CoursePageProps> = ({
}}
>
<Typography variant='h4' color='inherit' gutterBottom>
{courseData?.name}
{courseName}
</Typography>
{courseData && courseData?.url && (
<Link href={courseData.url} target='_blank' color="primary.contrastText">
{courseUrl && (
<Link href={courseUrl} target='_blank' color="primary.contrastText">
<Box
sx={{
display: 'flex',
Expand All @@ -235,99 +230,88 @@ const CourseId: NextPage<CoursePageProps> = ({
</Box>
</Link>
)}
{courseData &&
courseData?.avgWorkload &&
courseData?.avgDifficulty &&
courseData.avgOverall && (
<Grid
sx={{ my: 1 }}
container
direction='row'
spacing={4}
justifyContent='center'
>
<Grid item xs={12} lg={4}>
<Card variant='outlined' sx={{ padding: '5 30', color: 'inherit' }}>
<CardContent>
<Typography
sx={{ fontSize: 14 }}
gutterBottom
>
{`Average Workload`}
</Typography>
<Typography variant='h5' sx={{color: 'inherit'}}>
{roundNumber(Number(courseData?.avgWorkload), 1) +
' hrs/wk'}
</Typography>
</CardContent>
</Card>
</Grid>
<Grid item xs={12} lg={4}>
<Card
variant='outlined'
sx={{
padding: '5 30',
borderColor: mapRatingToColorInverted(
Number(courseData?.avgDifficulty),
),
}}
>
<CardContent>
<Typography
sx={{ fontSize: 14,
color: mapRatingToColorInverted(
Number(courseData?.avgDifficulty),
),
}}
gutterBottom
>
{`Average Difficulty`}
</Typography>
<Typography
variant='h5'
sx={{
color: mapRatingToColorInverted(
Number(courseData?.avgDifficulty),
),
}}
>
{roundNumber(Number(courseData?.avgDifficulty), 1) +
' /5'}
</Typography>
</CardContent>
</Card>
</Grid>
<Grid item xs={12} lg={4}>
<Card
variant='outlined'
sx={{
margin: '10',
padding: '5 30',
borderColor: mapRatingToColor(
Number(courseData.avgOverall),
),
}}
>
<CardContent>
<Typography
sx={{ fontSize: 14, color: mapRatingToColor(Number(courseData.avgOverall)) }}
gutterBottom
>
{`Average Overall`}
</Typography>
<Typography
variant='h5'
sx={{
color: mapRatingToColor(Number(courseData.avgOverall)),
}}
>
{roundNumber(Number(courseData.avgOverall), 1) + ' /5'}
</Typography>
</CardContent>
</Card>
</Grid>
{courseAvgWorkload && courseAvgDifficulty && courseAvgOverall && (
<Grid
sx={{ my: 1 }}
container
direction='row'
spacing={4}
justifyContent='center'
>
<Grid item xs={12} lg={4}>
<Card variant='outlined' sx={{ padding: '5 30', color:'inherit' }}>
<CardContent>
<Typography
sx={{ fontSize: 14 }}
gutterBottom
>
{`Average Workload`}
</Typography>
<Typography variant='h5'>
{roundNumber(Number(courseAvgWorkload), 1) + ' hrs/wk'}
</Typography>
</CardContent>
</Card>
</Grid>
)}
<Grid item xs={12} lg={4}>
<Card
variant='outlined'
sx={{
padding: '5 30',
borderColor: mapRatingToColorInverted(
Number(courseAvgDifficulty),
),
}}
>
<CardContent>
<Typography
sx={{ fontSize: 14 }}
gutterBottom
>
{`Average Difficulty`}
</Typography>
<Typography
variant='h5'
sx={{
color: mapRatingToColorInverted(
Number(courseAvgDifficulty),
),
}}
>
{roundNumber(Number(courseAvgDifficulty), 1) + ' /5'}
</Typography>
</CardContent>
</Card>
</Grid>
<Grid item xs={12} lg={4}>
<Card
variant='outlined'
sx={{
margin: '10',
padding: '5 30',
borderColor: mapRatingToColor(Number(courseAvgOverall)),
}}
>
<CardContent>
<Typography
sx={{ fontSize: 14 }}
gutterBottom
>
{`Average Overall`}
</Typography>
<Typography
variant='h5'
sx={{
color: mapRatingToColor(Number(courseAvgOverall)),
}}
>
{roundNumber(Number(courseAvgOverall), 1) + ' /5'}
</Typography>
</CardContent>
</Card>
</Grid>
</Grid>
)}
<Grid>
<ToggleButtonGroup
value={selectedSemester}
Expand Down Expand Up @@ -383,7 +367,7 @@ const CourseId: NextPage<CoursePageProps> = ({
</Box>
) : (
<>
{courseData?.numReviews ? (
{courseNumReviews ? (
<>
{courseReviews && (
<Grid container rowSpacing={5} sx={{ mt: 1 }}>
Expand Down Expand Up @@ -419,7 +403,14 @@ const CourseId: NextPage<CoursePageProps> = ({
closeAfterTransition
PaperProps={{sx:{backgroundImage: 'none'}}}
>
<ReviewForm {...{ courseData, handleReviewModalClose }} />
<ReviewForm
{...{
courseId,
courseName,
['reviewInput']: null,
handleReviewModalClose,
}}
/>
</Dialog>
<SpeedDial
ariaLabel='Review Dial'
Expand Down
13 changes: 11 additions & 2 deletions src/components/FormEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
import '@toast-ui/editor/dist/toastui-editor.css';
import { Editor } from '@toast-ui/react-editor';
import DOMPurify from 'isomorphic-dompurify';
import { useRef } from 'react';
import { useEffect, useRef } from 'react';

//SSR is currently not supported for toastui

export default function FormEditor({
initialValue,
onChange,
}: {
initialValue: string;
initialValue:any;
onChange: any;
}) {
const editorRef = useRef<Editor>(null);
Expand All @@ -23,6 +23,15 @@
const clean = DOMPurify.sanitize(dirty, { FORBID_TAGS: ['img'] });
onChange(clean);
}

useEffect(()=>{
//Set initial value this way because theres a character limit the other way when doing it via prop
if(!editorRef?.current?.getInstance().getMarkdown()){
editorRef?.current?.getInstance().setMarkdown(initialValue)
}
// eslint-disable-next-line react-hooks/exhaustive-deps
},[editorRef?.current?.getInstance().getMarkdown(),initialValue]);
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed

return (
<Box sx={{
"& .toastui-editor-dark":{
Expand Down
Loading