Allow override of theme on shared documents
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
||||
buildPitchBlackTheme,
|
||||
} from "@shared/styles/theme";
|
||||
import { CustomTheme } from "@shared/types";
|
||||
import type { Theme } from "~/stores/UiStore";
|
||||
import useMediaQuery from "~/hooks/useMediaQuery";
|
||||
import useStores from "./useStores";
|
||||
|
||||
@@ -14,25 +15,30 @@ import useStores from "./useStores";
|
||||
* and the custom theme provided.
|
||||
*
|
||||
* @param customTheme Custom theme to merge with the default theme
|
||||
* @param overrideTheme Optional override the theme to use
|
||||
* @returns The theme to use
|
||||
*/
|
||||
export default function useBuildTheme(customTheme: Partial<CustomTheme> = {}) {
|
||||
export default function useBuildTheme(
|
||||
customTheme: Partial<CustomTheme> = {},
|
||||
overrideTheme?: Theme
|
||||
) {
|
||||
const { ui } = useStores();
|
||||
const isMobile = useMediaQuery(`(max-width: ${breakpoints.tablet}px)`);
|
||||
const isPrinting = useMediaQuery("print");
|
||||
const resolvedTheme = overrideTheme ?? ui.resolvedTheme;
|
||||
|
||||
const theme = React.useMemo(
|
||||
() =>
|
||||
isPrinting
|
||||
? buildLightTheme(customTheme)
|
||||
: isMobile
|
||||
? ui.resolvedTheme === "dark"
|
||||
? resolvedTheme === "dark"
|
||||
? buildPitchBlackTheme(customTheme)
|
||||
: buildLightTheme(customTheme)
|
||||
: ui.resolvedTheme === "dark"
|
||||
: resolvedTheme === "dark"
|
||||
? buildDarkTheme(customTheme)
|
||||
: buildLightTheme(customTheme),
|
||||
[customTheme, isMobile, isPrinting, ui.resolvedTheme]
|
||||
[customTheme, isMobile, isPrinting, resolvedTheme]
|
||||
);
|
||||
|
||||
return theme;
|
||||
|
||||
@@ -8,6 +8,7 @@ import styled, { ThemeProvider } from "styled-components";
|
||||
import { setCookie } from "tiny-cookie";
|
||||
import { s } from "@shared/styles";
|
||||
import { NavigationNode, PublicTeam } from "@shared/types";
|
||||
import type { Theme } from "~/stores/UiStore";
|
||||
import DocumentModel from "~/models/Document";
|
||||
import Error404 from "~/scenes/Error404";
|
||||
import ErrorOffline from "~/scenes/ErrorOffline";
|
||||
@@ -94,8 +95,13 @@ function SharedDocumentScene(props: Props) {
|
||||
const { documents } = useStores();
|
||||
const { shareId, documentSlug } = props.match.params;
|
||||
const documentId = useDocumentId(documentSlug, response);
|
||||
const themeOverride = ["dark", "light"].includes(
|
||||
searchParams.get("theme") || ""
|
||||
)
|
||||
? (searchParams.get("theme") as Theme)
|
||||
: undefined;
|
||||
const can = usePolicy(response?.document.id ?? "");
|
||||
const theme = useBuildTheme(response?.team?.customTheme);
|
||||
const theme = useBuildTheme(response?.team?.customTheme, themeOverride);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!auth.user) {
|
||||
|
||||
Reference in New Issue
Block a user