Notebook-widget (#962)

* ⬆️ Add required dependencies

*  Add basic widget definition for `notebook`

* 🌐 Add basic translations for `notebook` widget

* 🐛 Fix `WidgetMenu` zIndex property

* ️ Use dynamic import for the `notebook` widget

* 🌐 Update translations

* 🚨 Disable eslint `no-param-reassign` rule

*  Add `notebook` widget

*  Add `immer` as a dependency

* fix: currentConfig not loaded in useEffect callback 

fixes #1249

* ♻️ Notebook widget UI (#1266)

* ♻️ Refactor note widget

* 🐛 Fix translations

* 💄 Widget styling changes

* 🔒 Fix lockfile

* 💄 Remove primary color from edit button

* 💄 Fix css

*  Add the ability to hide an option

* 🔥 Remove aria-labels

* ♻️ Address pull request feedback

* 🐛 Remove wrong description from default value

---------

Co-authored-by: gnattu <gnattu@users.noreply.github.com>
Co-authored-by: Manuel <manuel.ruwe@bluewin.ch>
Co-authored-by: Tagaishi <Tagaishi@hotmail.ch>
Co-authored-by: Meier Lukas <meierschlumpf@gmail.com>
This commit is contained in:
Thomas Camlong
2023-08-12 21:17:12 +02:00
committed by GitHub
parent 7614ec25c3
commit abb52b093a
12 changed files with 1435 additions and 1370 deletions

View File

@@ -15,6 +15,7 @@ import { rssRouter } from './routers/rss';
import { timezoneRouter } from './routers/timezone';
import { usenetRouter } from './routers/usenet/router';
import { weatherRouter } from './routers/weather';
import { notebookRouter } from './routers/notebook';
/**
* This is the primary router for your server.
@@ -37,6 +38,7 @@ export const rootRouter = createTRPCRouter({
timezone: timezoneRouter,
usenet: usenetRouter,
weather: weatherRouter,
notebook: notebookRouter
});
// export type definition of API

View File

@@ -0,0 +1,37 @@
import { TRPCError } from '@trpc/server';
import fs from 'fs';
import path from 'path';
import { z } from 'zod';
import { getConfig } from '~/tools/config/getConfig';
import { BackendConfigType } from '~/types/config';
import { INotebookWidget } from '~/widgets/notebook/NotebookWidgetTile';
import { createTRPCRouter, publicProcedure } from '../trpc';
export const notebookRouter = createTRPCRouter({
update: publicProcedure
.input(z.object({ widgetId: z.string(), content: z.string(), configName: z.string() }))
.mutation(async ({ input }) => {
const config = getConfig(input.configName);
const widget = config.widgets.find((widget) => widget.id === input.widgetId) as
| INotebookWidget
| undefined;
if (!widget) {
return new TRPCError({
code: 'BAD_REQUEST',
message: 'Specified widget was not found',
});
}
widget.properties.content = input.content;
const newConfig: BackendConfigType = {
...config,
widgets: [...config.widgets.filter((w) => w.id !== widget.id), widget],
};
const targetPath = path.join('data/configs', `${input.configName}.json`);
fs.writeFileSync(targetPath, JSON.stringify(newConfig, null, 2), 'utf8');
}),
});