Skip to content

Commit 82dca1b

Browse files
authored
Sync page title and document title (#1032)
* Sync page title and document title * update readme
1 parent 2a59c53 commit 82dca1b

19 files changed

+387
-273
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ The following changes are already implemented:
144144
* 📋 [Add User Memberships tab](https://github.com/etkecc/synapse-admin/issues/1002)
145145
* 🐋 [Run rootless in Docker container](https://github.com/etkecc/synapse-admin/issues/1021)
146146
* 🇮🇷 [Fix loading of Persian localization](https://github.com/etkecc/synapse-admin/commit/737ec69b16da62e515be12778c46823f6525df4e#diff-26ad4b834941d9b19ebf9db8082bd202aaf72ea0ddea85f5a8a0cb3c729cc6f2)
147+
* 🔖 [Sync page title and document title](https://github.com/etkecc/synapse-admin/pull/1032)
147148

148149
#### exclusive for [etke.cc](https://etke.cc) customers
149150

src/components/AdminLayout.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,14 @@ export const AdminLayout = ({ children }) => {
168168
const icfg = GetInstanceConfig();
169169
useEffect(() => {
170170
document.documentElement.lang = locale;
171-
// set <title> based on instance name
172-
if (icfg.name) {
171+
172+
// copy of the code from index.tsx to set base title dynamically
173+
document.head.dataset.baseTitle = icfg.name || "Synapse Admin";
174+
// set <title> based on instance name, only if it's not already set
175+
if (icfg.name && !document.title.includes(icfg.name)) {
173176
document.title = icfg.name;
174177
}
178+
175179
if (icfg.favicon_url) {
176180
const link: HTMLLinkElement | null = document.querySelector("link[rel~='icon']");
177181
if (link) {

src/components/etke.cc/BillingPage.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { Title, useDataProvider, useLocale, useNotify, useTranslate } from "reac
2424
import { EtkeAttribution } from "./EtkeAttribution";
2525
import { useAppContext } from "../../Context";
2626
import { SynapseDataProvider, Payment } from "../../synapse/dataProvider";
27+
import { useDocTitle } from "../hooks/useDocTitle";
2728

2829
const TruncatedUUID = ({ uuid }): React.ReactElement => {
2930
const short = `${uuid.slice(0, 8)}...${uuid.slice(-6)}`;
@@ -53,6 +54,7 @@ const BillingPage = () => {
5354
const [failure, setFailure] = useState<string | null>(null);
5455
const [downloadingInvoice, setDownloadingInvoice] = useState<string | null>(null);
5556

57+
useDocTitle(translate("etkecc.billing.name"));
5658
useEffect(() => {
5759
const fetchBillingData = async () => {
5860
if (!etkeccAdmin) return;

src/components/etke.cc/ServerActionsPage.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ import { Title, useTranslate } from "react-admin";
66
import CurrentlyRunningCommand from "./CurrentlyRunningCommand";
77
import { EtkeAttribution } from "./EtkeAttribution";
88
import ServerCommandsPanel from "./ServerCommandsPanel";
9+
import { useDocTitle } from "../hooks/useDocTitle";
910
import RecurringCommandsList from "./schedules/components/recurring/RecurringCommandsList";
1011
import ScheduledCommandsList from "./schedules/components/scheduled/ScheduledCommandsList";
1112

1213
const ServerActionsPage = () => {
1314
const translate = useTranslate();
15+
useDocTitle(translate("etkecc.actions.name"));
1416

1517
return (
1618
<>

src/components/etke.cc/ServerNotificationsPage.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Title, useLocale, useStore, useTranslate } from "react-admin";
77
import { useAppContext } from "../../Context";
88
import dataProvider, { ServerNotificationsResponse } from "../../synapse/dataProvider";
99
import { getTimeSince } from "../../utils/date";
10+
import { useDocTitle } from "../hooks/useDocTitle";
1011

1112
const ServerNotificationsPage = () => {
1213
const locale = useLocale();
@@ -17,6 +18,8 @@ const ServerNotificationsPage = () => {
1718
success: false,
1819
});
1920

21+
useDocTitle(translate("etkecc.notifications.title"));
22+
2023
const notifications = serverNotifications.notifications;
2124

2225
return (

src/components/etke.cc/ServerStatusPage.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { Title } from "react-admin";
88
import CurrentlyRunningCommand from "./CurrentlyRunningCommand";
99
import { EtkeAttribution } from "./EtkeAttribution";
1010
import { ServerProcessResponse, ServerStatusComponent, ServerStatusResponse } from "../../synapse/dataProvider";
11+
import { useDocTitle } from "../hooks/useDocTitle";
1112

1213
const StatusChip = ({
1314
isOkay,
@@ -44,6 +45,7 @@ const ServerComponentText = ({ text }: { text: string }) => {
4445

4546
const ServerStatusPage = () => {
4647
const translate = useTranslate();
48+
useDocTitle(translate("etkecc.status.name"));
4749
const errorLabel = translate("etkecc.status.error");
4850
const [serverStatus, _setServerStatus] = useStore<ServerStatusResponse>("serverStatus", {
4951
ok: false,

src/components/etke.cc/schedules/components/recurring/RecurringCommandEdit.tsx

Lines changed: 74 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ import {
1313
SelectInput,
1414
TimeInput,
1515
useTranslate,
16+
Title,
1617
} from "react-admin";
1718
import { useWatch } from "react-hook-form";
1819
import { useParams, useNavigate } from "react-router-dom";
1920

2021
import RecurringDeleteButton from "./RecurringDeleteButton";
2122
import { useAppContext } from "../../../../../Context";
2223
import { RecurringCommand } from "../../../../../synapse/dataProvider";
24+
import { useDocTitle } from "../../../../hooks/useDocTitle";
2325
import { EtkeAttribution } from "../../../EtkeAttribution";
2426
import { useServerCommands } from "../../../hooks/useServerCommands";
2527
import { useRecurringCommands } from "../../hooks/useRecurringCommands";
@@ -59,6 +61,7 @@ const RecurringCommandEdit = () => {
5961
const pageTitle = isCreating
6062
? translate("etkecc.actions.recurring_title_create")
6163
: translate("etkecc.actions.recurring_title_edit");
64+
useDocTitle(pageTitle);
6265

6366
const commandChoices = transformCommandsToChoices(serverCommands);
6467
const dayOfWeekChoices = [
@@ -144,74 +147,79 @@ const RecurringCommandEdit = () => {
144147
}
145148

146149
return (
147-
<Box sx={{ mt: 2 }}>
148-
<Button
149-
label={translate("etkecc.actions.buttons.back")}
150-
onClick={() => navigate("/server_actions")}
151-
startIcon={<ArrowBackIcon />}
152-
sx={{ mb: 2 }}
153-
/>
154-
155-
<Card>
156-
<CardHeader title={pageTitle} />
157-
<CardContent>
158-
{command && (
159-
<EtkeAttribution>
160-
<Alert severity="info">
161-
<Typography variant="body1" sx={{ px: 2 }}>
162-
{translate("etkecc.actions.command_details_intro")}{" "}
163-
<Link href={`https://etke.cc/help/extras/scheduler/#${command.command}`} target="_blank">
164-
{`etke.cc/help/extras/scheduler/#${command.command}`}
165-
</Link>
166-
.
167-
</Typography>
168-
</Alert>
169-
</EtkeAttribution>
170-
)}
171-
<Form
172-
defaultValues={command || undefined}
173-
onSubmit={handleSubmit}
174-
record={command || undefined}
175-
warnWhenUnsavedChanges
176-
>
177-
<Box display="flex" flexDirection="column" gap={2}>
178-
{!isCreating && (
179-
<TextInput readOnly source="id" label={translate("etkecc.actions.form.id")} fullWidth required />
180-
)}
181-
<SelectInput
182-
source="command"
183-
choices={commandChoices}
184-
label={translate("etkecc.actions.form.command")}
185-
fullWidth
186-
required
187-
/>
188-
<ArgumentsField serverCommands={serverCommands} />
189-
<SelectInput
190-
source="day_of_week"
191-
choices={dayOfWeekChoices}
192-
label={translate("etkecc.actions.form.day_of_week")}
193-
fullWidth
194-
required
195-
/>
196-
<TimeInput
197-
source="execution_time"
198-
label={translate("etkecc.actions.table.time_utc")}
199-
fullWidth
200-
required
201-
/>
202-
<Box mt={2} display="flex" justifyContent="space-between">
203-
<SaveButton
204-
label={
205-
isCreating ? translate("etkecc.actions.buttons.create") : translate("etkecc.actions.buttons.update")
206-
}
150+
<>
151+
<Title title={pageTitle} />
152+
<Box sx={{ mt: 2 }}>
153+
<Button
154+
label={translate("etkecc.actions.buttons.back")}
155+
onClick={() => navigate("/server_actions")}
156+
startIcon={<ArrowBackIcon />}
157+
sx={{ mb: 2 }}
158+
/>
159+
160+
<Card>
161+
<CardHeader title={pageTitle} />
162+
<CardContent>
163+
{command && (
164+
<EtkeAttribution>
165+
<Alert severity="info">
166+
<Typography variant="body1" sx={{ px: 2 }}>
167+
{translate("etkecc.actions.command_details_intro")}{" "}
168+
<Link href={`https://etke.cc/help/extras/scheduler/#${command.command}`} target="_blank">
169+
{`etke.cc/help/extras/scheduler/#${command.command}`}
170+
</Link>
171+
.
172+
</Typography>
173+
</Alert>
174+
</EtkeAttribution>
175+
)}
176+
<Form
177+
defaultValues={command || undefined}
178+
onSubmit={handleSubmit}
179+
record={command || undefined}
180+
warnWhenUnsavedChanges
181+
>
182+
<Box display="flex" flexDirection="column" gap={2}>
183+
{!isCreating && (
184+
<TextInput readOnly source="id" label={translate("etkecc.actions.form.id")} fullWidth required />
185+
)}
186+
<SelectInput
187+
source="command"
188+
choices={commandChoices}
189+
label={translate("etkecc.actions.form.command")}
190+
fullWidth
191+
required
207192
/>
208-
{!isCreating && <RecurringDeleteButton />}
193+
<ArgumentsField serverCommands={serverCommands} />
194+
<SelectInput
195+
source="day_of_week"
196+
choices={dayOfWeekChoices}
197+
label={translate("etkecc.actions.form.day_of_week")}
198+
fullWidth
199+
required
200+
/>
201+
<TimeInput
202+
source="execution_time"
203+
label={translate("etkecc.actions.table.time_utc")}
204+
fullWidth
205+
required
206+
/>
207+
<Box mt={2} display="flex" justifyContent="space-between">
208+
<SaveButton
209+
label={
210+
isCreating
211+
? translate("etkecc.actions.buttons.create")
212+
: translate("etkecc.actions.buttons.update")
213+
}
214+
/>
215+
{!isCreating && <RecurringDeleteButton />}
216+
</Box>
209217
</Box>
210-
</Box>
211-
</Form>
212-
</CardContent>
213-
</Card>
214-
</Box>
218+
</Form>
219+
</CardContent>
220+
</Card>
221+
</Box>
222+
</>
215223
);
216224
};
217225

0 commit comments

Comments
 (0)