|
1 |
| -import {useEffect} from 'react' |
| 1 | +import {useEffect, useState} from 'react' |
2 | 2 | import './App.css'
|
3 | 3 | import {connect} from 'socket.io-client'
|
4 | 4 | import {isJSONClean} from './utils/utils.ts'
|
5 | 5 | import {NavLink, Outlet, useNavigate} from "react-router-dom";
|
6 | 6 | import {useStore} from "./store/store.ts";
|
7 | 7 | import {LoadingScreen} from "./utils/LoadingScreen.tsx";
|
8 | 8 | import {Trans, useTranslation} from "react-i18next";
|
9 |
| -import {Cable, Construction, Crown, NotepadText, Wrench, PhoneCall} from "lucide-react"; |
| 9 | +import {Cable, Construction, Crown, NotepadText, Wrench, PhoneCall, LucideMenu} from "lucide-react"; |
10 | 10 |
|
11 |
| -const WS_URL = import.meta.env.DEV? 'http://localhost:9001' : '' |
12 |
| -export const App = ()=> { |
13 |
| - const setSettings = useStore(state => state.setSettings); |
14 |
| - const {t} = useTranslation() |
15 |
| - const navigate = useNavigate() |
| 11 | +const WS_URL = import.meta.env.DEV ? 'http://localhost:9001' : '' |
| 12 | +export const App = () => { |
| 13 | + const setSettings = useStore(state => state.setSettings); |
| 14 | + const {t} = useTranslation() |
| 15 | + const navigate = useNavigate() |
| 16 | + const [sidebarOpen, setSidebarOpen] = useState<boolean>(true) |
16 | 17 |
|
17 |
| - useEffect(() => { |
18 |
| - fetch('/admin-auth/', { |
19 |
| - method: 'POST' |
20 |
| - }).then((value)=>{ |
21 |
| - if(!value.ok){ |
22 |
| - navigate('/login') |
23 |
| - } |
24 |
| - }).catch(()=>{ |
25 |
| - navigate('/login') |
26 |
| - }) |
27 |
| - }, []); |
| 18 | + useEffect(() => { |
| 19 | + fetch('/admin-auth/', { |
| 20 | + method: 'POST' |
| 21 | + }).then((value) => { |
| 22 | + if (!value.ok) { |
| 23 | + navigate('/login') |
| 24 | + } |
| 25 | + }).catch(() => { |
| 26 | + navigate('/login') |
| 27 | + }) |
| 28 | + }, []); |
28 | 29 |
|
29 |
| - useEffect(() => { |
30 |
| - document.title = t('admin.page-title') |
| 30 | + useEffect(() => { |
| 31 | + document.title = t('admin.page-title') |
31 | 32 |
|
32 |
| - useStore.getState().setShowLoading(true); |
33 |
| - const settingSocket = connect(`${WS_URL}/settings`, { |
34 |
| - transports: ['websocket'], |
35 |
| - }); |
| 33 | + useStore.getState().setShowLoading(true); |
| 34 | + const settingSocket = connect(`${WS_URL}/settings`, { |
| 35 | + transports: ['websocket'], |
| 36 | + }); |
36 | 37 |
|
37 |
| - const pluginsSocket = connect(`${WS_URL}/pluginfw/installer`, { |
38 |
| - transports: ['websocket'], |
39 |
| - }) |
| 38 | + const pluginsSocket = connect(`${WS_URL}/pluginfw/installer`, { |
| 39 | + transports: ['websocket'], |
| 40 | + }) |
40 | 41 |
|
41 |
| - pluginsSocket.on('connect', () => { |
42 |
| - useStore.getState().setPluginsSocket(pluginsSocket); |
43 |
| - }); |
| 42 | + pluginsSocket.on('connect', () => { |
| 43 | + useStore.getState().setPluginsSocket(pluginsSocket); |
| 44 | + }); |
44 | 45 |
|
45 | 46 |
|
46 |
| - settingSocket.on('connect', () => { |
47 |
| - useStore.getState().setSettingsSocket(settingSocket); |
48 |
| - useStore.getState().setShowLoading(false) |
49 |
| - settingSocket.emit('load'); |
50 |
| - console.log('connected'); |
51 |
| - }); |
| 47 | + settingSocket.on('connect', () => { |
| 48 | + useStore.getState().setSettingsSocket(settingSocket); |
| 49 | + useStore.getState().setShowLoading(false) |
| 50 | + settingSocket.emit('load'); |
| 51 | + console.log('connected'); |
| 52 | + }); |
52 | 53 |
|
53 |
| - settingSocket.on('disconnect', (reason) => { |
54 |
| - // The settingSocket.io client will automatically try to reconnect for all reasons other than "io |
55 |
| - // server disconnect". |
56 |
| - useStore.getState().setShowLoading(true) |
57 |
| - if (reason === 'io server disconnect') { |
58 |
| - settingSocket.connect(); |
59 |
| - } |
60 |
| - }); |
| 54 | + settingSocket.on('disconnect', (reason) => { |
| 55 | + // The settingSocket.io client will automatically try to reconnect for all reasons other than "io |
| 56 | + // server disconnect". |
| 57 | + useStore.getState().setShowLoading(true) |
| 58 | + if (reason === 'io server disconnect') { |
| 59 | + settingSocket.connect(); |
| 60 | + } |
| 61 | + }); |
61 | 62 |
|
62 |
| - settingSocket.on('settings', (settings) => { |
63 |
| - /* Check whether the settings.json is authorized to be viewed */ |
64 |
| - if (settings.results === 'NOT_ALLOWED') { |
65 |
| - console.log('Not allowed to view settings.json') |
66 |
| - return; |
67 |
| - } |
| 63 | + settingSocket.on('settings', (settings) => { |
| 64 | + /* Check whether the settings.json is authorized to be viewed */ |
| 65 | + if (settings.results === 'NOT_ALLOWED') { |
| 66 | + console.log('Not allowed to view settings.json') |
| 67 | + return; |
| 68 | + } |
68 | 69 |
|
69 |
| - /* Check to make sure the JSON is clean before proceeding */ |
70 |
| - if (isJSONClean(settings.results)) { |
71 |
| - setSettings(settings.results); |
72 |
| - } else { |
73 |
| - alert('Invalid JSON'); |
74 |
| - } |
75 |
| - useStore.getState().setShowLoading(false); |
76 |
| - }); |
| 70 | + /* Check to make sure the JSON is clean before proceeding */ |
| 71 | + if (isJSONClean(settings.results)) { |
| 72 | + setSettings(settings.results); |
| 73 | + } else { |
| 74 | + alert('Invalid JSON'); |
| 75 | + } |
| 76 | + useStore.getState().setShowLoading(false); |
| 77 | + }); |
77 | 78 |
|
78 |
| - settingSocket.on('saveprogress', (status)=>{ |
79 |
| - console.log(status) |
80 |
| - }) |
| 79 | + settingSocket.on('saveprogress', (status) => { |
| 80 | + console.log(status) |
| 81 | + }) |
81 | 82 |
|
82 |
| - return () => { |
83 |
| - settingSocket.disconnect(); |
84 |
| - pluginsSocket.disconnect() |
85 |
| - } |
86 |
| - }, []); |
| 83 | + return () => { |
| 84 | + settingSocket.disconnect(); |
| 85 | + pluginsSocket.disconnect() |
| 86 | + } |
| 87 | + }, []); |
87 | 88 |
|
88 |
| - return <div id="wrapper"> |
89 |
| - <LoadingScreen/> |
90 |
| - <div className="menu"> |
91 |
| - <div className="inner-menu"> |
92 |
| - <span> |
| 89 | + return <div id="wrapper" className={`${sidebarOpen ? '': 'closed' }`}> |
| 90 | + <LoadingScreen/> |
| 91 | + <div className="menu"> |
| 92 | + <div className="inner-menu"> |
| 93 | + <span> |
93 | 94 | <Crown width={40} height={40}/>
|
94 | 95 | <h1>Etherpad</h1>
|
95 | 96 | </span>
|
96 |
| - <ul> |
97 |
| - <li><NavLink to="/plugins"><Cable/><Trans i18nKey="admin_plugins"/></NavLink></li> |
98 |
| - <li><NavLink to={"/settings"}><Wrench/><Trans i18nKey="admin_settings"/></NavLink></li> |
99 |
| - <li><NavLink to={"/help"}> <Construction/> <Trans i18nKey="admin_plugins_info"/></NavLink></li> |
100 |
| - <li><NavLink to={"/pads"}><NotepadText/><Trans |
101 |
| - i18nKey="ep_admin_pads:ep_adminpads2_manage-pads"/></NavLink></li> |
102 |
| - <li><NavLink to={"/shout"}><PhoneCall/>Communication</NavLink></li> |
103 |
| - </ul> |
104 |
| - </div> |
105 |
| - </div> |
106 |
| - <div className="innerwrapper"> |
107 |
| - <Outlet/> |
108 |
| - </div> |
| 97 | + <ul onClick={()=>{ |
| 98 | + setSidebarOpen(false) |
| 99 | + }}> |
| 100 | + <li><NavLink to="/plugins"><Cable/><Trans i18nKey="admin_plugins"/></NavLink></li> |
| 101 | + <li><NavLink to={"/settings"}><Wrench/><Trans i18nKey="admin_settings"/></NavLink></li> |
| 102 | + <li><NavLink to={"/help"}> <Construction/> <Trans i18nKey="admin_plugins_info"/></NavLink></li> |
| 103 | + <li><NavLink to={"/pads"}><NotepadText/><Trans |
| 104 | + i18nKey="ep_admin_pads:ep_adminpads2_manage-pads"/></NavLink></li> |
| 105 | + <li><NavLink to={"/shout"}><PhoneCall/>Communication</NavLink></li> |
| 106 | + </ul> |
| 107 | + </div> |
109 | 108 | </div>
|
| 109 | + <button id="icon-button" onClick={() => { |
| 110 | + setSidebarOpen(!sidebarOpen) |
| 111 | + }}><LucideMenu/></button> |
| 112 | + <div className="innerwrapper"> |
| 113 | + <Outlet/> |
| 114 | + </div> |
| 115 | + </div> |
110 | 116 | }
|
111 | 117 |
|
112 | 118 | export default App
|
0 commit comments