Files
notesnook/apps/mobile/share/store.js
2022-04-13 03:00:04 +05:00

41 lines
1.2 KiB
JavaScript

import { Appearance } from 'react-native';
import create from 'zustand';
import { ACCENT, COLOR_SCHEME_DARK, COLOR_SCHEME_LIGHT } from '../src/utils/color-scheme';
import { MMKV } from '../src/utils/database/mmkv';
export const useShareStore = create((set, get) => ({
colors: Appearance.getColorScheme() === 'dark' ? COLOR_SCHEME_DARK : COLOR_SCHEME_LIGHT,
accent: ACCENT,
setAccent: async () => {
let appSettings = MMKV.getString('appSettings');
if (appSettings) {
appSettings = JSON.parse(appSettings);
let accentColor = appSettings.theme?.accent || ACCENT.color;
let accent = {
color: accentColor,
shade: accentColor + '12'
};
set({ accent: accent });
}
},
setColors: () => {
set({
colors: Appearance.getColorScheme() === 'dark' ? COLOR_SCHEME_DARK : COLOR_SCHEME_LIGHT
});
},
appendNote: null,
setAppendNote: note => {
MMKV.setItem('shareMenuAppendNote', JSON.stringify(note));
set({ appendNote: note });
},
restoreAppendNote: async () => {
let note = MMKV.getString('shareMenuAppendNote');
if (note) {
note = JSON.parse(note);
set({ appendNote: note });
}
}
}));