generated from mantinedev/vite-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added different document titles if the app is installed (#5)
- Loading branch information
Showing
9 changed files
with
41 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { useIsInstalled } from "./useIsInstalled"; | ||
export { useCustomDocumentTitle } from "./useCustomDocumentTitle"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { useDocumentTitle } from "@mantine/hooks"; | ||
|
||
import { APP_TITLE } from "../constants"; | ||
import { useIsInstalled } from "./useIsInstalled"; | ||
|
||
/** | ||
* A custom hook that sets the document title with a given title string. | ||
* If the app is not installed, the app title is prepended to the given title. | ||
* @param title - The title string to set as the document title. | ||
*/ | ||
export const useCustomDocumentTitle = (title: string) => { | ||
const isInstalled = useIsInstalled(); | ||
const prefix = isInstalled ? "" : `${APP_TITLE} - `; | ||
useDocumentTitle(`${prefix}${title}`); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** | ||
* Returns a boolean indicating whether the web app is installed on the user's device. | ||
* | ||
* @returns {boolean} A boolean indicating whether the web app is installed on the user's device. | ||
*/ | ||
export const useIsInstalled = () => { | ||
const isInstalled = window.matchMedia("(display-mode: standalone)").matches; | ||
|
||
return isInstalled; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import { | |
Title, | ||
} from "@mantine/core"; | ||
import { dateFormatter, isDNTEnabled } from "../utils/general"; | ||
import { useCustomDocumentTitle } from "../hooks"; | ||
|
||
const PRIVACY_POLICY_LAST_UPDATE = new Date("2022-09-03"); | ||
const CONTACT_EMAIL = "[email protected]"; | ||
|
@@ -16,6 +17,7 @@ const DNTstatus = isDNTEnabled() ? "ENABLED" : "DISABLED"; | |
const DNTstatusColor = isDNTEnabled() ? "green" : "red"; | ||
|
||
export default function Privacy() { | ||
useCustomDocumentTitle("Privacy Policy"); | ||
return ( | ||
<Container> | ||
<Title | ||
|