💄 Styling backgrounds of widgets

This commit is contained in:
ajnart
2022-05-29 09:11:46 +02:00
parent 0457c91ede
commit c7c76ee22b
4 changed files with 48 additions and 30 deletions

View File

@@ -1,7 +1,5 @@
import { getCookie, setCookies } from 'cookies-next';
import { GetServerSidePropsContext } from 'next';
import path from 'path';
import fs from 'fs';
import { useEffect } from 'react';
import AppShelf from '../components/AppShelf/AppShelf';
import LoadConfigComponent from '../components/Config/LoadConfig';
@@ -10,6 +8,7 @@ import { useConfig } from '../tools/state';
import { migrateToIdConfig } from '../tools/migrate';
import { ModuleWrapper } from '../components/modules/moduleWrapper';
import { DownloadsModule } from '../components/modules';
import { getConfig } from '../tools/getConfig';
export async function getServerSideProps({
req,
@@ -17,38 +16,20 @@ export async function getServerSideProps({
}: GetServerSidePropsContext): Promise<{ props: { config: Config } }> {
let cookie = getCookie('config-name', { req, res });
if (!cookie) {
setCookies('config-name', 'default', { req, res, maxAge: 60 * 60 * 24 * 30 });
setCookies('config-name', 'default', {
req,
res,
maxAge: 60 * 60 * 24 * 30,
sameSite: 'strict',
});
cookie = 'default';
}
// Check if the config file exists
const configPath = path.join(process.cwd(), 'data/configs', `${cookie}.json`);
if (!fs.existsSync(configPath)) {
return {
props: {
config: {
name: cookie.toString(),
services: [],
settings: {
searchUrl: 'https://www.google.com/search?q=',
},
modules: {},
},
},
};
}
const config = fs.readFileSync(configPath, 'utf8');
// Print loaded config
return {
props: {
config: JSON.parse(config),
},
};
return getConfig(cookie as string);
}
export default function HomePage(props: any) {
const { config: initialConfig }: { config: Config } = props;
const { config, loadConfig, setConfig, getConfigs } = useConfig();
const { setConfig } = useConfig();
useEffect(() => {
const migratedConfig = migrateToIdConfig(initialConfig);
setConfig(migratedConfig);