diff --git a/client/entry-client.tsx b/client/entry-client.tsx index fbaba39..536d9e1 100644 --- a/client/entry-client.tsx +++ b/client/entry-client.tsx @@ -1,4 +1,10 @@ import { hydrate } from 'preact' import { App } from './App' +import { ClientContext } from './hooks' -hydrate(, document.body) +hydrate( + + + , + document.body +) diff --git a/client/hooks.tsx b/client/hooks.tsx index 8e991f2..f5068d0 100644 --- a/client/hooks.tsx +++ b/client/hooks.tsx @@ -1,4 +1,4 @@ -import { StateUpdater, useEffect, useState } from 'preact/hooks' +import { StateUpdater, useContext, useEffect, useState } from 'preact/hooks' import { createContext } from 'preact' import { prependBaseUrl, server } from './api' @@ -6,6 +6,7 @@ import { User } from '../shared/model' type Metadata = { title?: string + description?: string } export const MetadataContext = createContext({}) diff --git a/client/pages/Home.tsx b/client/pages/Home.tsx index 2a5e066..09c2f31 100644 --- a/client/pages/Home.tsx +++ b/client/pages/Home.tsx @@ -1,12 +1,12 @@ import { route } from 'preact-router' -import { useEffect, useState } from 'preact/hooks' +import { useContext, useEffect, useState } from 'preact/hooks' import { Problem as ProblemModel } from '../../shared/model' import { sortByNumericKey, sortByStringKey } from '../../shared/utils' import { Header } from '../components/Header' import { Problem } from '../components/Problem' import { Select } from '../components/Select' -import { useResource, useCurrentUser } from '../hooks' +import { useResource, useCurrentUser, MetadataContext } from '../hooks' function byTime(p: ProblemModel): string { return p.createdAt @@ -26,6 +26,10 @@ const SORT_ORDER: Record = { } export const HomePage = () => { + const metadata = useContext(MetadataContext) + metadata.title = `PHC Problemi` + metadata.description = 'Bacheca di problemi del PHC' + const [user] = useCurrentUser() const [problems] = useResource<(ProblemModel & { solutionsCount: number })[]>('/api/problems', []) diff --git a/client/pages/Problem.tsx b/client/pages/Problem.tsx index aa9d608..41d4634 100644 --- a/client/pages/Problem.tsx +++ b/client/pages/Problem.tsx @@ -14,6 +14,7 @@ type RouteProps = { export const ProblemPage = ({ id }: RouteProps) => { const metadata = useContext(MetadataContext) metadata.title = `Problem ${id}` + metadata.description = 'Bacheca di problemi del PHC' const [user] = useCurrentUser() diff --git a/server.ts b/server.ts index bf546d3..766218d 100644 --- a/server.ts +++ b/server.ts @@ -90,8 +90,6 @@ async function createProductionRouter() { const r = express.Router() - r.use('/', express.static('dist/entry-client')) - mountIndexHtmlRoutes(r, async (req, res) => { const transformedTemplate = await fs.readFile(path.resolve('./dist/entry-client/index.html'), 'utf-8') @@ -116,6 +114,8 @@ async function createProductionRouter() { ) }) + r.use('/', express.static('dist/entry-client')) + return r }