import React, {KeyboardEventHandler, useEffect, useState} from 'react'; import IFrontendSettings from "./interfaces/IFrontendSettings"; import '../styles/settings.css'; import IBackendSettings from "./interfaces/IBackendSettings"; import {getData} from "../App"; import ILibraryConnector from "./interfaces/ILibraryConnector"; import INotificationConnector from "./interfaces/INotificationConnector"; export default function Settings({backendConnected, apiUri, settings, changeSettings} : {backendConnected: boolean, apiUri: string, settings: IFrontendSettings, changeSettings: (settings: IFrontendSettings) => void}) { const [frontendSettings] = useState(settings); const [backendSettings, setBackendSettings] = useState(); const [showSettings, setShowSettings] = useState(false); const [libraryConnectors, setLibraryConnectors] = useState([]); const [notificationConnectors, setNotificationConnectors] = useState([]); useEffect(() => { if(!showSettings || !backendConnected) return; GetSettings(apiUri).then(setBackendSettings).catch(console.error); GetLibraryConnectors(apiUri).then(setLibraryConnectors).catch(console.error); GetNotificationConnectors(apiUri).then(setNotificationConnectors).catch(console.error); }, [showSettings]); async function GetSettings(apiUri: string) : Promise { //console.info("Getting Settings"); return getData(`${apiUri}/v2/Settings`) .then((json) => { //console.info("Got Settings"); const ret = json as IBackendSettings; //console.debug(ret); return (ret); }) .catch(Promise.reject); } async function GetLibraryConnectors(apiUri: string) : Promise { //console.info("Getting Library Connectors"); return getData(`${apiUri}/v2/LibraryConnector`) .then((json) => { //console.info("Got Library Connectors"); const ret = json as ILibraryConnector[]; //console.debug(ret); return (ret); }) .catch(Promise.reject); } async function GetNotificationConnectors(apiUri: string) : Promise { //console.info("Getting Notification Connectors"); return getData(`${apiUri}/v2/NotificationConnector`) .then((json) => { //console.info("Got Notification Connectors"); const ret = json as INotificationConnector[]; //console.debug(ret); return (ret); }) .catch(Promise.reject); } function GetKomga() : ILibraryConnector | undefined { return libraryConnectors.find(con => con.libraryType == 0); } function GetKavita() : ILibraryConnector | undefined { return libraryConnectors.find(con => con.libraryType == 1); } function GetGotify() : INotificationConnector | undefined { return notificationConnectors.find(con => con.notificationConnectorType == 0); } function GetLunasea() : INotificationConnector | undefined { return notificationConnectors.find(con => con.notificationConnectorType == 1); } function GetNtfy() : INotificationConnector | undefined { return notificationConnectors.find(con => con.notificationConnectorType == 2); } const SubmitApiUri : KeyboardEventHandler = (e) => { if(e.key == "Enter") changeSettings(settings); } return (
cogwheel setShowSettings(true)}/> {showSettings ?

Settings

Close Settings setShowSettings(false)}/>
TRANGA
API Settings
Rate Limits
Appearance
Sources
Mangadex Logo MangaDex
LIBRARY CONNECTORS
Komga Logo Komga
Test Reset Apply
Kavita Logo Kavita
Test Reset Apply
NOTIFICATION CONNECTORS
Gotify Logo Gotify
Test Reset Apply
Lunasea Logo LunaSea
Test Reset Apply
ntfy Logo Ntfy
Test Reset Apply
: <> }
); }