Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/FoxxMD/multi-scrobbler. Scrobble plays from multiple sources to multiple clients docs.multi-scrobbler.app
deezer docker jellyfin koito lastfm listenbrainz maloja mopidy mpris music music-assistant plex scrobble self-hosted spotify subsonic tautulli youtube-music
Something went wrong. Try again.
2.5 kB · 79 lines
TSX
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980import React, { useEffect, useState, useMemo } from "react"import BrowserOnly from "@docusaurus/BrowserOnly"import { useColorMode } from '@docusaurus/theme-common';
const STRINGIFY_JSON = (json: unknown) => JSON.stringify(json, null, "\t");import "../modern-json-react-styles.css";import { JSONSchema, Mode, ReactJsonEditor, createAjvValidator, type Content, type Validator } from 'modern-react-json-editor';import Ajv2020 from 'ajv/dist/2020';import f from "ajv-formats"import json5 from 'json5';
export interface SchemaEditorProps { config: object | string schema?: object height?: string}
// based on https://github.com/jy95/docusaurus-json-schema-plugin/blob/main/testsite/src/components/PlaygroundInner.tsxfunction SchemaEditorInner(props: SchemaEditorProps): JSX.Element {
const validator: Validator | undefined = useMemo(() => { if(props.schema === undefined) { return undefined; } return createAjvValidator({ schema: props.schema as JSONSchema, ajvOptions: { strict: "log", strictSchema: "log", allowUnionTypes: true, }, onCreateAjv: (ajv) => { const a = new Ajv2020(); a.addKeyword('deprecationMessage'); a.addKeyword('zockerId'); f.default(a); return a; } }); }, [props.schema]);
const initialData = useMemo(() => { let content: object; if(typeof props.config === 'string') { content = json5.parse(props.config); } else { content = props.config; } return {json: content}; },[props.config])
// const [data, setData] = useState({ json: props.config });
const { colorMode, // the "effective" color mode, never null } = useColorMode();
//const val = typeof props.config === 'object' ? STRINGIFY_JSON(props.config) : props.config; return ( <ReactJsonEditor validator={validator} theme={colorMode} mode={"text" as Mode.text} content={initialData} style={{height: 'initial'}} /> )}
export default function SchemaEditor(props: SchemaEditorProps): JSX.Element { return ( <BrowserOnly fallback={<div>Loading...</div>}> {() => { return <SchemaEditorInner {...props} /> }} </BrowserOnly> )}