From 61215450f14d3426b42355cb8d71595bb9901939 Mon Sep 17 00:00:00 2001 From: Jonson Petard Date: Tue, 2 Apr 2024 23:23:32 +0800 Subject: [PATCH] feat(custom-schema): add support for name and desc fields --- src/components/profile/profile-viewer.tsx | 2 ++ src/pages/_layout.tsx | 17 ++++++++++++++--- src/pages/profiles.tsx | 8 +++++--- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/components/profile/profile-viewer.tsx b/src/components/profile/profile-viewer.tsx index cfc06af446..15b48c40ef 100644 --- a/src/components/profile/profile-viewer.tsx +++ b/src/components/profile/profile-viewer.tsx @@ -28,6 +28,8 @@ import MDYSwitch from "../common/mdy-switch"; interface Props { onChange: () => void; url?: string; + name?: string; + desc?: string; } export interface ProfileViewerRef { diff --git a/src/pages/_layout.tsx b/src/pages/_layout.tsx index 588f3818b3..5273d11612 100644 --- a/src/pages/_layout.tsx +++ b/src/pages/_layout.tsx @@ -91,11 +91,22 @@ export default function Layout() { listen("scheme-request-received", (req) => { const message: string = req.payload as string; const url = new URL(message); + if (url.pathname.endsWith("/")) url.pathname = url.pathname.slice(0, -1); + if (url.pathname.startsWith("//")) url.pathname = url.pathname.slice(1); switch (url.pathname) { - case "//subscribe-remote-profile": - case "//subscribe-remote-profile/": + case "/subscribe-remote-profile": navigate("/profile", { - state: { scheme: url.searchParams.get("url") }, + state: { + subscribe: { + url: url.searchParams.get("url"), + name: url.searchParams.has("name") + ? decodeURIComponent(url.searchParams.get("name")!) + : undefined, + desc: url.searchParams.has("desc") + ? decodeURIComponent(url.searchParams.get("desc")!) + : undefined, + }, + }, }); } }); diff --git a/src/pages/profiles.tsx b/src/pages/profiles.tsx index 57570fc91e..01e3205797 100644 --- a/src/pages/profiles.tsx +++ b/src/pages/profiles.tsx @@ -42,12 +42,12 @@ import { import { LoadingButton } from "@mui/lab"; import { Box, Button, Grid, IconButton, Stack, TextField } from "@mui/material"; import { useLockFn } from "ahooks"; -import { over, throttle } from "lodash-es"; +import { throttle } from "lodash-es"; import { useEffect, useMemo, useRef, useState } from "react"; import { useTranslation } from "react-i18next"; +import { useLocation } from "react-router-dom"; import { useSetRecoilState } from "recoil"; import useSWR, { mutate } from "swr"; -import { useLocation } from "react-router-dom"; export default function ProfilePage() { const { t } = useTranslation(); @@ -430,7 +430,9 @@ export default function ProfilePage() { mutateProfiles()} />