feat: add page titles

This commit is contained in:
2024-04-21 02:06:10 +02:00
parent 6998d0a05e
commit bd1889a491
3 changed files with 16 additions and 0 deletions

View File

@@ -8,10 +8,12 @@ import {
TableHeadCell, TableHeadCell,
TableRow, TableRow,
} from "./ui/table/table"; } from "./ui/table/table";
import { useTitle } from "../hooks/use-title";
export function PodcastEpisodesList() { export function PodcastEpisodesList() {
const { podcastId } = useParams<{ podcastId: string }>(); const { podcastId } = useParams<{ podcastId: string }>();
const { data: podcast } = usePodcastQuery(podcastId); const { data: podcast } = usePodcastQuery(podcastId);
useTitle(podcast?.title ?? "Podcast");
return ( return (
<div> <div>

11
src/hooks/use-title.ts Normal file
View File

@@ -0,0 +1,11 @@
import { useEffect } from "react";
export function useTitle(title: string) {
useEffect(() => {
const prevTitle = document.title;
document.title = title;
return () => {
document.title = prevTitle;
};
});
}

View File

@@ -1,5 +1,6 @@
import { useParams } from "react-router-dom"; import { useParams } from "react-router-dom";
import { usePodcastQuery } from "../services/podcasts/podcast.hooks"; import { usePodcastQuery } from "../services/podcasts/podcast.hooks";
import { useTitle } from "../hooks/use-title";
export function Episode() { export function Episode() {
const { podcastId, episodeId } = useParams<{ const { podcastId, episodeId } = useParams<{
@@ -13,6 +14,8 @@ export function Episode() {
(episode) => episode.id.toString() === episodeId, (episode) => episode.id.toString() === episodeId,
); );
useTitle(episode?.title ?? "Episode");
return ( return (
<div className={"h-fit w-full p-4 pb-6 shadow-md"}> <div className={"h-fit w-full p-4 pb-6 shadow-md"}>
<h2 className={"text-2xl font-bold tracking-tight"}>{episode?.title}</h2> <h2 className={"text-2xl font-bold tracking-tight"}>{episode?.title}</h2>