mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
fix: shortcutId in filter
This commit is contained in:
@ -8,7 +8,7 @@ import Selector from "./common/Selector";
|
||||
import "../less/create-shortcut-dialog.less";
|
||||
|
||||
interface Props extends DialogProps {
|
||||
shortcutId?: string;
|
||||
shortcutId?: ShortcutId;
|
||||
}
|
||||
|
||||
const CreateShortcutDialog: React.FC<Props> = (props: Props) => {
|
||||
@ -23,7 +23,8 @@ const CreateShortcutDialog: React.FC<Props> = (props: Props) => {
|
||||
}).length;
|
||||
|
||||
useEffect(() => {
|
||||
const shortcutTemp = shortcutService.getShortcutById(shortcutId ?? "");
|
||||
if (shortcutId) {
|
||||
const shortcutTemp = shortcutService.getShortcutById(shortcutId);
|
||||
if (shortcutTemp) {
|
||||
setTitle(shortcutTemp.title);
|
||||
const temp = JSON.parse(shortcutTemp.payload);
|
||||
@ -31,6 +32,7 @@ const CreateShortcutDialog: React.FC<Props> = (props: Props) => {
|
||||
setFilters(temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, [shortcutId]);
|
||||
|
||||
const handleTitleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
@ -298,7 +300,7 @@ const FilterInputer: React.FC<MemoFilterInputerProps> = (props: MemoFilterInpute
|
||||
|
||||
const MemoFilterInputer: React.FC<MemoFilterInputerProps> = memo(FilterInputer);
|
||||
|
||||
export default function showCreateShortcutDialog(shortcutId?: string): void {
|
||||
export default function showCreateShortcutDialog(shortcutId?: ShortcutId): void {
|
||||
showDialog(
|
||||
{
|
||||
className: "create-shortcut-dialog",
|
||||
|
@ -1,9 +1,10 @@
|
||||
import { useContext, useEffect } from "react";
|
||||
import { locationService, shortcutService } from "../services";
|
||||
import appContext from "../stores/appContext";
|
||||
import { UNKNOWN_ID } from "../helpers/consts";
|
||||
import utils from "../helpers/utils";
|
||||
import useToggle from "../hooks/useToggle";
|
||||
import useLoading from "../hooks/useLoading";
|
||||
import utils from "../helpers/utils";
|
||||
import toastHelper from "./Toast";
|
||||
import showCreateShortcutDialog from "./CreateShortcutDialog";
|
||||
import "../less/shortcut-list.less";
|
||||
@ -47,7 +48,7 @@ const ShortcutList: React.FC<Props> = () => {
|
||||
</p>
|
||||
<div className="shortcuts-container">
|
||||
{sortedShortcuts.map((s) => {
|
||||
return <ShortcutContainer key={s.id} shortcut={s} isActive={s.id === shortcutId} />;
|
||||
return <ShortcutContainer key={s.id} shortcut={s} isActive={s.id === Number(shortcutId)} />;
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
@ -65,7 +66,7 @@ const ShortcutContainer: React.FC<ShortcutContainerProps> = (props: ShortcutCont
|
||||
|
||||
const handleShortcutClick = () => {
|
||||
if (isActive) {
|
||||
locationService.setMemoShortcut("");
|
||||
locationService.setMemoShortcut(UNKNOWN_ID);
|
||||
} else {
|
||||
if (!["/"].includes(locationService.getState().pathname)) {
|
||||
locationService.setPathname("/");
|
||||
|
@ -204,7 +204,7 @@ namespace api {
|
||||
});
|
||||
}
|
||||
|
||||
export function updateShortcut(shortcutId: string, title: string, payload: string) {
|
||||
export function updateShortcut(shortcutId: ShortcutId, title: string, payload: string) {
|
||||
return request<Shortcut>({
|
||||
method: "PATCH",
|
||||
url: `/api/shortcut/${shortcutId}`,
|
||||
@ -215,14 +215,14 @@ namespace api {
|
||||
});
|
||||
}
|
||||
|
||||
export function deleteShortcutById(shortcutId: string) {
|
||||
export function deleteShortcutById(shortcutId: ShortcutId) {
|
||||
return request({
|
||||
method: "DELETE",
|
||||
url: `/api/shortcut/${shortcutId}`,
|
||||
});
|
||||
}
|
||||
|
||||
export function pinShortcut(shortcutId: string) {
|
||||
export function pinShortcut(shortcutId: ShortcutId) {
|
||||
return request({
|
||||
method: "PATCH",
|
||||
url: `/api/shortcut/${shortcutId}`,
|
||||
@ -232,7 +232,7 @@ namespace api {
|
||||
});
|
||||
}
|
||||
|
||||
export function unpinShortcut(shortcutId: string) {
|
||||
export function unpinShortcut(shortcutId: ShortcutId) {
|
||||
return request({
|
||||
method: "PATCH",
|
||||
url: `/api/shortcut/${shortcutId}`,
|
||||
|
@ -36,13 +36,12 @@ class LocationService {
|
||||
duration: null,
|
||||
text: "",
|
||||
type: "",
|
||||
shortcutId: "",
|
||||
},
|
||||
};
|
||||
state.query.tag = urlParams.get("tag") ?? "";
|
||||
state.query.type = (urlParams.get("type") ?? "") as MemoSpecType;
|
||||
state.query.text = urlParams.get("text") ?? "";
|
||||
state.query.shortcutId = urlParams.get("shortcutId") ?? "";
|
||||
state.query.shortcutId = Number(urlParams.get("shortcutId")) ?? undefined;
|
||||
const from = parseInt(urlParams.get("from") ?? "0");
|
||||
const to = parseInt(urlParams.get("to") ?? "0");
|
||||
if (to > from && to !== 0) {
|
||||
@ -71,7 +70,6 @@ class LocationService {
|
||||
duration: null,
|
||||
text: "",
|
||||
type: "",
|
||||
shortcutId: "",
|
||||
},
|
||||
});
|
||||
|
||||
@ -142,7 +140,7 @@ class LocationService {
|
||||
updateLocationUrl();
|
||||
};
|
||||
|
||||
public setMemoShortcut = (shortcutId: string) => {
|
||||
public setMemoShortcut = (shortcutId?: ShortcutId) => {
|
||||
appStore.dispatch({
|
||||
type: "SET_SHORTCUT_ID",
|
||||
payload: shortcutId,
|
||||
|
@ -1,6 +1,7 @@
|
||||
import userService from "./userService";
|
||||
import api from "../helpers/api";
|
||||
import appStore from "../stores/appStore";
|
||||
import { UNKNOWN_ID } from "../helpers/consts";
|
||||
|
||||
class ShortcutService {
|
||||
public getState() {
|
||||
@ -22,10 +23,14 @@ class ShortcutService {
|
||||
return data;
|
||||
}
|
||||
|
||||
public getShortcutById(id: string) {
|
||||
for (const q of this.getState().shortcuts) {
|
||||
if (q.id === id) {
|
||||
return q;
|
||||
public getShortcutById(id: ShortcutId) {
|
||||
if (id === UNKNOWN_ID) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (const s of this.getState().shortcuts) {
|
||||
if (s.id === id) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
@ -50,7 +55,7 @@ class ShortcutService {
|
||||
});
|
||||
}
|
||||
|
||||
public async deleteShortcut(shortcutId: string) {
|
||||
public async deleteShortcut(shortcutId: ShortcutId) {
|
||||
await api.deleteShortcutById(shortcutId);
|
||||
appStore.dispatch({
|
||||
type: "DELETE_SHORTCUT_BY_ID",
|
||||
@ -60,21 +65,21 @@ class ShortcutService {
|
||||
});
|
||||
}
|
||||
|
||||
public async createShortcut(title: string, shortcutstring: string) {
|
||||
const data = await api.createShortcut(title, shortcutstring);
|
||||
public async createShortcut(title: string, payload: string) {
|
||||
const data = await api.createShortcut(title, payload);
|
||||
return data;
|
||||
}
|
||||
|
||||
public async updateShortcut(shortcutId: string, title: string, shortcutstring: string) {
|
||||
const data = await api.updateShortcut(shortcutId, title, shortcutstring);
|
||||
public async updateShortcut(shortcutId: ShortcutId, title: string, payload: string) {
|
||||
const data = await api.updateShortcut(shortcutId, title, payload);
|
||||
return data;
|
||||
}
|
||||
|
||||
public async pinShortcut(shortcutId: string) {
|
||||
public async pinShortcut(shortcutId: ShortcutId) {
|
||||
await api.pinShortcut(shortcutId);
|
||||
}
|
||||
|
||||
public async unpinShortcut(shortcutId: string) {
|
||||
public async unpinShortcut(shortcutId: ShortcutId) {
|
||||
await api.unpinShortcut(shortcutId);
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ interface SetQueryAction {
|
||||
|
||||
interface SetShortcutIdAction {
|
||||
type: "SET_SHORTCUT_ID";
|
||||
payload: string;
|
||||
payload: ShortcutId | undefined;
|
||||
}
|
||||
|
||||
interface SetTagQueryAction {
|
||||
@ -183,6 +183,5 @@ export const defaultState: State = {
|
||||
duration: null,
|
||||
type: "",
|
||||
text: "",
|
||||
shortcutId: "",
|
||||
},
|
||||
};
|
||||
|
@ -21,7 +21,7 @@ interface InsertShortcutAction {
|
||||
interface DeleteShortcutByIdAction {
|
||||
type: "DELETE_SHORTCUT_BY_ID";
|
||||
payload: {
|
||||
id: string;
|
||||
id: ShortcutId;
|
||||
};
|
||||
}
|
||||
|
||||
|
2
web/src/types/location.d.ts
vendored
2
web/src/types/location.d.ts
vendored
@ -8,7 +8,7 @@ interface Query {
|
||||
duration: Duration | null;
|
||||
type: MemoSpecType | "";
|
||||
text: string;
|
||||
shortcutId: string;
|
||||
shortcutId?: ShortcutId;
|
||||
}
|
||||
|
||||
type AppRouter = "/" | "/signin";
|
||||
|
2
web/src/types/modules/shortcut.d.ts
vendored
2
web/src/types/modules/shortcut.d.ts
vendored
@ -1,7 +1,7 @@
|
||||
type ShortcutId = number;
|
||||
|
||||
interface Shortcut {
|
||||
id: string;
|
||||
id: ShortcutId;
|
||||
|
||||
rowStatus: RowStatus;
|
||||
createdTs: TimeStamp;
|
||||
|
Reference in New Issue
Block a user