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

Fix: actually use SSR #1080

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 11 additions & 6 deletions frontend/components/CreateAccountForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Component } from "react"
import Link from "next/link"
import { NextRouter, withRouter } from "next/router"

import { ApolloClient } from "@apollo/client"
import { CircularProgress, Paper, TextField, Typography } from "@mui/material"
import { styled } from "@mui/material/styles"

Expand Down Expand Up @@ -60,6 +61,7 @@ export function capitalizeFirstLetter(string: string) {

export interface CreateAccountFormProps {
onComplete: (...args: any[]) => any
apolloClient?: ApolloClient<object>
router: NextRouter
}

Expand Down Expand Up @@ -109,11 +111,14 @@ class CreateAccountForm extends Component<CreateAccountFormProps> {
password_confirmation: this.state.password_confirmation,
})

await authenticate({
email: this.state.email ?? "",
password: this.state.password ?? "",
redirect: false,
})
await authenticate(
{
email: this.state.email ?? "",
password: this.state.password ?? "",
redirect: false,
},
this.props.apolloClient,
)

this.props.onComplete()
} catch (error: any) {
Expand Down Expand Up @@ -177,7 +182,7 @@ class CreateAccountForm extends Component<CreateAccountFormProps> {
newState.error += t("emailNoAt")
newState.errorObj.email = true
}
if (email && email.indexOf(".") === -1) {
if (email.indexOf(".") === -1) {
newState.error += t("emailNoPoint")
newState.errorObj.email = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const CourseAliasEditForm = () => {
<>
{values.length ? (
values.map((alias, index: number) => (
<Row>
<Row key={`course-alias-${alias.course_code}`}>
<StyledFieldWithAnchor
id={`course_aliases[${index}].course_code`}
name={`course_aliases[${index}].course_code`}
Expand Down
20 changes: 10 additions & 10 deletions frontend/components/Dashboard/StudyModules/ModuleCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ const NaviCardTitle = styled(Typography)`
`

interface ModuleCardProps {
module?: StudyModuleDetailedFieldsFragment
studyModule?: StudyModuleDetailedFieldsFragment
loading?: boolean
}

function ModuleCard({ module, loading }: ModuleCardProps) {
const imageUrl = module
? module.image
? `../../../static/images/${module.image}`
: `../../../static/images/${module.slug}.jpg`
function ModuleCard({ studyModule, loading }: ModuleCardProps) {
const imageUrl = studyModule
? studyModule.image
? `../../../static/images/${studyModule.image}`
: `../../../static/images/${studyModule.slug}.jpg`
: "" // TODO: placeholder

return (
Expand Down Expand Up @@ -126,7 +126,7 @@ function ModuleCard({ module, loading }: ModuleCardProps) {
</NaviCardTitle>
) : (
<NaviCardTitle align="left">
{module ? module.name : "New module"}
{studyModule?.name ?? "New module"}
</NaviCardTitle>
)}

Expand All @@ -138,10 +138,10 @@ function ModuleCard({ module, loading }: ModuleCardProps) {
>
<Skeleton variant="text" width="100%" />
</ButtonWithPaddingAndMargin>
) : module ? (
<Link href={`/study-modules/${module.slug}/edit`} passHref>
) : studyModule ? (
<Link href={`/study-modules/${studyModule.slug}/edit`} passHref>
{/* eslint-disable-next-line jsx-a11y/anchor-is-valid */}
<a aria-label={`Edit study module ${module.name}`}>
<a aria-label={`Edit study module ${studyModule.name}`}>
<ButtonWithPaddingAndMargin
variant="text"
color="secondary"
Expand Down
4 changes: 2 additions & 2 deletions frontend/components/Dashboard/StudyModules/ModuleGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ const ModuleGrid = ({ modules, loading }: ModuleGridProps) => (
))
) : (
<>
{modules?.map((module) => (
<ModuleCard key={module.slug} module={module} />
{modules?.map((studyModule) => (
<ModuleCard key={studyModule.slug} studyModule={studyModule} />
))}
<ModuleCard key={"newmodule"} />
</>
Expand Down
4 changes: 3 additions & 1 deletion frontend/components/Dashboard/Users/UserInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ const renderAvailableFields = (data: UserDetailedFieldsFragment) => {
if (!content || !title) {
return null
}
return <InfoRow title={title} content={content} />
return (
<InfoRow title={title} content={content} key={`${data.id}-${field}`} />
)
})
.filter(notEmpty)
}
Expand Down
96 changes: 61 additions & 35 deletions frontend/components/FilterMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from "react"
import React, { useCallback, useState } from "react"

import { Clear, Search } from "@mui/icons-material"
import {
Expand Down Expand Up @@ -135,16 +135,16 @@ export default function FilterMenu({

useEffect(() => setLabelWidth(inputLabel?.current?.offsetWidth ?? 0), [])*/

const onSubmit = () => {
const onSubmit = useCallback(() => {
setSearchVariables({
...searchVariables,
search,
hidden,
handledBy,
})
}
}, [searchVariables, search, hidden, handledBy, setSearchVariables])

const handleStatusChange =
const handleStatusChange = useCallback(
(value: string) => (e: React.ChangeEvent<HTMLInputElement>) => {
const newStatus = (
e.target.checked
Expand All @@ -159,23 +159,63 @@ export default function FilterMenu({
...searchVariables,
status: newStatus,
})
}
},
[setStatus, setSearchVariables, searchVariables],
)

const handleHiddenChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setHidden(e.target.checked)
setSearchVariables({
...searchVariables,
hidden: e.target.checked,
})
}
const handleHiddenChange = useCallback(
(e: React.ChangeEvent<HTMLInputElement>) => {
setHidden(e.target.checked)
setSearchVariables({
...searchVariables,
hidden: e.target.checked,
})
},
[setHidden, setSearchVariables, searchVariables],
)

const handleHandledByChange = (e: SelectChangeEvent<string>) => {
setHandledBy(e.target.value)
const handleHandledByChange = useCallback(
(e: SelectChangeEvent<string>) => {
setHandledBy(e.target.value)
setSearchVariables({
...searchVariables,
handledBy: e.target.value,
})
},
[setHandledBy, setSearchVariables, searchVariables],
)

const handleSearchReset = useCallback(() => {
setSearch("")
}, [setSearch])

const handleSearchChange = useCallback(
(e: React.ChangeEvent<HTMLInputElement>) => {
setSearch(e.target.value)
},
[setSearch],
)

const handleSearchEnter = useCallback(
(e: React.KeyboardEvent<HTMLDivElement>) => {
if (e.key === "Enter") {
onSubmit()
}
},
[onSubmit],
)

const handleResetAll = useCallback(() => {
setHidden(true)
setHandledBy("")
setStatus([CourseStatus.Active, CourseStatus.Upcoming])
setSearchVariables({
...searchVariables,
handledBy: e.target.value,
search: "",
hidden: true,
handledBy: null,
status: [CourseStatus.Active, CourseStatus.Upcoming],
})
}
}, [setHidden, setHandledBy, setStatus, setSearchVariables])

return (
<Container>
Expand All @@ -186,17 +226,13 @@ export default function FilterMenu({
value={search}
autoComplete="off"
variant="outlined"
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
setSearch(e.target.value)
}
onKeyDown={(e) => e.key === "Enter" && onSubmit()}
onChange={handleSearchChange}
onKeyDown={handleSearchEnter}
InputProps={{
endAdornment: (
<InputAdornment position="end">
<IconButton
onClick={() => {
setSearch("")
}}
onClick={handleSearchReset}
disabled={search === ""}
edge="end"
aria-label="clear search"
Expand Down Expand Up @@ -286,17 +322,7 @@ export default function FilterMenu({
disabled={loading}
color="secondary"
variant="contained"
onClick={() => {
setHidden(true)
setHandledBy("")
setStatus([CourseStatus.Active, CourseStatus.Upcoming])
setSearchVariables({
search: "",
hidden: true,
handledBy: null,
status: [CourseStatus.Active, CourseStatus.Upcoming],
})
}}
onClick={handleResetAll}
>
{t("reset")}
</Button>
Expand Down
3 changes: 2 additions & 1 deletion frontend/components/HeaderBar/MoocLogo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ const MoocLogo = () => (
<MoocLogoLink aria-label="MOOC.fi homepage">
<MoocLogoAvatar
alt="MOOC logo"
src={require("../../static/images/moocfi.svg")}
// src={require("../../static/images/moocfi.svg")}
src="/static/images/moocfi.svg"
/>
<MoocLogoText>MOOC.fi</MoocLogoText>
</MoocLogoLink>
Expand Down
14 changes: 10 additions & 4 deletions frontend/components/Home/CourseAndModuleList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ const CourseAndModuleList = () => {
const { studyModules, modulesWithCourses } = useMemo(() => {
let studyModules = modulesData?.study_modules ?? []
const modulesWithCourses = studyModules
.map((module) => {
.map((studyModule) => {
const moduleCourses = (courses ?? []).filter(
(course) =>
course.study_modules?.some(
(courseModule) => courseModule.id === module.id,
) && course?.status !== CourseStatus.Ended,
)

return { ...module, courses: moduleCourses }
return { ...studyModule, courses: moduleCourses }
})
.filter((m) => m.courses.length > 0)

Expand Down Expand Up @@ -126,8 +126,14 @@ const CourseAndModuleList = () => {
</section>
{language === "fi_FI" && (
<section id="modules">
<ModuleNavi modules={studyModules} loading={modulesLoading} />
<ModuleList modules={modulesWithCourses} loading={modulesLoading} />
<ModuleNavi
modules={studyModules}
loading={coursesLoading || modulesLoading}
/>
<ModuleList
modules={modulesWithCourses}
loading={coursesLoading || modulesLoading}
/>
</section>
)}
<CourseHighlights
Expand Down
Loading