Skip to content

Commit

Permalink
feat(custom-schema): add support for name and desc fields
Browse files Browse the repository at this point in the history
  • Loading branch information
greenhat616 committed Apr 2, 2024
1 parent 70c03cc commit 6121545
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/components/profile/profile-viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import MDYSwitch from "../common/mdy-switch";
interface Props {
onChange: () => void;
url?: string;
name?: string;
desc?: string;
}

export interface ProfileViewerRef {
Expand Down
17 changes: 14 additions & 3 deletions src/pages/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
});
}
});
Expand Down
8 changes: 5 additions & 3 deletions src/pages/profiles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -430,7 +430,9 @@ export default function ProfilePage() {

<ProfileViewer
ref={viewerRef}
url={location.state != null ? (location.state.scheme as string) : ""}
url={location.state?.subscribe?.url as string | undefined}
name={location.state?.subscribe?.name as string | undefined}
desc={location.state?.subscribe?.desc as string | undefined}
onChange={() => mutateProfiles()}
/>
<ConfigViewer ref={configRef} />
Expand Down

0 comments on commit 6121545

Please sign in to comment.