etherpad-lite/admin/src/pages/SettingsPage.tsx

55 lines
2.4 KiB
TypeScript
Raw Normal View History

import {useStore} from "../store/store.ts";
import {isJSONClean} from "../utils/utils.ts";
import {Trans} from "react-i18next";
2024-03-13 14:58:14 +01:00
import {IconButton} from "../components/IconButton.tsx";
import {RotateCw, Save} from "lucide-react";
2024-03-13 15:20:17 +01:00
import Editor from '@monaco-editor/react';
export const SettingsPage = ()=>{
const settingsSocket = useStore(state=>state.settingsSocket)
const settings = useStore(state=>state.settings)
return <div>
<h1><Trans i18nKey="admin_settings.current"/></h1>
2024-03-13 14:58:14 +01:00
<Editor language="json" theme="vs-dark" options={{
2024-03-13 15:20:17 +01:00
comments: {
ignoreEmptyLines: true,
insertSpace: true
},
2024-03-13 14:58:14 +01:00
codeLens:false,
inDiffEditor: false
}} value={settings} onChange={(v)=>{
2024-03-13 15:20:17 +01:00
useStore.getState().setSettings(v!)
2024-03-13 14:58:14 +01:00
}} className="settings"/>
<div className="settings-button-bar">
2024-03-13 15:20:17 +01:00
<IconButton className="settingsButton" icon={<Save/>} title={<Trans i18nKey="admin_settings.current_save.value"/>} onClick={() => {
if (isJSONClean(settings!)) {
// JSON is clean so emit it to the server
settingsSocket!.emit('saveSettings', settings!);
useStore.getState().setToastState({
open: true,
title: "Succesfully saved settings",
success: true
})
} else {
useStore.getState().setToastState({
open: true,
title: "Error saving settings",
success: false
})
}
2024-03-13 14:58:14 +01:00
}}/>
<IconButton className="settingsButton" icon={<RotateCw/>} title={<Trans i18nKey="admin_settings.current_restart.value"/>} onClick={() => {
settingsSocket!.emit('restartServer');
2024-03-13 14:58:14 +01:00
}}/>
</div>
<div className="separator"/>
<div className="settings-button-bar">
<a rel="noopener noreferrer" target="_blank" href="https://github.com/ether/etherpad-lite/wiki/Example-Production-Settings.JSON"><Trans
i18nKey="admin_settings.current_example-prod"/></a>
<a rel="noopener noreferrer" target="_blank" href="https://github.com/ether/etherpad-lite/wiki/Example-Development-Settings.JSON"><Trans
i18nKey="admin_settings.current_example-devel"/></a>
</div>
</div>
}