mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-11 16:05:47 +01:00
♻️ Use color scheme on board customize page
This commit is contained in:
@@ -3,6 +3,7 @@ import {
|
|||||||
ColorSwatch,
|
ColorSwatch,
|
||||||
Group,
|
Group,
|
||||||
Input,
|
Input,
|
||||||
|
MantineTheme,
|
||||||
Slider,
|
Slider,
|
||||||
Stack,
|
Stack,
|
||||||
Text,
|
Text,
|
||||||
@@ -14,6 +15,8 @@ import {
|
|||||||
import { useTranslation } from 'next-i18next';
|
import { useTranslation } from 'next-i18next';
|
||||||
import { highlight, languages } from 'prismjs';
|
import { highlight, languages } from 'prismjs';
|
||||||
import Editor from 'react-simple-code-editor';
|
import Editor from 'react-simple-code-editor';
|
||||||
|
import { useColorScheme } from '~/hooks/use-colorscheme';
|
||||||
|
import { useColorTheme } from '~/tools/color';
|
||||||
|
|
||||||
import { useBoardCustomizationFormContext } from '../form';
|
import { useBoardCustomizationFormContext } from '../form';
|
||||||
|
|
||||||
@@ -44,6 +47,7 @@ const ColorSelector = ({ type }: ColorSelectorProps) => {
|
|||||||
const { t } = useTranslation('boards/customize');
|
const { t } = useTranslation('boards/customize');
|
||||||
const theme = useMantineTheme();
|
const theme = useMantineTheme();
|
||||||
const form = useBoardCustomizationFormContext();
|
const form = useBoardCustomizationFormContext();
|
||||||
|
const { setPrimaryColor, setSecondaryColor } = useColorTheme();
|
||||||
|
|
||||||
const colors = Object.keys(theme.colors).map((color) => ({
|
const colors = Object.keys(theme.colors).map((color) => ({
|
||||||
swatch: theme.colors[color][6],
|
swatch: theme.colors[color][6],
|
||||||
@@ -58,7 +62,14 @@ const ColorSelector = ({ type }: ColorSelectorProps) => {
|
|||||||
key={color}
|
key={color}
|
||||||
component="button"
|
component="button"
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => form.getInputProps(`appearance.${type}`).onChange(color)}
|
onClick={() => {
|
||||||
|
form.getInputProps(`appearance.${type}`).onChange(color);
|
||||||
|
if (type === 'primaryColor') {
|
||||||
|
setPrimaryColor(color);
|
||||||
|
} else {
|
||||||
|
setSecondaryColor(color);
|
||||||
|
}
|
||||||
|
}}
|
||||||
color={swatch}
|
color={swatch}
|
||||||
style={{ cursor: 'pointer' }}
|
style={{ cursor: 'pointer' }}
|
||||||
>
|
>
|
||||||
@@ -73,6 +84,7 @@ const ColorSelector = ({ type }: ColorSelectorProps) => {
|
|||||||
const ShadeSelector = () => {
|
const ShadeSelector = () => {
|
||||||
const form = useBoardCustomizationFormContext();
|
const form = useBoardCustomizationFormContext();
|
||||||
const theme = useMantineTheme();
|
const theme = useMantineTheme();
|
||||||
|
const { setPrimaryShade } = useColorTheme();
|
||||||
|
|
||||||
const primaryColor = form.values.appearance.primaryColor;
|
const primaryColor = form.values.appearance.primaryColor;
|
||||||
const primaryShades = theme.colors[primaryColor].map((_, shade) => ({
|
const primaryShades = theme.colors[primaryColor].map((_, shade) => ({
|
||||||
@@ -88,7 +100,10 @@ const ShadeSelector = () => {
|
|||||||
key={shade}
|
key={shade}
|
||||||
component="button"
|
component="button"
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => form.getInputProps(`appearance.shade`).onChange(shade)}
|
onClick={() => {
|
||||||
|
form.getInputProps(`appearance.shade`).onChange(shade);
|
||||||
|
setPrimaryShade(shade as MantineTheme['primaryShade']);
|
||||||
|
}}
|
||||||
color={swatch}
|
color={swatch}
|
||||||
style={{ cursor: 'pointer' }}
|
style={{ cursor: 'pointer' }}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -39,9 +39,10 @@ export const ConfigProvider = ({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const config = currentConfig ?? fallbackConfig;
|
const config = currentConfig ?? fallbackConfig;
|
||||||
setPrimaryColor(config?.settings.customization.colors.primary || 'red');
|
if (!config) return;
|
||||||
setSecondaryColor(config?.settings.customization.colors.secondary || 'orange');
|
setPrimaryColor(config?.settings.customization.colors.primary ?? 'red');
|
||||||
setPrimaryShade(config?.settings.customization.colors.shade || 6);
|
setSecondaryColor(config?.settings.customization.colors.secondary ?? 'orange');
|
||||||
|
setPrimaryShade(config?.settings.customization.colors.shade ?? 6);
|
||||||
return () => {
|
return () => {
|
||||||
setPrimaryColor('red');
|
setPrimaryColor('red');
|
||||||
setSecondaryColor('orange');
|
setSecondaryColor('orange');
|
||||||
|
|||||||
@@ -40,19 +40,22 @@ function App(
|
|||||||
packageAttributes: ServerSidePackageAttributesType;
|
packageAttributes: ServerSidePackageAttributesType;
|
||||||
editModeEnabled: boolean;
|
editModeEnabled: boolean;
|
||||||
config?: ConfigType;
|
config?: ConfigType;
|
||||||
|
primaryColor?: MantineTheme['primaryColor'];
|
||||||
|
secondaryColor?: MantineTheme['primaryColor'];
|
||||||
|
primaryShade?: MantineTheme['primaryShade'];
|
||||||
session: Session;
|
session: Session;
|
||||||
}>
|
}>
|
||||||
) {
|
) {
|
||||||
const { Component, pageProps } = props;
|
const { Component, pageProps } = props;
|
||||||
|
|
||||||
const [primaryColor, setPrimaryColor] = useState<MantineTheme['primaryColor']>(
|
const [primaryColor, setPrimaryColor] = useState<MantineTheme['primaryColor']>(
|
||||||
props.pageProps.config?.settings.customization.colors.primary || 'red'
|
props.pageProps.primaryColor ?? 'red'
|
||||||
);
|
);
|
||||||
const [secondaryColor, setSecondaryColor] = useState<MantineTheme['primaryColor']>(
|
const [secondaryColor, setSecondaryColor] = useState<MantineTheme['primaryColor']>(
|
||||||
props.pageProps.config?.settings.customization.colors.secondary || 'orange'
|
props.pageProps.secondaryColor ?? 'orange'
|
||||||
);
|
);
|
||||||
const [primaryShade, setPrimaryShade] = useState<MantineTheme['primaryShade']>(
|
const [primaryShade, setPrimaryShade] = useState<MantineTheme['primaryShade']>(
|
||||||
props.pageProps.config?.settings.customization.colors.shade || 6
|
props.pageProps.primaryShade ?? 6
|
||||||
);
|
);
|
||||||
const colorTheme = {
|
const colorTheme = {
|
||||||
primaryColor,
|
primaryColor,
|
||||||
|
|||||||
@@ -57,6 +57,9 @@ export const getServerSideProps: GetServerSideProps<BoardGetServerSideProps> = a
|
|||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
config,
|
config,
|
||||||
|
primaryColor: config.settings.customization.colors.primary,
|
||||||
|
secondaryColor: config.settings.customization.colors.secondary,
|
||||||
|
primaryShade: config.settings.customization.colors.shade,
|
||||||
...translations,
|
...translations,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import { useTranslation } from 'next-i18next';
|
|||||||
import Head from 'next/head';
|
import Head from 'next/head';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import { useRouter } from 'next/router';
|
import { useRouter } from 'next/router';
|
||||||
import { ReactNode } from 'react';
|
import { ReactNode, useEffect } from 'react';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
import { AppearanceCustomization } from '~/components/Board/Customize/Appearance/AppearanceCustomization';
|
import { AppearanceCustomization } from '~/components/Board/Customize/Appearance/AppearanceCustomization';
|
||||||
import { GridstackCustomization } from '~/components/Board/Customize/Gridstack/GridstackCustomization';
|
import { GridstackCustomization } from '~/components/Board/Customize/Gridstack/GridstackCustomization';
|
||||||
@@ -28,8 +28,8 @@ import {
|
|||||||
import { MainLayout } from '~/components/layout/Templates/MainLayout';
|
import { MainLayout } from '~/components/layout/Templates/MainLayout';
|
||||||
import { createTrpcServersideHelpers } from '~/server/api/helper';
|
import { createTrpcServersideHelpers } from '~/server/api/helper';
|
||||||
import { getServerAuthSession } from '~/server/auth';
|
import { getServerAuthSession } from '~/server/auth';
|
||||||
|
import { useColorTheme } from '~/tools/color';
|
||||||
import { getServerSideTranslations } from '~/tools/server/getServerSideTranslations';
|
import { getServerSideTranslations } from '~/tools/server/getServerSideTranslations';
|
||||||
import { boardNamespaces } from '~/tools/server/translation-namespaces';
|
|
||||||
import { firstUpperCase } from '~/tools/shared/strings';
|
import { firstUpperCase } from '~/tools/shared/strings';
|
||||||
import { api } from '~/utils/api';
|
import { api } from '~/utils/api';
|
||||||
import { useI18nZodResolver } from '~/utils/i18n-zod-resolver';
|
import { useI18nZodResolver } from '~/utils/i18n-zod-resolver';
|
||||||
@@ -212,7 +212,7 @@ export const getServerSideProps: GetServerSideProps = async ({ req, res, locale,
|
|||||||
|
|
||||||
const helpers = await createTrpcServersideHelpers({ req, res });
|
const helpers = await createTrpcServersideHelpers({ req, res });
|
||||||
|
|
||||||
helpers.config.byName.prefetch({ name: routeParams.data.slug });
|
const config = await helpers.config.byName.fetch({ name: routeParams.data.slug });
|
||||||
|
|
||||||
const translations = await getServerSideTranslations(
|
const translations = await getServerSideTranslations(
|
||||||
[
|
[
|
||||||
@@ -231,6 +231,9 @@ export const getServerSideProps: GetServerSideProps = async ({ req, res, locale,
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
|
primaryColor: config.settings.customization.colors.primary,
|
||||||
|
secondaryColor: config.settings.customization.colors.secondary,
|
||||||
|
primaryShade: config.settings.customization.colors.shade,
|
||||||
trpcState: helpers.dehydrate(),
|
trpcState: helpers.dehydrate(),
|
||||||
...translations,
|
...translations,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -47,6 +47,9 @@ export const getServerSideProps: GetServerSideProps<BoardGetServerSideProps> = a
|
|||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
config,
|
config,
|
||||||
|
primaryColor: config.settings.customization.colors.primary,
|
||||||
|
secondaryColor: config.settings.customization.colors.secondary,
|
||||||
|
primaryShade: config.settings.customization.colors.shade,
|
||||||
...translations,
|
...translations,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user