mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
chore: update redux store and service
This commit is contained in:
@ -55,7 +55,9 @@ const ChangePasswordDialog: React.FC<Props> = ({ destroy }: Props) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await userService.updatePassword(newPassword);
|
await userService.patchUser({
|
||||||
|
password: newPassword,
|
||||||
|
});
|
||||||
toastHelper.info("Password changed.");
|
toastHelper.info("Password changed.");
|
||||||
handleCloseBtnClick();
|
handleCloseBtnClick();
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
|
@ -25,7 +25,9 @@ const ConfirmResetOpenIdDialog: React.FC<Props> = ({ destroy }: Props) => {
|
|||||||
|
|
||||||
resetBtnClickLoadingState.setLoading();
|
resetBtnClickLoadingState.setLoading();
|
||||||
try {
|
try {
|
||||||
await userService.resetOpenId();
|
await userService.patchUser({
|
||||||
|
resetOpenId: true,
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
toastHelper.error("Request reset open API failed.");
|
toastHelper.error("Request reset open API failed.");
|
||||||
return;
|
return;
|
||||||
|
@ -48,9 +48,16 @@ const CreateShortcutDialog: React.FC<Props> = (props: Props) => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (shortcutId) {
|
if (shortcutId) {
|
||||||
await shortcutService.updateShortcut(shortcutId, title, JSON.stringify(filters));
|
await shortcutService.patchShortcut({
|
||||||
|
id: shortcutId,
|
||||||
|
title,
|
||||||
|
payload: JSON.stringify(filters),
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
await shortcutService.createShortcut(title, JSON.stringify(filters));
|
await shortcutService.createShortcut({
|
||||||
|
title,
|
||||||
|
payload: JSON.stringify(filters),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
toastHelper.error(error.message);
|
toastHelper.error(error.message);
|
||||||
|
@ -38,7 +38,10 @@ const DeletedMemo: React.FC<Props> = (props: Props) => {
|
|||||||
|
|
||||||
const handleRestoreMemoClick = async () => {
|
const handleRestoreMemoClick = async () => {
|
||||||
try {
|
try {
|
||||||
await memoService.restoreMemoById(memo.id);
|
await memoService.patchMemo({
|
||||||
|
id: memo.id,
|
||||||
|
rowStatus: "NORMAL",
|
||||||
|
});
|
||||||
handleDeletedMemoAction(memo.id);
|
handleDeletedMemoAction(memo.id);
|
||||||
toastHelper.info("Restored successfully");
|
toastHelper.info("Restored successfully");
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
|
@ -33,16 +33,8 @@ const Memo: React.FC<Props> = (props: Props) => {
|
|||||||
try {
|
try {
|
||||||
if (memo.pinned) {
|
if (memo.pinned) {
|
||||||
await memoService.unpinMemo(memo.id);
|
await memoService.unpinMemo(memo.id);
|
||||||
memoService.editMemo({
|
|
||||||
...memo,
|
|
||||||
pinned: false,
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
await memoService.pinMemo(memo.id);
|
await memoService.pinMemo(memo.id);
|
||||||
memoService.editMemo({
|
|
||||||
...memo,
|
|
||||||
pinned: true,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// do nth
|
// do nth
|
||||||
@ -50,23 +42,26 @@ const Memo: React.FC<Props> = (props: Props) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleMarkMemoClick = () => {
|
const handleMarkMemoClick = () => {
|
||||||
editorStateService.setMarkMemo(memo.id);
|
editorStateService.setMarkMemoWithId(memo.id);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleEditMemoClick = () => {
|
const handleEditMemoClick = () => {
|
||||||
editorStateService.setEditMemo(memo.id);
|
editorStateService.setEditMemoWithId(memo.id);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDeleteMemoClick = async () => {
|
const handleDeleteMemoClick = async () => {
|
||||||
if (showConfirmDeleteBtn) {
|
if (showConfirmDeleteBtn) {
|
||||||
try {
|
try {
|
||||||
await memoService.archiveMemoById(memo.id);
|
await memoService.patchMemo({
|
||||||
|
id: memo.id,
|
||||||
|
rowStatus: "ARCHIVED",
|
||||||
|
});
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
toastHelper.error(error.message);
|
toastHelper.error(error.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (editorStateService.getState().editMemoId === memo.id) {
|
if (editorStateService.getState().editMemoId === memo.id) {
|
||||||
editorStateService.setEditMemo(UNKNOWN_ID);
|
editorStateService.clearEditMemo();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
toggleConfirmDeleteBtn();
|
toggleConfirmDeleteBtn();
|
||||||
|
@ -96,7 +96,7 @@ const MemoCardDialog: React.FC<Props> = (props: Props) => {
|
|||||||
|
|
||||||
const handleEditMemoBtnClick = useCallback(() => {
|
const handleEditMemoBtnClick = useCallback(() => {
|
||||||
props.destroy();
|
props.destroy();
|
||||||
editorStateService.setEditMemo(memo.id);
|
editorStateService.setEditMemoWithId(memo.id);
|
||||||
}, [memo.id]);
|
}, [memo.id]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -57,7 +57,7 @@ const MemoEditor: React.FC<Props> = () => {
|
|||||||
const editorCurrentValue = editorRef.current?.getContent();
|
const editorCurrentValue = editorRef.current?.getContent();
|
||||||
const memoLinkText = `${editorCurrentValue ? "\n" : ""}Mark: [@MEMO](${editorState.markMemoId})`;
|
const memoLinkText = `${editorCurrentValue ? "\n" : ""}Mark: [@MEMO](${editorState.markMemoId})`;
|
||||||
editorRef.current?.insertText(memoLinkText);
|
editorRef.current?.insertText(memoLinkText);
|
||||||
editorStateService.setMarkMemo(UNKNOWN_ID);
|
editorStateService.clearMarkMemo();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@ -155,14 +155,16 @@ const MemoEditor: React.FC<Props> = () => {
|
|||||||
const prevMemo = memoService.getMemoById(editMemoId ?? UNKNOWN_ID);
|
const prevMemo = memoService.getMemoById(editMemoId ?? UNKNOWN_ID);
|
||||||
|
|
||||||
if (prevMemo && prevMemo.content !== content) {
|
if (prevMemo && prevMemo.content !== content) {
|
||||||
const editedMemo = await memoService.updateMemo(prevMemo.id, content);
|
await memoService.patchMemo({
|
||||||
editedMemo.createdTs = Date.now();
|
id: prevMemo.id,
|
||||||
memoService.editMemo(editedMemo);
|
content,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
editorStateService.setEditMemo(UNKNOWN_ID);
|
editorStateService.clearEditMemo();
|
||||||
} else {
|
} else {
|
||||||
const newMemo = await memoService.createMemo(content);
|
await memoService.createMemo({
|
||||||
memoService.pushMemo(newMemo);
|
content,
|
||||||
|
});
|
||||||
locationService.clearQuery();
|
locationService.clearQuery();
|
||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
@ -173,7 +175,7 @@ const MemoEditor: React.FC<Props> = () => {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleCancelBtnClick = useCallback(() => {
|
const handleCancelBtnClick = useCallback(() => {
|
||||||
editorStateService.setEditMemo(UNKNOWN_ID);
|
editorStateService.clearEditMemo();
|
||||||
editorRef.current?.setContent("");
|
editorRef.current?.setContent("");
|
||||||
setEditorContentCache("");
|
setEditorContentCache("");
|
||||||
}, []);
|
}, []);
|
||||||
|
@ -28,7 +28,7 @@ const MemoFilter: React.FC<FilterProps> = () => {
|
|||||||
<div
|
<div
|
||||||
className={"filter-item-container " + (tagQuery ? "" : "hidden")}
|
className={"filter-item-container " + (tagQuery ? "" : "hidden")}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
locationService.setTagQuery("");
|
locationService.setTagQuery(undefined);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<span className="icon-text">🏷️</span> {tagQuery}
|
<span className="icon-text">🏷️</span> {tagQuery}
|
||||||
@ -45,7 +45,7 @@ const MemoFilter: React.FC<FilterProps> = () => {
|
|||||||
<div
|
<div
|
||||||
className="filter-item-container"
|
className="filter-item-container"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
locationService.setFromAndToQuery(0, 0);
|
locationService.setFromAndToQuery();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<span className="icon-text">🗓️</span> {utils.getDateString(duration.from)} to {utils.getDateString(duration.to)}
|
<span className="icon-text">🗓️</span> {utils.getDateString(duration.from)} to {utils.getDateString(duration.to)}
|
||||||
|
@ -18,9 +18,7 @@ const MemoTrashDialog: React.FC<Props> = (props: Props) => {
|
|||||||
memoService
|
memoService
|
||||||
.fetchDeletedMemos()
|
.fetchDeletedMemos()
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
if (result !== false) {
|
|
||||||
setDeletedMemos(result);
|
setDeletedMemos(result);
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
toastHelper.error("Failed to fetch deleted memos: ", error);
|
toastHelper.error("Failed to fetch deleted memos: ", error);
|
||||||
|
@ -32,7 +32,9 @@ const MenuBtnsPopup: React.FC<Props> = (props: Props) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleSignOutBtnClick = async () => {
|
const handleSignOutBtnClick = async () => {
|
||||||
await userService.doSignOut();
|
userService.doSignOut().catch(() => {
|
||||||
|
// do nth
|
||||||
|
});
|
||||||
locationService.replaceHistory("/signin");
|
locationService.replaceHistory("/signin");
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
};
|
};
|
||||||
|
@ -39,8 +39,9 @@ const MyAccountSection: React.FC<Props> = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await userService.updateUsername(username);
|
await userService.patchUser({
|
||||||
await userService.doSignIn();
|
name: username,
|
||||||
|
});
|
||||||
toastHelper.info("Username changed");
|
toastHelper.info("Username changed");
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
toastHelper.error(error.message);
|
toastHelper.error(error.message);
|
||||||
|
@ -45,7 +45,11 @@ const PreferencesSection: React.FC<Props> = () => {
|
|||||||
const createdTs = (memo as any).createdAt || memo.createdTs || Date.now();
|
const createdTs = (memo as any).createdAt || memo.createdTs || Date.now();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await memoService.importMemo(content, createdTs);
|
const memoCreate = {
|
||||||
|
content,
|
||||||
|
createdTs: Math.floor(utils.getTimeStampByDate(createdTs) / 1000),
|
||||||
|
};
|
||||||
|
await memoService.createMemo(memoCreate);
|
||||||
succeedAmount++;
|
succeedAmount++;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// do nth
|
// do nth
|
||||||
|
@ -96,19 +96,11 @@ const ShortcutContainer: React.FC<ShortcutContainerProps> = (props: ShortcutCont
|
|||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (shortcut.rowStatus === "ARCHIVED") {
|
const shortcutPatch: ShortcutPatch = {
|
||||||
await shortcutService.unpinShortcut(shortcut.id);
|
id: shortcut.id,
|
||||||
shortcutService.editShortcut({
|
rowStatus: shortcut.rowStatus === "ARCHIVED" ? "NORMAL" : "ARCHIVED",
|
||||||
...shortcut,
|
};
|
||||||
rowStatus: "NORMAL",
|
await shortcutService.patchShortcut(shortcutPatch);
|
||||||
});
|
|
||||||
} else {
|
|
||||||
await shortcutService.pinShortcut(shortcut.id);
|
|
||||||
shortcutService.editShortcut({
|
|
||||||
...shortcut,
|
|
||||||
rowStatus: "ARCHIVED",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// do nth
|
// do nth
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ const UsageHeatMap: React.FC<Props> = () => {
|
|||||||
|
|
||||||
const handleUsageStatItemClick = useCallback((item: DailyUsageStat) => {
|
const handleUsageStatItemClick = useCallback((item: DailyUsageStat) => {
|
||||||
if (locationService.getState().query?.duration?.from === item.timestamp) {
|
if (locationService.getState().query?.duration?.from === item.timestamp) {
|
||||||
locationService.setFromAndToQuery(0, 0);
|
locationService.setFromAndToQuery();
|
||||||
setCurrentStat(null);
|
setCurrentStat(null);
|
||||||
} else if (item.count > 0) {
|
} else if (item.count > 0) {
|
||||||
if (!["/"].includes(locationService.getState().pathname)) {
|
if (!["/"].includes(locationService.getState().pathname)) {
|
||||||
|
@ -159,26 +159,6 @@ namespace api {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function archiveMemo(memoId: MemoId) {
|
|
||||||
return request({
|
|
||||||
method: "PATCH",
|
|
||||||
url: `/api/memo/${memoId}`,
|
|
||||||
data: {
|
|
||||||
rowStatus: "ARCHIVED",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function restoreMemo(memoId: MemoId) {
|
|
||||||
return request({
|
|
||||||
method: "PATCH",
|
|
||||||
url: `/api/memo/${memoId}`,
|
|
||||||
data: {
|
|
||||||
rowStatus: "NORMAL",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function deleteMemo(memoId: MemoId) {
|
export function deleteMemo(memoId: MemoId) {
|
||||||
return request({
|
return request({
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
@ -193,25 +173,19 @@ namespace api {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createShortcut(title: string, payload: string) {
|
export function createShortcut(shortcutCreate: ShortcutCreate) {
|
||||||
return request<Shortcut>({
|
return request<Shortcut>({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
url: "/api/shortcut",
|
url: "/api/shortcut",
|
||||||
data: {
|
data: shortcutCreate,
|
||||||
title,
|
|
||||||
payload,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateShortcut(shortcutId: ShortcutId, title: string, payload: string) {
|
export function patchShortcut(shortcutPatch: ShortcutPatch) {
|
||||||
return request<Shortcut>({
|
return request<Shortcut>({
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
url: `/api/shortcut/${shortcutId}`,
|
url: `/api/shortcut/${shortcutPatch.id}`,
|
||||||
data: {
|
data: shortcutPatch,
|
||||||
title,
|
|
||||||
payload,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,26 +196,6 @@ namespace api {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function pinShortcut(shortcutId: ShortcutId) {
|
|
||||||
return request({
|
|
||||||
method: "PATCH",
|
|
||||||
url: `/api/shortcut/${shortcutId}`,
|
|
||||||
data: {
|
|
||||||
rowStatus: "ARCHIVED",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function unpinShortcut(shortcutId: ShortcutId) {
|
|
||||||
return request({
|
|
||||||
method: "PATCH",
|
|
||||||
url: `/api/shortcut/${shortcutId}`,
|
|
||||||
data: {
|
|
||||||
rowStatus: "NORMAL",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function uploadFile(formData: FormData) {
|
export function uploadFile(formData: FormData) {
|
||||||
return request<Resource>({
|
return request<Resource>({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
> .search-bar-inputer {
|
> .search-bar-inputer {
|
||||||
.flex(row, flex-start, center);
|
.flex(row, flex-start, center);
|
||||||
@apply w-full py-2 px-4 rounded-lg flex flex-row justify-start items-center bg-gray-200;
|
@apply w-full py-2 px-4 rounded-lg flex flex-row justify-start items-center bg-zinc-200;
|
||||||
|
|
||||||
> .icon-img {
|
> .icon-img {
|
||||||
@apply mr-2 w-4 h-auto opacity-80;
|
@apply mr-2 w-4 h-auto opacity-80;
|
||||||
|
@ -6,13 +6,21 @@ const editorStateService = {
|
|||||||
return store.getState().editor;
|
return store.getState().editor;
|
||||||
},
|
},
|
||||||
|
|
||||||
setEditMemo: (editMemoId: MemoId) => {
|
setEditMemoWithId: (editMemoId: MemoId) => {
|
||||||
store.dispatch(setEditMemoId(editMemoId));
|
store.dispatch(setEditMemoId(editMemoId));
|
||||||
},
|
},
|
||||||
|
|
||||||
setMarkMemo: (markMemoId: MemoId) => {
|
clearEditMemo: () => {
|
||||||
|
store.dispatch(setEditMemoId());
|
||||||
|
},
|
||||||
|
|
||||||
|
setMarkMemoWithId: (markMemoId: MemoId) => {
|
||||||
store.dispatch(setMarkMemoId(markMemoId));
|
store.dispatch(setMarkMemoId(markMemoId));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
clearMarkMemo: () => {
|
||||||
|
store.dispatch(setMarkMemoId());
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default editorStateService;
|
export default editorStateService;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import utils from "../helpers/utils";
|
import utils from "../helpers/utils";
|
||||||
import store from "../store";
|
import store from "../store";
|
||||||
import { setQuery, setPathname } from "../store/modules/location";
|
import { setQuery, setPathname, Query } from "../store/modules/location";
|
||||||
|
|
||||||
const updateLocationUrl = (method: "replace" | "push" = "replace") => {
|
const updateLocationUrl = (method: "replace" | "push" = "replace") => {
|
||||||
const { query, pathname, hash } = store.getState().location;
|
const { query, pathname, hash } = store.getState().location;
|
||||||
@ -23,36 +23,34 @@ const locationService = {
|
|||||||
return store.getState().location;
|
return store.getState().location;
|
||||||
},
|
},
|
||||||
|
|
||||||
clearQuery: () => {
|
setPathname: (pathname: string) => {
|
||||||
store.dispatch(setQuery({}));
|
store.dispatch(setPathname(pathname));
|
||||||
updateLocationUrl();
|
updateLocationUrl();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
pushHistory: (pathname: string) => {
|
||||||
|
store.dispatch(setPathname(pathname));
|
||||||
|
updateLocationUrl("push");
|
||||||
|
},
|
||||||
|
|
||||||
|
replaceHistory: (pathname: string) => {
|
||||||
|
store.dispatch(setPathname(pathname));
|
||||||
|
updateLocationUrl("replace");
|
||||||
|
},
|
||||||
|
|
||||||
setQuery: (query: Query) => {
|
setQuery: (query: Query) => {
|
||||||
store.dispatch(setQuery(query));
|
store.dispatch(setQuery(query));
|
||||||
updateLocationUrl();
|
updateLocationUrl();
|
||||||
},
|
},
|
||||||
|
|
||||||
setPathname: (pathname: AppRouter) => {
|
clearQuery: () => {
|
||||||
store.dispatch(setPathname(pathname));
|
store.dispatch(setQuery({}));
|
||||||
updateLocationUrl();
|
updateLocationUrl();
|
||||||
},
|
},
|
||||||
|
|
||||||
pushHistory: (pathname: AppRouter) => {
|
|
||||||
store.dispatch(setPathname(pathname));
|
|
||||||
updateLocationUrl("push");
|
|
||||||
},
|
|
||||||
|
|
||||||
replaceHistory: (pathname: AppRouter) => {
|
|
||||||
store.dispatch(setPathname(pathname));
|
|
||||||
updateLocationUrl("replace");
|
|
||||||
},
|
|
||||||
|
|
||||||
setMemoTypeQuery: (type?: MemoSpecType) => {
|
setMemoTypeQuery: (type?: MemoSpecType) => {
|
||||||
const { query } = store.getState().location;
|
|
||||||
store.dispatch(
|
store.dispatch(
|
||||||
setQuery({
|
setQuery({
|
||||||
...query,
|
|
||||||
type: type,
|
type: type,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@ -60,10 +58,8 @@ const locationService = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
setMemoShortcut: (shortcutId?: ShortcutId) => {
|
setMemoShortcut: (shortcutId?: ShortcutId) => {
|
||||||
const { query } = store.getState().location;
|
|
||||||
store.dispatch(
|
store.dispatch(
|
||||||
setQuery({
|
setQuery({
|
||||||
...query,
|
|
||||||
shortcutId: shortcutId,
|
shortcutId: shortcutId,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@ -71,10 +67,8 @@ const locationService = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
setTextQuery: (text?: string) => {
|
setTextQuery: (text?: string) => {
|
||||||
const { query } = store.getState().location;
|
|
||||||
store.dispatch(
|
store.dispatch(
|
||||||
setQuery({
|
setQuery({
|
||||||
...query,
|
|
||||||
text: text,
|
text: text,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@ -82,34 +76,30 @@ const locationService = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
setTagQuery: (tag?: string) => {
|
setTagQuery: (tag?: string) => {
|
||||||
const { query } = store.getState().location;
|
|
||||||
store.dispatch(
|
store.dispatch(
|
||||||
setQuery({
|
setQuery({
|
||||||
...query,
|
|
||||||
tag: tag,
|
tag: tag,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
updateLocationUrl();
|
updateLocationUrl();
|
||||||
},
|
},
|
||||||
|
|
||||||
setFromAndToQuery: (from: number, to: number) => {
|
setFromAndToQuery: (from?: number, to?: number) => {
|
||||||
const { query } = store.getState().location;
|
let duration = undefined;
|
||||||
|
if (from && to && from < to) {
|
||||||
|
duration = {
|
||||||
|
from,
|
||||||
|
to,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
store.dispatch(
|
store.dispatch(
|
||||||
setQuery({
|
setQuery({
|
||||||
...query,
|
duration,
|
||||||
duration: { from, to },
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
updateLocationUrl();
|
updateLocationUrl();
|
||||||
},
|
},
|
||||||
|
|
||||||
getValidPathname: (pathname: string): AppRouter => {
|
|
||||||
if (["/", "/signin"].includes(pathname)) {
|
|
||||||
return pathname as AppRouter;
|
|
||||||
} else {
|
|
||||||
return "/";
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default locationService;
|
export default locationService;
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
import api from "../helpers/api";
|
import api from "../helpers/api";
|
||||||
import { TAG_REG } from "../helpers/consts";
|
import { TAG_REG } from "../helpers/consts";
|
||||||
import utils from "../helpers/utils";
|
import { createMemo, patchMemo, setMemos, setTags } from "../store/modules/memo";
|
||||||
import { patchMemo, setMemos, setTags } from "../store/modules/memo";
|
|
||||||
import store from "../store";
|
import store from "../store";
|
||||||
import userService from "./userService";
|
|
||||||
|
|
||||||
const convertResponseModelMemo = (memo: Memo): Memo => {
|
const convertResponseModelMemo = (memo: Memo): Memo => {
|
||||||
return {
|
return {
|
||||||
@ -19,36 +17,24 @@ const memoService = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
fetchAllMemos: async () => {
|
fetchAllMemos: async () => {
|
||||||
if (!userService.getState().user) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = await api.getMyMemos();
|
const data = await api.getMyMemos();
|
||||||
const memos: Memo[] = data.filter((m) => m.rowStatus !== "ARCHIVED").map((m) => convertResponseModelMemo(m));
|
const memos = data.filter((m) => m.rowStatus !== "ARCHIVED").map((m) => convertResponseModelMemo(m));
|
||||||
store.dispatch(setMemos(memos));
|
store.dispatch(setMemos(memos));
|
||||||
|
|
||||||
return memos;
|
return memos;
|
||||||
},
|
},
|
||||||
|
|
||||||
fetchDeletedMemos: async () => {
|
fetchDeletedMemos: async () => {
|
||||||
if (!userService.getState().user) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = await api.getMyArchivedMemos();
|
const data = await api.getMyArchivedMemos();
|
||||||
const deletedMemos: Memo[] = data.map((m) => {
|
const deletedMemos = data.map((m) => {
|
||||||
return convertResponseModelMemo(m);
|
return convertResponseModelMemo(m);
|
||||||
});
|
});
|
||||||
return deletedMemos;
|
return deletedMemos;
|
||||||
},
|
},
|
||||||
|
|
||||||
pushMemo: (memo: Memo) => {
|
getMemoById: (memoId: MemoId) => {
|
||||||
store.dispatch(setMemos(memoService.getState().memos.concat(memo)));
|
|
||||||
},
|
|
||||||
|
|
||||||
getMemoById: (id: MemoId) => {
|
|
||||||
for (const m of memoService.getState().memos) {
|
for (const m of memoService.getState().memos) {
|
||||||
if (m.id === id) {
|
if (m.id === memoId) {
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -56,35 +42,6 @@ const memoService = {
|
|||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
|
|
||||||
archiveMemoById: async (id: MemoId) => {
|
|
||||||
const memo = memoService.getMemoById(id);
|
|
||||||
if (!memo) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await api.archiveMemo(id);
|
|
||||||
store.dispatch(
|
|
||||||
patchMemo({
|
|
||||||
...memo,
|
|
||||||
rowStatus: "ARCHIVED",
|
|
||||||
})
|
|
||||||
);
|
|
||||||
},
|
|
||||||
|
|
||||||
restoreMemoById: async (id: MemoId) => {
|
|
||||||
await api.restoreMemo(id);
|
|
||||||
memoService.clearMemos();
|
|
||||||
memoService.fetchAllMemos();
|
|
||||||
},
|
|
||||||
|
|
||||||
deleteMemoById: async (id: MemoId) => {
|
|
||||||
await api.deleteMemo(id);
|
|
||||||
},
|
|
||||||
|
|
||||||
editMemo: (memo: Memo) => {
|
|
||||||
store.dispatch(patchMemo(memo));
|
|
||||||
},
|
|
||||||
|
|
||||||
updateTagsState: () => {
|
updateTagsState: () => {
|
||||||
const { memos } = memoService.getState();
|
const { memos } = memoService.getState();
|
||||||
const tagsSet = new Set<string>();
|
const tagsSet = new Set<string>();
|
||||||
@ -97,43 +54,46 @@ const memoService = {
|
|||||||
store.dispatch(setTags(Array.from(tagsSet).filter((t) => Boolean(t))));
|
store.dispatch(setTags(Array.from(tagsSet).filter((t) => Boolean(t))));
|
||||||
},
|
},
|
||||||
|
|
||||||
clearMemos: () => {
|
|
||||||
store.dispatch(setMemos([]));
|
|
||||||
},
|
|
||||||
|
|
||||||
getLinkedMemos: async (memoId: MemoId): Promise<Memo[]> => {
|
getLinkedMemos: async (memoId: MemoId): Promise<Memo[]> => {
|
||||||
const { memos } = memoService.getState();
|
const { memos } = memoService.getState();
|
||||||
return memos.filter((m) => m.content.includes(`${memoId}`));
|
return memos.filter((m) => m.content.includes(`${memoId}`));
|
||||||
},
|
},
|
||||||
|
|
||||||
createMemo: async (content: string): Promise<Memo> => {
|
createMemo: async (memoCreate: MemoCreate) => {
|
||||||
const memo = await api.createMemo({
|
const data = await api.createMemo(memoCreate);
|
||||||
content,
|
const memo = convertResponseModelMemo(data);
|
||||||
});
|
store.dispatch(createMemo(memo));
|
||||||
return convertResponseModelMemo(memo);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
updateMemo: async (memoId: MemoId, content: string): Promise<Memo> => {
|
patchMemo: async (memoPatch: MemoPatch): Promise<Memo> => {
|
||||||
const memo = await api.patchMemo({
|
const data = await api.patchMemo(memoPatch);
|
||||||
id: memoId,
|
const memo = convertResponseModelMemo(data);
|
||||||
content,
|
store.dispatch(patchMemo(memo));
|
||||||
});
|
return memo;
|
||||||
return convertResponseModelMemo(memo);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
pinMemo: async (memoId: MemoId) => {
|
pinMemo: async (memoId: MemoId) => {
|
||||||
await api.pinMemo(memoId);
|
await api.pinMemo(memoId);
|
||||||
|
store.dispatch(
|
||||||
|
patchMemo({
|
||||||
|
id: memoId,
|
||||||
|
pinned: true,
|
||||||
|
})
|
||||||
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
unpinMemo: async (memoId: MemoId) => {
|
unpinMemo: async (memoId: MemoId) => {
|
||||||
await api.unpinMemo(memoId);
|
await api.unpinMemo(memoId);
|
||||||
|
store.dispatch(
|
||||||
|
patchMemo({
|
||||||
|
id: memoId,
|
||||||
|
pinned: false,
|
||||||
|
})
|
||||||
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
importMemo: async (content: string, createdTs: TimeStamp) => {
|
deleteMemoById: async (memoId: MemoId) => {
|
||||||
await api.createMemo({
|
await api.deleteMemo(memoId);
|
||||||
content,
|
|
||||||
createdTs: Math.floor(utils.getTimeStampByDate(createdTs) / 1000),
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
import userService from "./userService";
|
|
||||||
import api from "../helpers/api";
|
import api from "../helpers/api";
|
||||||
import { UNKNOWN_ID } from "../helpers/consts";
|
|
||||||
import store from "../store/";
|
import store from "../store/";
|
||||||
import { deleteShortcut, patchShortcut, setShortcuts } from "../store/modules/shortcut";
|
import { createShortcut, deleteShortcut, patchShortcut, setShortcuts } from "../store/modules/shortcut";
|
||||||
|
|
||||||
const convertResponseModelShortcut = (shortcut: Shortcut): Shortcut => {
|
const convertResponseModelShortcut = (shortcut: Shortcut): Shortcut => {
|
||||||
return {
|
return {
|
||||||
@ -18,21 +16,12 @@ const shortcutService = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
getMyAllShortcuts: async () => {
|
getMyAllShortcuts: async () => {
|
||||||
if (!userService.getState().user) {
|
const rawData = await api.getMyShortcuts();
|
||||||
return false;
|
const shortcuts = rawData.map((s) => convertResponseModelShortcut(s));
|
||||||
}
|
|
||||||
|
|
||||||
const data = await api.getMyShortcuts();
|
|
||||||
const shortcuts = data.map((s) => convertResponseModelShortcut(s));
|
|
||||||
store.dispatch(setShortcuts(shortcuts));
|
store.dispatch(setShortcuts(shortcuts));
|
||||||
return shortcuts;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
getShortcutById: (id: ShortcutId) => {
|
getShortcutById: (id: ShortcutId) => {
|
||||||
if (id === UNKNOWN_ID) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const s of shortcutService.getState().shortcuts) {
|
for (const s of shortcutService.getState().shortcuts) {
|
||||||
if (s.id === id) {
|
if (s.id === id) {
|
||||||
return s;
|
return s;
|
||||||
@ -42,11 +31,15 @@ const shortcutService = {
|
|||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
|
|
||||||
pushShortcut: (shortcut: Shortcut) => {
|
createShortcut: async (shortcutCreate: ShortcutCreate) => {
|
||||||
store.dispatch(setShortcuts(shortcutService.getState().shortcuts.concat(shortcut)));
|
const data = await api.createShortcut(shortcutCreate);
|
||||||
|
const shortcut = convertResponseModelShortcut(data);
|
||||||
|
store.dispatch(createShortcut(shortcut));
|
||||||
},
|
},
|
||||||
|
|
||||||
editShortcut: (shortcut: Shortcut) => {
|
patchShortcut: async (shortcutPatch: ShortcutPatch) => {
|
||||||
|
const data = await api.patchShortcut(shortcutPatch);
|
||||||
|
const shortcut = convertResponseModelShortcut(data);
|
||||||
store.dispatch(patchShortcut(shortcut));
|
store.dispatch(patchShortcut(shortcut));
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -54,24 +47,6 @@ const shortcutService = {
|
|||||||
await api.deleteShortcutById(shortcutId);
|
await api.deleteShortcutById(shortcutId);
|
||||||
store.dispatch(deleteShortcut(shortcutId));
|
store.dispatch(deleteShortcut(shortcutId));
|
||||||
},
|
},
|
||||||
|
|
||||||
createShortcut: async (title: string, payload: string) => {
|
|
||||||
const data = await api.createShortcut(title, payload);
|
|
||||||
shortcutService.pushShortcut(convertResponseModelShortcut(data));
|
|
||||||
},
|
|
||||||
|
|
||||||
updateShortcut: async (shortcutId: ShortcutId, title: string, payload: string) => {
|
|
||||||
const data = await api.updateShortcut(shortcutId, title, payload);
|
|
||||||
store.dispatch(patchShortcut(convertResponseModelShortcut(data)));
|
|
||||||
},
|
|
||||||
|
|
||||||
pinShortcut: async (shortcutId: ShortcutId) => {
|
|
||||||
await api.pinShortcut(shortcutId);
|
|
||||||
},
|
|
||||||
|
|
||||||
unpinShortcut: async (shortcutId: ShortcutId) => {
|
|
||||||
await api.unpinShortcut(shortcutId);
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default shortcutService;
|
export default shortcutService;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import api from "../helpers/api";
|
import api from "../helpers/api";
|
||||||
import { signin, signout } from "../store/modules/user";
|
|
||||||
import store from "../store";
|
import store from "../store";
|
||||||
|
import { setUser, patchUser } from "../store/modules/user";
|
||||||
|
|
||||||
const convertResponseModelUser = (user: User): User => {
|
const convertResponseModelUser = (user: User): User => {
|
||||||
return {
|
return {
|
||||||
@ -18,7 +18,7 @@ const userService = {
|
|||||||
doSignIn: async () => {
|
doSignIn: async () => {
|
||||||
const user = await api.getUser();
|
const user = await api.getUser();
|
||||||
if (user) {
|
if (user) {
|
||||||
store.dispatch(signin(convertResponseModelUser(user)));
|
store.dispatch(setUser(convertResponseModelUser(user)));
|
||||||
} else {
|
} else {
|
||||||
userService.doSignOut();
|
userService.doSignOut();
|
||||||
}
|
}
|
||||||
@ -26,29 +26,14 @@ const userService = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
doSignOut: async () => {
|
doSignOut: async () => {
|
||||||
store.dispatch(signout);
|
store.dispatch(setUser());
|
||||||
api.signout().catch(() => {
|
await api.signout();
|
||||||
// do nth
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
updateUsername: async (name: string): Promise<void> => {
|
patchUser: async (userPatch: UserPatch): Promise<void> => {
|
||||||
await api.patchUser({
|
const data = await api.patchUser(userPatch);
|
||||||
name,
|
const user = convertResponseModelUser(data);
|
||||||
});
|
store.dispatch(patchUser(user));
|
||||||
},
|
|
||||||
|
|
||||||
updatePassword: async (password: string): Promise<void> => {
|
|
||||||
await api.patchUser({
|
|
||||||
password,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
resetOpenId: async (): Promise<string> => {
|
|
||||||
const user = await api.patchUser({
|
|
||||||
resetOpenId: true,
|
|
||||||
});
|
|
||||||
return user.openId;
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -10,10 +10,16 @@ const editorSlice = createSlice({
|
|||||||
initialState: {} as State,
|
initialState: {} as State,
|
||||||
reducers: {
|
reducers: {
|
||||||
setMarkMemoId: (state, action: PayloadAction<Option<MemoId>>) => {
|
setMarkMemoId: (state, action: PayloadAction<Option<MemoId>>) => {
|
||||||
state.markMemoId = action.payload;
|
return {
|
||||||
|
...state,
|
||||||
|
markMemoId: action.payload,
|
||||||
|
};
|
||||||
},
|
},
|
||||||
setEditMemoId: (state, action: PayloadAction<Option<MemoId>>) => {
|
setEditMemoId: (state, action: PayloadAction<Option<MemoId>>) => {
|
||||||
state.editMemoId = action.payload;
|
return {
|
||||||
|
...state,
|
||||||
|
editMemoId: action.payload,
|
||||||
|
};
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -1,14 +1,27 @@
|
|||||||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||||
|
|
||||||
interface State {
|
interface Duration {
|
||||||
pathname: AppRouter;
|
from: number;
|
||||||
hash: string;
|
to: number;
|
||||||
query?: Query;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const getValidPathname = (pathname: string): AppRouter => {
|
export interface Query {
|
||||||
|
tag?: string;
|
||||||
|
duration?: Duration;
|
||||||
|
type?: MemoSpecType;
|
||||||
|
text?: string;
|
||||||
|
shortcutId?: ShortcutId;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface State {
|
||||||
|
pathname: string;
|
||||||
|
hash: string;
|
||||||
|
query: Query;
|
||||||
|
}
|
||||||
|
|
||||||
|
const getValidPathname = (pathname: string): string => {
|
||||||
if (["/", "/signin"].includes(pathname)) {
|
if (["/", "/signin"].includes(pathname)) {
|
||||||
return pathname as AppRouter;
|
return pathname;
|
||||||
} else {
|
} else {
|
||||||
return "/";
|
return "/";
|
||||||
}
|
}
|
||||||
@ -20,6 +33,7 @@ const getStateFromLocation = () => {
|
|||||||
const state: State = {
|
const state: State = {
|
||||||
pathname: getValidPathname(pathname),
|
pathname: getValidPathname(pathname),
|
||||||
hash: hash,
|
hash: hash,
|
||||||
|
query: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
if (search !== "") {
|
if (search !== "") {
|
||||||
@ -48,11 +62,20 @@ const locationSlice = createSlice({
|
|||||||
updateStateWithLocation: () => {
|
updateStateWithLocation: () => {
|
||||||
return getStateFromLocation();
|
return getStateFromLocation();
|
||||||
},
|
},
|
||||||
setPathname: (state, action: PayloadAction<AppRouter>) => {
|
setPathname: (state, action: PayloadAction<string>) => {
|
||||||
state.pathname = action.payload;
|
return {
|
||||||
|
...state,
|
||||||
|
pathname: action.payload,
|
||||||
|
};
|
||||||
},
|
},
|
||||||
setQuery: (state, action: PayloadAction<Partial<Query>>) => {
|
setQuery: (state, action: PayloadAction<Partial<Query>>) => {
|
||||||
state.query = action.payload;
|
return {
|
||||||
|
...state,
|
||||||
|
query: {
|
||||||
|
...state.query,
|
||||||
|
...action.payload,
|
||||||
|
},
|
||||||
|
};
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -33,12 +33,9 @@ const memoSlice = createSlice({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
deleteMemo: (state, action: PayloadAction<MemoId>) => {
|
|
||||||
state.memos = [...state.memos].filter((memo) => memo.id !== action.payload);
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const { setMemos, setTags, createMemo, patchMemo, deleteMemo } = memoSlice.actions;
|
export const { setMemos, setTags, createMemo, patchMemo } = memoSlice.actions;
|
||||||
|
|
||||||
export default memoSlice.reducer;
|
export default memoSlice.reducer;
|
||||||
|
@ -8,18 +8,12 @@ const userSlice = createSlice({
|
|||||||
name: "user",
|
name: "user",
|
||||||
initialState: {} as State,
|
initialState: {} as State,
|
||||||
reducers: {
|
reducers: {
|
||||||
signin: (state, action: PayloadAction<User>) => {
|
setUser: (state, action: PayloadAction<User | undefined>) => {
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
user: action.payload,
|
user: action.payload,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
signout: (state) => {
|
|
||||||
return {
|
|
||||||
...state,
|
|
||||||
user: undefined,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
patchUser: (state, action: PayloadAction<Partial<User>>) => {
|
patchUser: (state, action: PayloadAction<Partial<User>>) => {
|
||||||
state.user = {
|
state.user = {
|
||||||
...state.user,
|
...state.user,
|
||||||
@ -29,6 +23,6 @@ const userSlice = createSlice({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const { signin, signout, patchUser } = userSlice.actions;
|
export const { setUser, patchUser } = userSlice.actions;
|
||||||
|
|
||||||
export default userSlice.reducer;
|
export default userSlice.reducer;
|
||||||
|
20
web/src/types/location.d.ts
vendored
20
web/src/types/location.d.ts
vendored
@ -1,20 +0,0 @@
|
|||||||
interface Duration {
|
|
||||||
from: number;
|
|
||||||
to: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Query {
|
|
||||||
tag?: string;
|
|
||||||
duration?: Duration;
|
|
||||||
type?: MemoSpecType;
|
|
||||||
text?: string;
|
|
||||||
shortcutId?: ShortcutId;
|
|
||||||
}
|
|
||||||
|
|
||||||
type AppRouter = "/" | "/signin";
|
|
||||||
|
|
||||||
interface AppLocation {
|
|
||||||
pathname: AppRouter;
|
|
||||||
hash: string;
|
|
||||||
query: Query;
|
|
||||||
}
|
|
||||||
|
12
web/src/types/modules/shortcut.d.ts
vendored
12
web/src/types/modules/shortcut.d.ts
vendored
@ -10,3 +10,15 @@ interface Shortcut {
|
|||||||
title: string;
|
title: string;
|
||||||
payload: string;
|
payload: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface ShortcutCreate {
|
||||||
|
title: string;
|
||||||
|
payload: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ShortcutPatch {
|
||||||
|
id: ShortcutId;
|
||||||
|
title?: string;
|
||||||
|
payload?: string;
|
||||||
|
rowStatus?: RowStatus;
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user