mirror of https://github.com/usememos/memos
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.3 KiB
TypeScript
51 lines
1.3 KiB
TypeScript
import { storage } from "../helpers/storage";
|
|
import appStore from "../stores/appStore";
|
|
import { AppSetting } from "../stores/globalStateStore";
|
|
|
|
class GlobalStateService {
|
|
constructor() {
|
|
const cachedSetting = storage.get(["shouldSplitMemoWord", "shouldHideImageUrl", "shouldUseMarkdownParser"]);
|
|
const defaultAppSetting = {
|
|
shouldSplitMemoWord: cachedSetting.shouldSplitMemoWord ?? true,
|
|
shouldHideImageUrl: cachedSetting.shouldHideImageUrl ?? true,
|
|
shouldUseMarkdownParser: cachedSetting.shouldUseMarkdownParser ?? true,
|
|
};
|
|
|
|
this.setAppSetting(defaultAppSetting);
|
|
}
|
|
|
|
public getState = () => {
|
|
return appStore.getState().globalState;
|
|
};
|
|
|
|
public setEditMemoId = (editMemoId: MemoId) => {
|
|
appStore.dispatch({
|
|
type: "SET_EDIT_MEMO_ID",
|
|
payload: {
|
|
editMemoId,
|
|
},
|
|
});
|
|
};
|
|
|
|
public setMarkMemoId = (markMemoId: MemoId) => {
|
|
appStore.dispatch({
|
|
type: "SET_MARK_MEMO_ID",
|
|
payload: {
|
|
markMemoId,
|
|
},
|
|
});
|
|
};
|
|
|
|
public setAppSetting = (appSetting: Partial<AppSetting>) => {
|
|
appStore.dispatch({
|
|
type: "SET_APP_SETTING",
|
|
payload: appSetting,
|
|
});
|
|
storage.set(appSetting);
|
|
};
|
|
}
|
|
|
|
const globalStateService = new GlobalStateService();
|
|
|
|
export default globalStateService;
|