diff --git a/src/main/tipc.ts b/src/main/tipc.ts index 368a627919..c6bf87b7f4 100644 --- a/src/main/tipc.ts +++ b/src/main/tipc.ts @@ -1,8 +1,9 @@ -import { tipc, getRendererHandlers } from "@egoist/tipc/main" +import { getRendererHandlers, tipc } from "@egoist/tipc/main" import type { MessageBoxOptions } from "electron" import { dialog, Menu, ShareMenu } from "electron" -import { RendererHandlers } from "./renderer-handlers" + import { getMainWindow } from "." +import type { RendererHandlers } from "./renderer-handlers" const t = tipc.create() diff --git a/src/renderer/src/App.tsx b/src/renderer/src/App.tsx index 8c0dd1e1db..8dd5eda086 100644 --- a/src/renderer/src/App.tsx +++ b/src/renderer/src/App.tsx @@ -1,11 +1,9 @@ +import { queryClient } from "@renderer/lib/query-client" +import { useEffect } from "react" import { Outlet } from "react-router-dom" import { useDark } from "./hooks/useDark" import { handlers } from "./tipc" -import { useEffect } from "react" - -import { queryClient } from "@renderer/lib/query-client" - function App() { useDark() diff --git a/src/renderer/src/pages/add/index.tsx b/src/renderer/src/pages/add/index.tsx index 1011e63630..d0db50166a 100644 --- a/src/renderer/src/pages/add/index.tsx +++ b/src/renderer/src/pages/add/index.tsx @@ -1,7 +1,8 @@ -import { zodResolver } from "@hookform/resolvers/zod"; -import { FollowSummary } from "@renderer/components/feed-summary"; -import { AutoComplete } from "@renderer/components/ui/autocomplete"; -import { Button } from "@renderer/components/ui/button"; +import { zodResolver } from "@hookform/resolvers/zod" +import { FollowSummary } from "@renderer/components/feed-summary" +import { AutoComplete } from "@renderer/components/ui/autocomplete" +import { Button } from "@renderer/components/ui/button" +import { Card, CardHeader } from "@renderer/components/ui/card" import { Form, FormControl, @@ -10,60 +11,59 @@ import { FormItem, FormLabel, FormMessage, -} from "@renderer/components/ui/form"; +} from "@renderer/components/ui/form" import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, -} from "@renderer/components/ui/select"; -import { Switch } from "@renderer/components/ui/switch"; -import { useBizQuery } from "@renderer/hooks/useBizQuery"; -import { views } from "@renderer/lib/constants"; -import { cn } from "@renderer/lib/utils"; -import { Queries } from "@renderer/queries"; -import { apiFetch } from "@renderer/queries/api-fetch"; -import { useFeed } from "@renderer/queries/feed"; -import { useMutation } from "@tanstack/react-query"; -import { useEffect } from "react"; -import { useForm } from "react-hook-form"; -import { z } from "zod"; -import { Card, CardHeader } from "@renderer/components/ui/card"; -import { client } from "@renderer/lib/client"; +} from "@renderer/components/ui/select" +import { Switch } from "@renderer/components/ui/switch" +import { useBizQuery } from "@renderer/hooks/useBizQuery" +import { client } from "@renderer/lib/client" +import { views } from "@renderer/lib/constants" +import { cn } from "@renderer/lib/utils" +import { Queries } from "@renderer/queries" +import { apiFetch } from "@renderer/queries/api-fetch" +import { useFeed } from "@renderer/queries/feed" +import { useMutation } from "@tanstack/react-query" +import { useEffect } from "react" +import { useForm } from "react-hook-form" +import { z } from "zod" const formSchema = z.object({ view: z.string(), category: z.string().nullable().optional(), isPrivate: z.boolean().optional(), -}); +}) export function Component() { - const urlSearchParams = new URLSearchParams(location.search); - const paramUrl = urlSearchParams.get("url"); - const url = paramUrl ? decodeURIComponent(paramUrl) : undefined; - const id = urlSearchParams.get("id") || undefined; + const urlSearchParams = new URLSearchParams(location.search) + const paramUrl = urlSearchParams.get("url") + const url = paramUrl ? decodeURIComponent(paramUrl) : undefined + const id = urlSearchParams.get("id") || undefined const feed = useFeed({ url, id, - }); + }) - const isSubscribed = !!feed.data?.subscription; + const isSubscribed = !!feed.data?.subscription const form = useForm>({ resolver: zodResolver(formSchema), defaultValues: { view: "0", }, - }); + }) useEffect(() => { if (feed.data?.subscription) { - form.setValue("view", `${feed.data?.subscription?.view}`); - form.setValue("category", feed.data?.subscription?.category); - form.setValue("isPrivate", feed.data?.subscription?.isPrivate || false); + form.setValue("view", `${feed.data?.subscription?.view}`) + form.setValue("category", feed.data?.subscription?.category) + form.setValue("isPrivate", feed.data?.subscription?.isPrivate || false) } - }, [feed.data?.subscription]); + }, [feed.data?.subscription]) const followMutation = useMutation({ mutationFn: async (values: z.infer) => @@ -82,141 +82,141 @@ export function Component() { isSubscribed && variables.view !== `${feed.data?.subscription?.view}` ) { - Queries.subscription.byView(feed.data?.subscription?.view).invalidate(); + Queries.subscription.byView(feed.data?.subscription?.view).invalidate() client?.invalidateQuery( - Queries.subscription.byView(feed.data?.subscription?.view).key - ); + Queries.subscription.byView(feed.data?.subscription?.view).key, + ) } - Queries.subscription.byView(Number.parseInt(variables.view)).invalidate(); - client?.invalidateQuery(Queries.subscription.byView(Number.parseInt(variables.view)).key); - Queries.feed.byId({ id: feed.data?.feed.id }).invalidate(); - client?.invalidateQuery(Queries.feed.byId({ id: feed.data?.feed.id }).key); + Queries.subscription.byView(Number.parseInt(variables.view)).invalidate() + client?.invalidateQuery( + Queries.subscription.byView(Number.parseInt(variables.view)).key, + ) + Queries.feed.byId({ id: feed.data?.feed.id }).invalidate() + client?.invalidateQuery( + Queries.feed.byId({ id: feed.data?.feed.id }).key, + ) }, - }); + }) function onSubmit(values: z.infer) { - followMutation.mutate(values); + followMutation.mutate(values) } const categories = useBizQuery( - Queries.subscription.categories(Number.parseInt(form.watch("view"))) - ); + Queries.subscription.categories(Number.parseInt(form.watch("view"))), + ) return ( -
-
+
+
logo Add follow
- {feed.isLoading ? ( -
- Loading... -
- ) : ( - !feed.data?.feed ? ( -
-

Feed not found.

-

{url}

-
- ) : ( -
- - - - - -
- - ( - - View - + + + + + + + {views.map((view, index) => ( + +
+ + {view.icon} + + {view.name} +
+
+ ))} +
+ + +
+ )} + /> + ( + +
+ Category + + By default, your follows will be grouped by website. + +
+ + + + +
+ )} + /> + ( + +
+ Prviate Follow + + Whether this follow is publicly visible on your profile + page. + +
+ + + +
+ )} + /> + - - -
- ) - )} + {isSubscribed ? "Update" : "Follow"} + + + +
+ )}
- ); + ) } diff --git a/src/renderer/src/queries/index.ts b/src/renderer/src/queries/index.ts index 78384f68fa..f0789d415f 100644 --- a/src/renderer/src/queries/index.ts +++ b/src/renderer/src/queries/index.ts @@ -1,6 +1,6 @@ import { entries } from "./entries" -import { subscription } from "./subscriptions" import { feed } from "./feed" +import { subscription } from "./subscriptions" export const Queries = { subscription, diff --git a/src/renderer/src/tipc.ts b/src/renderer/src/tipc.ts index 221ea7bb53..1f39dac380 100644 --- a/src/renderer/src/tipc.ts +++ b/src/renderer/src/tipc.ts @@ -1,13 +1,15 @@ import { createEventHandlers } from "@egoist/tipc/renderer" -import { RendererHandlers } from "@main/renderer-handlers" +import type { RendererHandlers } from "@main/renderer-handlers" -export const handlers = window.electron ? createEventHandlers({ - on: (channel, callback) => { - const remover = window.electron!.ipcRenderer.on(channel, callback) - return () => { - remover() - } - }, +export const handlers = window.electron ? + createEventHandlers({ + on: (channel, callback) => { + const remover = window.electron!.ipcRenderer.on(channel, callback) + return () => { + remover() + } + }, - send: window.electron!.ipcRenderer.send, -}) : null + send: window.electron!.ipcRenderer.send, + }) : + null