mirror of
https://github.com/austinried/subtracks.git
synced 2025-12-27 09:09:29 +01:00
29 lines
788 B
TypeScript
29 lines
788 B
TypeScript
import { atom, DefaultValue, selector } from 'recoil';
|
|
import { AppSettings, Server } from '../models/settings';
|
|
import { getAppSettings, setAppSettings } from '../storage/settings';
|
|
|
|
export const appSettingsState = atom<AppSettings>({
|
|
key: 'appSettingsState',
|
|
default: selector({
|
|
key: 'appSettingsState/default',
|
|
get: () => getAppSettings(),
|
|
}),
|
|
effects_UNSTABLE: [
|
|
({ onSet }) => {
|
|
onSet((newValue) => {
|
|
if (!(newValue instanceof DefaultValue)) {
|
|
setAppSettings(newValue);
|
|
}
|
|
});
|
|
}
|
|
],
|
|
});
|
|
|
|
export const activeServer = selector<Server | undefined>({
|
|
key: 'activeServer',
|
|
get: ({get}) => {
|
|
const appSettings = get(appSettingsState);
|
|
return appSettings.servers.find(x => x.id == appSettings.activeServer);
|
|
}
|
|
});
|