mirror of
https://github.com/tachiyomiorg/tachiyomi-extensions-inspector.git
synced 2025-01-11 16:29:08 +01:00
darkTheme in localStorage
This commit is contained in:
parent
af1c34fba5
commit
de30d55bcf
@ -11,4 +11,5 @@ object Config {
|
|||||||
val extensionsRoot = "$dataRoot/extensions"
|
val extensionsRoot = "$dataRoot/extensions"
|
||||||
val thumbnailsRoot = "$dataRoot/thumbnails"
|
val thumbnailsRoot = "$dataRoot/thumbnails"
|
||||||
val mangaRoot = "$dataRoot/manga"
|
val mangaRoot = "$dataRoot/manga"
|
||||||
|
val serverPort = 4567
|
||||||
}
|
}
|
||||||
|
@ -22,10 +22,11 @@ import DarkTheme from './context/DarkTheme';
|
|||||||
import Library from './screens/Library';
|
import Library from './screens/Library';
|
||||||
import Settings from './screens/Settings';
|
import Settings from './screens/Settings';
|
||||||
import Categories from './screens/settings/Categories';
|
import Categories from './screens/settings/Categories';
|
||||||
|
import useLocalStorage from './util/useLocalStorage';
|
||||||
|
|
||||||
export default function App() {
|
export default function App() {
|
||||||
const [title, setTitle] = useState<string>('Tachidesk');
|
const [title, setTitle] = useState<string>('Tachidesk');
|
||||||
const [darkTheme, setDarkTheme] = useState<boolean>(true);
|
const [darkTheme, setDarkTheme] = useLocalStorage<boolean>('darkTheme', true);
|
||||||
const navTitleContext = { title, setTitle };
|
const navTitleContext = { title, setTitle };
|
||||||
const darkThemeContext = { darkTheme, setDarkTheme };
|
const darkThemeContext = { darkTheme, setDarkTheme };
|
||||||
|
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import ReactDOM from 'react-dom';
|
import ReactDOM from 'react-dom';
|
||||||
import App from './App';
|
import App from './App';
|
||||||
import reportWebVitals from './reportWebVitals';
|
|
||||||
import './index.css';
|
import './index.css';
|
||||||
// roboto font
|
// roboto font
|
||||||
import 'fontsource-roboto';
|
import 'fontsource-roboto';
|
||||||
@ -16,8 +15,3 @@ ReactDOM.render(
|
|||||||
</React.StrictMode>,
|
</React.StrictMode>,
|
||||||
document.getElementById('root'),
|
document.getElementById('root'),
|
||||||
);
|
);
|
||||||
|
|
||||||
// If you want to start measuring performance in your app, pass a function
|
|
||||||
// to log results (for example: reportWebVitals(console.log))
|
|
||||||
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
|
|
||||||
reportWebVitals();
|
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
||||||
|
|
||||||
import { ReportHandler } from 'web-vitals';
|
|
||||||
|
|
||||||
const reportWebVitals = (onPerfEntry?: ReportHandler) => {
|
|
||||||
if (onPerfEntry) {
|
|
||||||
import('web-vitals').then(({
|
|
||||||
getCLS, getFID, getFCP, getLCP, getTTFB,
|
|
||||||
}) => {
|
|
||||||
getCLS(onPerfEntry);
|
|
||||||
getFID(onPerfEntry);
|
|
||||||
getFCP(onPerfEntry);
|
|
||||||
getLCP(onPerfEntry);
|
|
||||||
getTTFB(onPerfEntry);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export default reportWebVitals;
|
|
42
webUI/react/src/util/useLocalStorage.tsx
Normal file
42
webUI/react/src/util/useLocalStorage.tsx
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
import { useState, Dispatch, SetStateAction } from 'react';
|
||||||
|
|
||||||
|
// eslint-disable-next-line max-len
|
||||||
|
export default function useLocalStorage<T>(key: string, initialValue: T) : [T, Dispatch<SetStateAction<T>>] {
|
||||||
|
// State to store our value
|
||||||
|
// Pass initial state function to useState so logic is only executed once
|
||||||
|
const [storedValue, setStoredValue] = useState<T>(() => {
|
||||||
|
try {
|
||||||
|
// Get from local storage by key
|
||||||
|
const item = window.localStorage.getItem(key);
|
||||||
|
|
||||||
|
// Parse stored json or if null return set and return initialValue
|
||||||
|
if (item !== null) { return JSON.parse(item); }
|
||||||
|
|
||||||
|
window.localStorage.setItem(key, JSON.stringify(initialValue));
|
||||||
|
} finally {
|
||||||
|
// eslint-disable-next-line no-unsafe-finally
|
||||||
|
return initialValue;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Return a wrapped version of useState's setter function that ...
|
||||||
|
// ... persists the new value to localStorage.
|
||||||
|
const setValue = (value: T | ((prevState: T) => T)) => {
|
||||||
|
try {
|
||||||
|
// Allow value to be a function so we have same API as useState
|
||||||
|
const valueToStore = value instanceof Function ? value(storedValue) : value;
|
||||||
|
// Save state
|
||||||
|
setStoredValue(valueToStore);
|
||||||
|
// Save to local storage
|
||||||
|
window.localStorage.setItem(key, JSON.stringify(valueToStore));
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-empty
|
||||||
|
} catch (error) { }
|
||||||
|
};
|
||||||
|
|
||||||
|
return [storedValue, setValue];
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user