set browser tab title (#220)
* Update the browser tab title The tab title will be set to the same title as the "NavigationBar" with "- Tachidesk" as the suffix * Set the manga title and chapter name as browser tab title in the reader While the reader is still loading the "mangaId" and the "chapterIndex" will be set as the title.
This commit is contained in:
@@ -14,7 +14,7 @@ type ContextType = {
|
|||||||
|
|
||||||
// AppBar title
|
// AppBar title
|
||||||
title: string
|
title: string
|
||||||
setTitle: React.Dispatch<React.SetStateAction<string>>
|
setTitle: (title: string) => void
|
||||||
|
|
||||||
// AppBar action buttons
|
// AppBar action buttons
|
||||||
action: any
|
action: any
|
||||||
|
|||||||
@@ -21,11 +21,16 @@ export default function NavBarProvider({ children }:IProps) {
|
|||||||
value: <div />,
|
value: <div />,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const updateTitle = (newTitle: string) => {
|
||||||
|
document.title = `${newTitle} - Tachidesk`;
|
||||||
|
setTitle(newTitle);
|
||||||
|
};
|
||||||
|
|
||||||
const value = {
|
const value = {
|
||||||
defaultBackTo,
|
defaultBackTo,
|
||||||
setDefaultBackTo,
|
setDefaultBackTo,
|
||||||
title,
|
title,
|
||||||
setTitle,
|
setTitle: updateTitle,
|
||||||
action,
|
action,
|
||||||
setAction,
|
setAction,
|
||||||
override,
|
override,
|
||||||
|
|||||||
@@ -85,6 +85,14 @@ export default function Reader() {
|
|||||||
requestUpdateMangaMetadata(manga, [[key, value]]).catch(() => makeToast('Failed to save the reader settings to the server', 'warning'));
|
requestUpdateMangaMetadata(manga, [[key, value]]).catch(() => makeToast('Failed to save the reader settings to the server', 'warning'));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!manga?.title || (chapter as IChapter)?.name === 'Loading...') {
|
||||||
|
setTitle(`Reader - Manga ${mangaId} Chapter ${chapterIndex}`);
|
||||||
|
} else {
|
||||||
|
setTitle(`${manga.title}: ${(chapter as IChapter).name}`);
|
||||||
|
}
|
||||||
|
}, [manga, chapter]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!areDefaultSettingsLoading && !isMangaLoading) {
|
if (!areDefaultSettingsLoading && !isMangaLoading) {
|
||||||
checkAndHandleMissingStoredReaderSettings(manga, 'manga', defaultSettings).catch(() => {});
|
checkAndHandleMissingStoredReaderSettings(manga, 'manga', defaultSettings).catch(() => {});
|
||||||
@@ -115,12 +123,10 @@ export default function Reader() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setIsMangaLoading(true);
|
setIsMangaLoading(true);
|
||||||
setTitle('Reader');
|
|
||||||
client.get(`/api/v1/manga/${mangaId}/`)
|
client.get(`/api/v1/manga/${mangaId}/`)
|
||||||
.then((response) => response.data)
|
.then((response) => response.data)
|
||||||
.then((data: IManga) => {
|
.then((data: IManga) => {
|
||||||
setManga(data);
|
setManga(data);
|
||||||
setTitle(data.title);
|
|
||||||
setIsMangaLoading(false);
|
setIsMangaLoading(false);
|
||||||
});
|
});
|
||||||
}, [mangaId]);
|
}, [mangaId]);
|
||||||
|
|||||||
Reference in New Issue
Block a user