Skip to content

Commit

Permalink
refactor: move useDocumentTitle to hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
webofpies committed Jan 20, 2025
1 parent 8fbc6d4 commit 5ac8508
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions frontend/src/features/book/components/Book/Book.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import { definedLangInfoQuery } from "@language/api/language";
import { termDataQuery } from "@term/api/term";
import { paneResizeStorage } from "@actions/utils";
import useNavigationProgress from "@hooks/useNavigationProgress";
import useDocumentTitle from "@hooks/useDocumentTitle";
import TranslationPane from "../TranslationPane/TranslationPane";
import ReadPane from "../ReadPane/ReadPane";
import { getBookQuery, getPageQuery } from "../../api/query";
import useSetupShortcuts from "../../hooks/useSetupShortcuts";
import useBookState from "../../hooks/useBookState";
import useDocumentTitle from "../../hooks/useDocumentTitle";
import classes from "./Book.module.css";

const ThemeForm = lazy(
Expand Down Expand Up @@ -45,7 +45,7 @@ function Book({ themeFormOpen, onThemeFormOpen, onDrawerOpen }) {
const { data: term } = useQuery(termDataQuery(key));

const [state, dispatch] = useBookState();
useDocumentTitle(book);
useDocumentTitle(`Reading "${book.title}"`);
useNavigationProgress();
useSetupShortcuts(dispatch, language, setActiveTerm, onThemeFormOpen);

Expand Down
14 changes: 0 additions & 14 deletions frontend/src/features/book/hooks/useDocumentTitle.jsx

This file was deleted.

14 changes: 14 additions & 0 deletions frontend/src/hooks/useDocumentTitle.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { useEffect } from "react";

function useDocumentTitle(title) {
useEffect(() => {
const prevTitle = document.title;
document.title = title;

return () => {
document.title = prevTitle;
};
}, [title]);
}

export default useDocumentTitle;

0 comments on commit 5ac8508

Please sign in to comment.