feat: contextual page title

This commit is contained in:
wpetit 2023-08-31 22:11:13 -06:00
parent 3fc3d813d3
commit 3fef770522
5 changed files with 27 additions and 12 deletions

View File

@ -0,0 +1,7 @@
import { useEffect } from "react"
export const useTitle = (title: string) => {
useEffect(() => {
window.document.title = `⏱️ | ${title}`
}, [title])
}

View File

@ -1,12 +1,15 @@
import React, { FunctionComponent, MouseEvent, useCallback, useState } from "react";
import React, { FunctionComponent, MouseEvent, useCallback, useEffect, useState } from "react";
import style from "./style.module.css";
import { useHistory } from 'react-router';
import { base58UUID } from '../../util/uuid';
import { useStoredProjectList } from "../../hooks/use-stored-project-list";
import { formatDate } from "../../util/date";
import { Direction, useSort } from "../../hooks/useSort";
import { useTitle } from "../../hooks/use-title";
const Home: FunctionComponent = () => {
useTitle('Accueil')
const [projects] = useStoredProjectList()
const [sortingKey, setSortingKey] = useState('updatedAt')
const [sortingDirection, setSortingDirection] = useState<Direction>(Direction.DESC)
@ -33,7 +36,6 @@ const Home: FunctionComponent = () => {
}
setSortingDirection(sortingDirection => -sortingDirection)
}, [sortingKey, sortingDirection])
return (

View File

@ -1,15 +1,18 @@
import React, { FunctionComponent } from "react";
import { Link } from 'react-router-dom';
import style from "./style.module.css";
import { useTitle } from "../../hooks/use-title";
const NotFound: FunctionComponent = () => {
return (
<div className={style.notFound}>
<h1>Error 404</h1>
<p>That page doesn't exist.</p>
<Link to="/"><h4>Back to Home</h4></Link>
</div>
);
useTitle("Page non trouvée")
return (
<div className={style.notFound}>
<h1>Erreur 404</h1>
<p>Cette page n'existe pas</p>
<Link to="/"><h4>Retour à la page d'accueil</h4></Link>
</div>
);
};
export default NotFound;

View File

@ -11,13 +11,14 @@ import ParamsTab from "./params-tab";
import ExportTab from "./export-tab";
import { useServerSync } from "../../hooks/use-server-sync";
import { RouteChildrenProps, RouteProps, useParams } from "react-router";
import { useTitle } from "../../hooks/use-title";
export interface ProjectProps {
projectId: string
}
const Project: FunctionComponent<ProjectProps> = () => {
const { projectId } = useParams();
const { projectId } = useParams<{ projectId: string }>();
const projectStorageKey = getProjectStorageKey(projectId);
const [ storedProject, storeProject ] = useLocalStorage(projectStorageKey, newProject(projectId));
const [ project, dispatch ] = useProjectReducer(storedProject);
@ -34,6 +35,8 @@ const Project: FunctionComponent<ProjectProps> = () => {
useEffect(()=> {
storeProject(project);
}, [project]);
useTitle(project.label ? project.label : "Projet sans nom")
return (
<div className={`container ${style.estimation}`}>

View File

@ -63,7 +63,7 @@ module.exports = {
plugins: [
new ForkTsCheckerWebpackPlugin(),
new HtmlWebpackPlugin({
title: 'Guesstimate',
title: '⏱️ Guesstimate',
scriptLoading: 'defer',
template: path.join(__dirname, 'src/index.html')
@ -87,7 +87,7 @@ module.exports = {
function getCurrentVersion() {
let version
try {
version = exec("git describe --abbrev=0 2>/dev/null")
version = exec("git describe --always 2>/dev/null")
} catch(err) {}
return version ? version : "0.0.0";
}