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";
|
import "../less/create-shortcut-dialog.less";
|
||||||
|
|
||||||
interface Props extends DialogProps {
|
interface Props extends DialogProps {
|
||||||
shortcutId?: string;
|
shortcutId?: ShortcutId;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CreateShortcutDialog: React.FC<Props> = (props: Props) => {
|
const CreateShortcutDialog: React.FC<Props> = (props: Props) => {
|
||||||
@ -23,12 +23,14 @@ const CreateShortcutDialog: React.FC<Props> = (props: Props) => {
|
|||||||
}).length;
|
}).length;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const shortcutTemp = shortcutService.getShortcutById(shortcutId ?? "");
|
if (shortcutId) {
|
||||||
if (shortcutTemp) {
|
const shortcutTemp = shortcutService.getShortcutById(shortcutId);
|
||||||
setTitle(shortcutTemp.title);
|
if (shortcutTemp) {
|
||||||
const temp = JSON.parse(shortcutTemp.payload);
|
setTitle(shortcutTemp.title);
|
||||||
if (Array.isArray(temp)) {
|
const temp = JSON.parse(shortcutTemp.payload);
|
||||||
setFilters(temp);
|
if (Array.isArray(temp)) {
|
||||||
|
setFilters(temp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [shortcutId]);
|
}, [shortcutId]);
|
||||||
@ -298,7 +300,7 @@ const FilterInputer: React.FC<MemoFilterInputerProps> = (props: MemoFilterInpute
|
|||||||
|
|
||||||
const MemoFilterInputer: React.FC<MemoFilterInputerProps> = memo(FilterInputer);
|
const MemoFilterInputer: React.FC<MemoFilterInputerProps> = memo(FilterInputer);
|
||||||
|
|
||||||
export default function showCreateShortcutDialog(shortcutId?: string): void {
|
export default function showCreateShortcutDialog(shortcutId?: ShortcutId): void {
|
||||||
showDialog(
|
showDialog(
|
||||||
{
|
{
|
||||||
className: "create-shortcut-dialog",
|
className: "create-shortcut-dialog",
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
import { useContext, useEffect } from "react";
|
import { useContext, useEffect } from "react";
|
||||||
import { locationService, shortcutService } from "../services";
|
import { locationService, shortcutService } from "../services";
|
||||||
import appContext from "../stores/appContext";
|
import appContext from "../stores/appContext";
|
||||||
|
import { UNKNOWN_ID } from "../helpers/consts";
|
||||||
|
import utils from "../helpers/utils";
|
||||||
import useToggle from "../hooks/useToggle";
|
import useToggle from "../hooks/useToggle";
|
||||||
import useLoading from "../hooks/useLoading";
|
import useLoading from "../hooks/useLoading";
|
||||||
import utils from "../helpers/utils";
|
|
||||||
import toastHelper from "./Toast";
|
import toastHelper from "./Toast";
|
||||||
import showCreateShortcutDialog from "./CreateShortcutDialog";
|
import showCreateShortcutDialog from "./CreateShortcutDialog";
|
||||||
import "../less/shortcut-list.less";
|
import "../less/shortcut-list.less";
|
||||||
@ -47,7 +48,7 @@ const ShortcutList: React.FC<Props> = () => {
|
|||||||
</p>
|
</p>
|
||||||
<div className="shortcuts-container">
|
<div className="shortcuts-container">
|
||||||
{sortedShortcuts.map((s) => {
|
{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>
|
||||||
</div>
|
</div>
|
||||||
@ -65,7 +66,7 @@ const ShortcutContainer: React.FC<ShortcutContainerProps> = (props: ShortcutCont
|
|||||||
|
|
||||||
const handleShortcutClick = () => {
|
const handleShortcutClick = () => {
|
||||||
if (isActive) {
|
if (isActive) {
|
||||||
locationService.setMemoShortcut("");
|
locationService.setMemoShortcut(UNKNOWN_ID);
|
||||||
} else {
|
} else {
|
||||||
if (!["/"].includes(locationService.getState().pathname)) {
|
if (!["/"].includes(locationService.getState().pathname)) {
|
||||||
locationService.setPathname("/");
|
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>({
|
return request<Shortcut>({
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
url: `/api/shortcut/${shortcutId}`,
|
url: `/api/shortcut/${shortcutId}`,
|
||||||
@ -215,14 +215,14 @@ namespace api {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function deleteShortcutById(shortcutId: string) {
|
export function deleteShortcutById(shortcutId: ShortcutId) {
|
||||||
return request({
|
return request({
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
url: `/api/shortcut/${shortcutId}`,
|
url: `/api/shortcut/${shortcutId}`,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function pinShortcut(shortcutId: string) {
|
export function pinShortcut(shortcutId: ShortcutId) {
|
||||||
return request({
|
return request({
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
url: `/api/shortcut/${shortcutId}`,
|
url: `/api/shortcut/${shortcutId}`,
|
||||||
@ -232,7 +232,7 @@ namespace api {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function unpinShortcut(shortcutId: string) {
|
export function unpinShortcut(shortcutId: ShortcutId) {
|
||||||
return request({
|
return request({
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
url: `/api/shortcut/${shortcutId}`,
|
url: `/api/shortcut/${shortcutId}`,
|
||||||
|
@ -36,13 +36,12 @@ class LocationService {
|
|||||||
duration: null,
|
duration: null,
|
||||||
text: "",
|
text: "",
|
||||||
type: "",
|
type: "",
|
||||||
shortcutId: "",
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
state.query.tag = urlParams.get("tag") ?? "";
|
state.query.tag = urlParams.get("tag") ?? "";
|
||||||
state.query.type = (urlParams.get("type") ?? "") as MemoSpecType;
|
state.query.type = (urlParams.get("type") ?? "") as MemoSpecType;
|
||||||
state.query.text = urlParams.get("text") ?? "";
|
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 from = parseInt(urlParams.get("from") ?? "0");
|
||||||
const to = parseInt(urlParams.get("to") ?? "0");
|
const to = parseInt(urlParams.get("to") ?? "0");
|
||||||
if (to > from && to !== 0) {
|
if (to > from && to !== 0) {
|
||||||
@ -71,7 +70,6 @@ class LocationService {
|
|||||||
duration: null,
|
duration: null,
|
||||||
text: "",
|
text: "",
|
||||||
type: "",
|
type: "",
|
||||||
shortcutId: "",
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -142,7 +140,7 @@ class LocationService {
|
|||||||
updateLocationUrl();
|
updateLocationUrl();
|
||||||
};
|
};
|
||||||
|
|
||||||
public setMemoShortcut = (shortcutId: string) => {
|
public setMemoShortcut = (shortcutId?: ShortcutId) => {
|
||||||
appStore.dispatch({
|
appStore.dispatch({
|
||||||
type: "SET_SHORTCUT_ID",
|
type: "SET_SHORTCUT_ID",
|
||||||
payload: shortcutId,
|
payload: shortcutId,
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import userService from "./userService";
|
import userService from "./userService";
|
||||||
import api from "../helpers/api";
|
import api from "../helpers/api";
|
||||||
import appStore from "../stores/appStore";
|
import appStore from "../stores/appStore";
|
||||||
|
import { UNKNOWN_ID } from "../helpers/consts";
|
||||||
|
|
||||||
class ShortcutService {
|
class ShortcutService {
|
||||||
public getState() {
|
public getState() {
|
||||||
@ -22,10 +23,14 @@ class ShortcutService {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getShortcutById(id: string) {
|
public getShortcutById(id: ShortcutId) {
|
||||||
for (const q of this.getState().shortcuts) {
|
if (id === UNKNOWN_ID) {
|
||||||
if (q.id === id) {
|
return null;
|
||||||
return q;
|
}
|
||||||
|
|
||||||
|
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);
|
await api.deleteShortcutById(shortcutId);
|
||||||
appStore.dispatch({
|
appStore.dispatch({
|
||||||
type: "DELETE_SHORTCUT_BY_ID",
|
type: "DELETE_SHORTCUT_BY_ID",
|
||||||
@ -60,21 +65,21 @@ class ShortcutService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async createShortcut(title: string, shortcutstring: string) {
|
public async createShortcut(title: string, payload: string) {
|
||||||
const data = await api.createShortcut(title, shortcutstring);
|
const data = await api.createShortcut(title, payload);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async updateShortcut(shortcutId: string, title: string, shortcutstring: string) {
|
public async updateShortcut(shortcutId: ShortcutId, title: string, payload: string) {
|
||||||
const data = await api.updateShortcut(shortcutId, title, shortcutstring);
|
const data = await api.updateShortcut(shortcutId, title, payload);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async pinShortcut(shortcutId: string) {
|
public async pinShortcut(shortcutId: ShortcutId) {
|
||||||
await api.pinShortcut(shortcutId);
|
await api.pinShortcut(shortcutId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async unpinShortcut(shortcutId: string) {
|
public async unpinShortcut(shortcutId: ShortcutId) {
|
||||||
await api.unpinShortcut(shortcutId);
|
await api.unpinShortcut(shortcutId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ interface SetQueryAction {
|
|||||||
|
|
||||||
interface SetShortcutIdAction {
|
interface SetShortcutIdAction {
|
||||||
type: "SET_SHORTCUT_ID";
|
type: "SET_SHORTCUT_ID";
|
||||||
payload: string;
|
payload: ShortcutId | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface SetTagQueryAction {
|
interface SetTagQueryAction {
|
||||||
@ -183,6 +183,5 @@ export const defaultState: State = {
|
|||||||
duration: null,
|
duration: null,
|
||||||
type: "",
|
type: "",
|
||||||
text: "",
|
text: "",
|
||||||
shortcutId: "",
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -21,7 +21,7 @@ interface InsertShortcutAction {
|
|||||||
interface DeleteShortcutByIdAction {
|
interface DeleteShortcutByIdAction {
|
||||||
type: "DELETE_SHORTCUT_BY_ID";
|
type: "DELETE_SHORTCUT_BY_ID";
|
||||||
payload: {
|
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;
|
duration: Duration | null;
|
||||||
type: MemoSpecType | "";
|
type: MemoSpecType | "";
|
||||||
text: string;
|
text: string;
|
||||||
shortcutId: string;
|
shortcutId?: ShortcutId;
|
||||||
}
|
}
|
||||||
|
|
||||||
type AppRouter = "/" | "/signin";
|
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;
|
type ShortcutId = number;
|
||||||
|
|
||||||
interface Shortcut {
|
interface Shortcut {
|
||||||
id: string;
|
id: ShortcutId;
|
||||||
|
|
||||||
rowStatus: RowStatus;
|
rowStatus: RowStatus;
|
||||||
createdTs: TimeStamp;
|
createdTs: TimeStamp;
|
||||||
|
Reference in New Issue
Block a user