mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
fix: duration query string (#465)
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||||
|
import { parse, ParsedQs } from "qs";
|
||||||
|
|
||||||
interface Duration {
|
interface Duration {
|
||||||
from: number;
|
from: number;
|
||||||
@@ -31,7 +32,7 @@ const getValidPathname = (pathname: string): string => {
|
|||||||
|
|
||||||
const getStateFromLocation = () => {
|
const getStateFromLocation = () => {
|
||||||
const { pathname, search, hash } = window.location;
|
const { pathname, search, hash } = window.location;
|
||||||
const urlParams = new URLSearchParams(search);
|
const urlParams = parse(search.slice(1));
|
||||||
const state: State = {
|
const state: State = {
|
||||||
pathname: getValidPathname(pathname),
|
pathname: getValidPathname(pathname),
|
||||||
hash: hash,
|
hash: hash,
|
||||||
@@ -40,20 +41,22 @@ const getStateFromLocation = () => {
|
|||||||
|
|
||||||
if (search !== "") {
|
if (search !== "") {
|
||||||
state.query = {};
|
state.query = {};
|
||||||
state.query.tag = urlParams.get("tag") ?? undefined;
|
state.query.tag = urlParams["tag"] as string;
|
||||||
state.query.type = (urlParams.get("type") as MemoSpecType) ?? undefined;
|
state.query.type = urlParams["type"] as MemoSpecType;
|
||||||
state.query.text = urlParams.get("text") ?? undefined;
|
state.query.text = urlParams["text"] as string;
|
||||||
const shortcutIdStr = urlParams.get("shortcutId");
|
const shortcutIdStr = urlParams["shortcutId"] as string;
|
||||||
state.query.shortcutId = shortcutIdStr ? Number(shortcutIdStr) : undefined;
|
state.query.shortcutId = shortcutIdStr ? Number(shortcutIdStr) : undefined;
|
||||||
const from = parseInt(urlParams.get("from") ?? "0");
|
const durationObj = urlParams["duration"] as ParsedQs;
|
||||||
const to = parseInt(urlParams.get("to") ?? "0");
|
if (durationObj) {
|
||||||
if (to > from && to !== 0) {
|
const duration: Duration = {
|
||||||
state.query.duration = {
|
from: Number(durationObj["from"]),
|
||||||
from,
|
to: Number(durationObj["to"]),
|
||||||
to,
|
|
||||||
};
|
};
|
||||||
|
if (duration.to > duration.from && duration.to !== 0) {
|
||||||
|
state.query.duration = duration;
|
||||||
}
|
}
|
||||||
state.query.visibility = (urlParams.get("visibility") as Visibility) ?? undefined;
|
}
|
||||||
|
state.query.visibility = urlParams["visibility"] as Visibility;
|
||||||
}
|
}
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
|
Reference in New Issue
Block a user