import './settings.css'; import { useRef, useState } from 'preact/hooks'; import { useSnapshot } from 'valtio'; import Avatar from '../components/avatar'; import Icon from '../components/icon'; import NameText from '../components/name-text'; import RelativeTime from '../components/relative-time'; import states from '../utils/states'; import store from '../utils/store'; /* Settings component that shows these settings: - Accounts list for switching - Dark/light/auto theme switch (done with adding/removing 'is-light' or 'is-dark' class on the body) */ function Settings({ onClose }) { const snapStates = useSnapshot(states); // Accounts const accounts = store.local.getJSON('accounts'); const currentAccount = store.session.get('currentAccount'); const currentTheme = store.local.get('theme') || 'auto'; const themeFormRef = useRef(); const moreThanOneAccount = accounts.length > 1; const [currentDefault, setCurrentDefault] = useState(0); return (
{/* */}

Accounts

{moreThanOneAccount && (

Note: Default account will always be used for first load. Switched accounts will persist during the session.

)}

Add new account

Theme

{ console.log(e); e.preventDefault(); const formData = new FormData(themeFormRef.current); const theme = formData.get('theme'); const html = document.documentElement; if (theme === 'auto') { html.classList.remove('is-light', 'is-dark'); } else { html.classList.toggle('is-light', theme === 'light'); html.classList.toggle('is-dark', theme === 'dark'); } document .querySelector('meta[name="color-scheme"]') .setAttribute('content', theme); if (theme === 'auto') { store.local.del('theme'); } else { store.local.set('theme', theme); } }} >

Settings

Hidden features

About

Built {' '} by{' '} { e.preventDefault(); states.showAccount = 'cheeaun@mastodon.social'; }} > @cheeaun .

{__BUILD_TIME__ && (

Last build: {' '} {__COMMIT_HASH__ && ( <> ( {__COMMIT_HASH__} ) )}

)}
); } export default Settings;