feat: feed claim (#77)

* feat: logo pos

Signed-off-by: Innei <i@innei.in>

* feat: feed claim modal init

Signed-off-by: Innei <i@innei.in>

* feat: tab indicator animated

Signed-off-by: Innei <i@innei.in>

* feat: claim modal ui

Signed-off-by: Innei <i@innei.in>

* feat: claim api

Signed-off-by: Innei <i@innei.in>

* Update src/renderer/src/queries/feed.ts

* feat: claim

Signed-off-by: Innei <i@innei.in>

* update

Signed-off-by: Innei <i@innei.in>

* style: format

---------

Signed-off-by: Innei <i@innei.in>
Co-authored-by: DIYgod <i@diygod.me>
This commit is contained in:
Innei
2024-06-21 17:51:44 +08:00
committed by GitHub
co-authored by DIYgod
parent b9613c11a0
commit 73e96ba1ed
28 changed files with 547 additions and 153 deletions
+1
View File
@@ -21,6 +21,7 @@ export default defineConfig(
"unicorn/consistent-function-scoping": "warn",
"unicorn/prefer-module": "off",
"@typescript-eslint/no-floating-promises": "off",
"@typescript-eslint/no-unused-expressions": 0,
},
settings: {
tailwindcss: {
+1
View File
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none"><path fill="#fff" fill-opacity=".01" d="M24 0v24H0V0z"/><path fill="#10161F" fill-rule="evenodd" d="M12 2C6.477 2 2 6.477 2 12s4.477 10 10 10 10-4.477 10-10S17.523 2 12 2m4.95 7.795a1 1 0 0 0-1.415-1.414l-4.95 4.95-2.12-2.121a1 1 0 0 0-1.415 1.414l2.829 2.828a1 1 0 0 0 1.414 0z" clip-rule="evenodd"/></svg>

After

Width:  |  Height:  |  Size: 382 B

+1
View File
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none"><path fill="#fff" fill-opacity=".01" d="M24 0v24H0V0z"/><path fill="#10161F" fill-rule="evenodd" d="M21.546 5.112a1.5 1.5 0 0 1 0 2.121L10.232 18.547a1.5 1.5 0 0 1-2.121 0L2.454 12.89a1.5 1.5 0 1 1 2.121-2.121l4.596 4.596L19.424 5.112a1.5 1.5 0 0 1 2.122 0" clip-rule="evenodd"/></svg>

After

Width:  |  Height:  |  Size: 360 B

+1
View File
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none"><path fill="#fff" fill-opacity=".01" d="M24 0v24H0V0z"/><path stroke="#10161F" stroke-width="2" d="M7.824 5c.09-.266.204-.504.35-.722a4 4 0 0 1 1.104-1.104C10.286 2.5 11.69 2.5 14.5 2.5c2.809 0 4.213 0 5.222.674.437.292.812.667 1.104 1.104.674 1.009.674 2.413.674 5.222 0 2.809 0 4.213-.674 5.222a4.003 4.003 0 0 1-1.104 1.104c-.219.146-.456.26-.722.35M9.5 21.5c2.809 0 4.213 0 5.222-.674a4.003 4.003 0 0 0 1.104-1.104c.674-1.009.674-2.413.674-5.222 0-2.809 0-4.213-.674-5.222a4.002 4.002 0 0 0-1.104-1.104C13.713 7.5 12.31 7.5 9.5 7.5c-2.809 0-4.213 0-5.222.674a4 4 0 0 0-1.104 1.104C2.5 10.287 2.5 11.69 2.5 14.5c0 2.809 0 4.213.674 5.222.292.437.667.812 1.104 1.104 1.009.674 2.413.674 5.222.674Z"/></svg>

After

Width:  |  Height:  |  Size: 783 B

+5 -1
View File
@@ -17,7 +17,10 @@ export const router = {
showContextMenu: t.procedure
.input<{
items: Array<{ type: "text", label: string } | { type: "separator" }>
items: Array<
| { type: "text", label: string, enabled?: boolean }
| { type: "separator" }
>
}>()
.action(async ({ input, context }) => {
const menu = Menu.buildFromTemplate(
@@ -29,6 +32,7 @@ export const router = {
}
return {
label: item.label,
enabled: item.enabled ?? true,
click() {
context.sender.send("menu-click", index)
},
+8
View File
@@ -0,0 +1,8 @@
/* eslint-disable unicorn/no-unreadable-array-destructuring */
import type { User } from "@auth/core/types"
import { createAtomHooks } from "@renderer/lib/jotai"
import { atom } from "jotai"
export const [, , useUser, useSetUser, getUser, setUser] = createAtomHooks(
atom<Nullable<User>>(null),
)
@@ -32,6 +32,7 @@ export const AutoResizeHeight: React.FC<AnimateChangeInHeightProps> = ({
const resizeObserver = new ResizeObserver((entries) => {
// We only have one entry, so we can use entries[0].
const observedHeight = entries[0].contentRect.height
// add margin top
setHeight(observedHeight)
})
@@ -125,8 +125,7 @@ export const ActionButton = React.forwardRef<
</TooltipTrigger>
<TooltipContent side={tooltipSide ?? "bottom"}>
{tooltip}
{shortcut &&
shortcut.split("+").map((key) => <Kbd key={key}>{key}</Kbd>)}
{shortcut && shortcut.split("+").map((key) => <Kbd key={key}>{key}</Kbd>)}
</TooltipContent>
</Tooltip>
</>
@@ -42,7 +42,7 @@ export const styledButtonVariant = cva(
{
variant: "plain",
status: "disabled",
className: "text-theme-disabled border-theme-inactive dark:border-zinc-800",
className: "text-theme-disabled border-theme-inactive dark:border-zinc-800 hover:!bg-theme-background",
},
],
variants: {
@@ -0,0 +1,64 @@
import { cn } from "@renderer/lib/utils"
import type { Variants } from "framer-motion"
import { AnimatePresence, m } from "framer-motion"
import { useCallback, useRef, useState } from "react"
import { MotionButtonBase } from "../button"
const copyIconVariants: Variants = {
initial: {
opacity: 1,
scale: 1,
},
animate: {
opacity: 1,
scale: 1,
},
exit: {
opacity: 0,
scale: 0,
},
}
export const CopyButton: Component<{
value: string
}> = ({ value, className }) => {
const [copied, setCopied] = useState(false)
const copiedTimerRef = useRef<any>()
const handleCopy = useCallback(() => {
navigator.clipboard.writeText(value)
setCopied(true)
clearTimeout(copiedTimerRef.current)
copiedTimerRef.current = setTimeout(() => {
setCopied(false)
}, 2000)
}, [value])
return (
<MotionButtonBase
onClick={handleCopy}
className={cn(
"center flex text-xs",
"rounded-md border border-theme-accent/5 bg-theme-accent/80 p-1.5 text-white backdrop-blur duration-200",
className,
)}
>
<AnimatePresence mode="wait">
{copied ? (
<m.i
key="copied"
className="i-mgc-check-filled size-4"
{...copyIconVariants}
/>
) : (
<m.i
key="copy"
className="i-mgc-copy-2-cute-re size-4"
{...copyIconVariants}
/>
)}
</AnimatePresence>
</MotionButtonBase>
)
}
@@ -0,0 +1 @@
export * from "./copy-button"
+70 -39
View File
@@ -2,29 +2,26 @@ import * as TabsPrimitive from "@radix-ui/react-tabs"
import { cn } from "@renderer/lib/utils"
import type { VariantProps } from "class-variance-authority"
import { cva } from "class-variance-authority"
import { m } from "framer-motion"
import * as React from "react"
const Tabs = TabsPrimitive.Root
const tabsListVariants = cva(
"",
{
variants: {
variant: {
default: "border-b",
rounded: "rounded-md bg-muted p-1",
},
},
defaultVariants: {
variant: "default",
const tabsListVariants = cva("", {
variants: {
variant: {
default: "border-b",
rounded: "rounded-md bg-muted p-1",
},
},
)
defaultVariants: {
variant: "default",
},
})
export interface TabsListProps
extends React.ComponentPropsWithoutRef<typeof TabsPrimitive.List>,
VariantProps<typeof tabsListVariants> {
}
VariantProps<typeof tabsListVariants> {}
const TabsList = React.forwardRef<
React.ElementRef<typeof TabsPrimitive.List>,
TabsListProps
@@ -41,39 +38,73 @@ const TabsList = React.forwardRef<
))
TabsList.displayName = TabsPrimitive.List.displayName
const tabsTriggerVariants = cva(
"",
{
variants: {
variant: {
default: "py-1.5 border-b-2 border-transparent data-[state=active]:border-current data-[state=active]:text-theme-accent dark:data-[state=active]:text-theme-accent-500",
rounded: "py-1 rounded-sm data-[state=active]:bg-theme-accent-300 dark:data-[state=active]:bg-theme-accent-800 data-[state=active]:shadow-sm",
},
},
defaultVariants: {
variant: "default",
const tabsTriggerVariants = cva("", {
variants: {
variant: {
default:
"py-1.5 border-b-2 border-transparent data-[state=active]:text-theme-accent dark:data-[state=active]:text-theme-accent-500",
rounded:
"py-1 rounded-sm data-[state=active]:bg-theme-accent-300 dark:data-[state=active]:bg-theme-accent-800 data-[state=active]:shadow-sm",
},
},
)
defaultVariants: {
variant: "default",
},
})
export interface TabsTriggerProps
extends React.ComponentPropsWithoutRef<typeof TabsPrimitive.Trigger>,
VariantProps<typeof tabsTriggerVariants> {
}
VariantProps<typeof tabsTriggerVariants> {}
const TabsTrigger = React.forwardRef<
React.ElementRef<typeof TabsPrimitive.Trigger>,
TabsTriggerProps
>(({ className, variant, ...props }, ref) => (
<TabsPrimitive.Trigger
ref={ref}
className={cn(
"inline-flex items-center justify-center whitespace-nowrap px-3 text-sm font-medium ring-offset-background transition-all disabled:pointer-events-none disabled:opacity-50 data-[state=active]:text-theme-foreground",
tabsTriggerVariants({ variant }),
className,
)}
{...props}
/>
))
>(({ className, variant, children, ...props }, ref) => {
const triggerRef = React.useRef(null)
React.useImperativeHandle(ref, () => triggerRef.current!, [ref])
const [isSelect, setIsSelect] = React.useState(false)
React.useLayoutEffect(() => {
if (!triggerRef.current) return
const trigger = triggerRef.current as HTMLElement
const isSelect = trigger.dataset.state === "active"
setIsSelect(isSelect)
const ob = new MutationObserver(() => {
const isSelect = trigger.dataset.state === "active"
setIsSelect(isSelect)
})
ob.observe(trigger, {
attributes: true,
attributeFilter: ["data-state"],
})
return () => {
ob.disconnect()
}
}, [])
return (
<TabsPrimitive.Trigger
ref={triggerRef}
className={cn(
"inline-flex items-center justify-center whitespace-nowrap px-3 text-sm font-medium ring-offset-background transition-all disabled:pointer-events-none disabled:opacity-50 data-[state=active]:text-theme-foreground",
"relative",
tabsTriggerVariants({ variant }),
className,
)}
{...props}
>
{children}
{isSelect && (
<m.span
layoutId="tab-selected-underline"
className="absolute -bottom-1 h-0.5 w-[calc(100%-16px)] rounded bg-theme-accent"
/>
)}
</TabsPrimitive.Trigger>
)
})
TabsTrigger.displayName = TabsPrimitive.Trigger.displayName
const TabsContent = React.forwardRef<
+89 -50
View File
@@ -14,10 +14,10 @@ declare const routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
};
};
output: {
code: 0;
data: {
transactionHash: string;
};
code: 0;
};
outputFormat: "json";
status: 200;
@@ -32,14 +32,14 @@ declare const routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
};
};
output: {
code: 0;
data: {
userId: string;
addressIndex: number;
address: string | null;
createdAt: string;
powerToken: bigint;
addressIndex: number;
address: string | null;
}[];
code: 0;
};
outputFormat: "json";
status: 200;
@@ -47,14 +47,14 @@ declare const routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
$post: {
input: {};
output: {
code: 0;
data: {
userId: string;
addressIndex: number;
address: string | null;
createdAt: string;
powerToken: bigint;
addressIndex: number;
address: string | null;
};
code: 0;
};
outputFormat: "json";
status: 200;
@@ -73,8 +73,8 @@ declare const routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
output: {
code: 0;
data?: {
title?: string | undefined;
description?: string | undefined;
title?: string | undefined;
} | undefined;
};
outputFormat: "json";
@@ -109,7 +109,7 @@ declare const routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
name: string;
condition: {
value: string;
field: "view" | "title" | "site_url" | "feed_url";
field: "title" | "view" | "site_url" | "feed_url";
operator: "contains" | "not_contains" | "eq" | "not_eq" | "gt" | "lt" | "regex";
}[];
result: {
@@ -121,7 +121,7 @@ declare const routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
}[] | undefined;
blockRules?: {
value: string | number;
field: "title" | "all" | "content" | "author" | "url" | "order";
field: "title" | "content" | "all" | "author" | "url" | "order";
operator: "contains" | "not_contains" | "eq" | "not_eq" | "gt" | "lt" | "regex";
}[] | undefined;
};
@@ -138,7 +138,7 @@ declare const routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
name: string;
condition: {
value: string;
field: "view" | "title" | "site_url" | "feed_url";
field: "title" | "view" | "site_url" | "feed_url";
operator: "contains" | "not_contains" | "eq" | "not_eq" | "gt" | "lt" | "regex";
}[];
result: {
@@ -150,7 +150,7 @@ declare const routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
}[] | undefined;
blockRules?: {
value: string | number;
field: "title" | "all" | "content" | "author" | "url" | "order";
field: "title" | "content" | "all" | "author" | "url" | "order";
operator: "contains" | "not_contains" | "eq" | "not_eq" | "gt" | "lt" | "regex";
}[] | undefined;
};
@@ -197,8 +197,8 @@ declare const routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
};
};
output: {
data: Record<string, number>;
code: 0;
data: Record<string, number>;
};
outputFormat: "json";
status: 200;
@@ -229,8 +229,8 @@ declare const routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
};
};
output: {
data: boolean;
code: 0;
data: boolean;
};
outputFormat: "json";
status: 200;
@@ -302,6 +302,40 @@ declare const routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
};
};
} & {
"/feeds/claim/message": {
$get: {
input: {
query: {
feedId: string;
};
};
output: {
code: 0;
data: {
xml: string;
description: string;
content: string;
json: string;
};
};
outputFormat: "json";
status: 200;
};
};
"/feeds/claim/challenge": {
$post: {
input: {
json: {
feedId: string;
};
};
output: {
code: 0;
};
outputFormat: "json";
status: 200;
};
};
"/feeds": {
$get: {
input: {
@@ -311,34 +345,35 @@ declare const routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
};
};
output: {
code: 0;
data: {
feed: {
url: string;
checkedAt: string;
nextCheckAt: string;
description?: string | null | undefined;
title?: string | null | undefined;
id?: string | undefined;
image?: string | null | undefined;
title?: string | null | undefined;
description?: string | null | undefined;
siteUrl?: string | null | undefined;
lastModifiedHeader?: string | null | undefined;
etagHeader?: string | null | undefined;
ttl?: number | null | undefined;
errorMessage?: string | null | undefined;
errorAt?: string | null | undefined;
ownerUserId?: string | null | undefined;
};
subscriptionCount: number;
readCount: number;
subscription?: {
title: string | null;
userId: string;
view: number;
title: string | null;
feedId: string;
category: string | null;
isPrivate: boolean | null;
} | undefined;
};
code: 0;
};
outputFormat: "json";
status: 200;
@@ -370,11 +405,11 @@ declare const routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
output: {
data: {
feed: {
description: string | null;
title: string | null;
id: string;
image: string | null;
title: string | null;
url: string;
description: string | null;
siteUrl: string | null;
checkedAt: string;
nextCheckAt: string;
@@ -383,14 +418,15 @@ declare const routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
ttl: number | null;
errorMessage: string | null;
errorAt: string | null;
ownerUserId: string | null;
};
entries?: {
id: string;
description: string | null;
title: string | null;
content: string | null;
id: string;
author: string | null;
url: string | null;
description: string | null;
feedId: string;
guid: string;
authorUrl: string | null;
@@ -401,9 +437,9 @@ declare const routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
categories: string[] | null;
enclosures?: {
url: string;
title?: string | undefined;
type?: string | undefined;
length?: number | undefined;
type?: string | undefined;
title?: string | undefined;
}[] | null | undefined;
}[] | undefined;
docs?: string | undefined;
@@ -420,12 +456,12 @@ declare const routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
$post: {
input: {};
output: {
code: 0;
data: {
userId: string;
sessionToken: string;
expires: string;
};
code: 0;
};
outputFormat: "json";
status: 200;
@@ -475,11 +511,11 @@ declare const routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
total: number;
data?: {
entries: {
id: string;
description: string | null;
title: string | null;
id: string;
author: string | null;
url: string | null;
description: string | null;
guid: string;
authorUrl: string | null;
authorAvatar: string | null;
@@ -489,17 +525,17 @@ declare const routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
categories: string[] | null;
enclosures?: {
url: string;
title?: string | undefined;
type?: string | undefined;
length?: number | undefined;
type?: string | undefined;
title?: string | undefined;
}[] | null | undefined;
};
feeds: {
description: string | null;
title: string | null;
id: string;
image: string | null;
title: string | null;
url: string;
description: string | null;
siteUrl: string | null;
checkedAt: string;
nextCheckAt: string;
@@ -508,6 +544,7 @@ declare const routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
ttl: number | null;
errorMessage: string | null;
errorAt: string | null;
ownerUserId: string | null;
};
read: boolean | null;
collections?: {
@@ -536,12 +573,12 @@ declare const routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
code: 0;
data?: {
entries: {
id: string;
description: string | null;
title: string | null;
content: string | null;
id: string;
author: string | null;
url: string | null;
description: string | null;
guid: string;
authorUrl: string | null;
authorAvatar: string | null;
@@ -551,17 +588,20 @@ declare const routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
categories: string[] | null;
enclosures?: {
url: string;
title?: string | undefined;
type?: string | undefined;
length?: number | undefined;
type?: string | undefined;
title?: string | undefined;
}[] | null | undefined;
};
collections: {
createdAt: string;
};
feeds: {
description: string | null;
title: string | null;
id: string;
image: string | null;
title: string | null;
url: string;
description: string | null;
siteUrl: string | null;
checkedAt: string;
nextCheckAt: string;
@@ -570,9 +610,7 @@ declare const routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
ttl: number | null;
errorMessage: string | null;
errorAt: string | null;
};
collections: {
createdAt: string;
ownerUserId: string | null;
};
read: boolean | null;
settings?: {
@@ -597,13 +635,14 @@ declare const routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
};
};
output: {
code: 0;
data: {
id: string;
description: string | null;
title: string | null;
content: string | null;
id: string;
author: string | null;
url: string | null;
description: string | null;
feedId: string;
guid: string;
authorUrl: string | null;
@@ -614,12 +653,11 @@ declare const routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
categories: string[] | null;
enclosures?: {
url: string;
title?: string | undefined;
type?: string | undefined;
length?: number | undefined;
type?: string | undefined;
title?: string | undefined;
}[] | null | undefined;
}[];
code: 0;
};
outputFormat: "json";
status: 200;
@@ -634,16 +672,18 @@ declare const routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
};
};
output: {
code: 0;
data: {
title: string | null;
userId: string;
view: number;
title: string | null;
feedId: string;
feeds: {
description: string | null;
title: string | null;
id: string;
image: string | null;
title: string | null;
url: string;
description: string | null;
siteUrl: string | null;
checkedAt: string;
nextCheckAt: string;
@@ -652,12 +692,11 @@ declare const routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
ttl: number | null;
errorMessage: string | null;
errorAt: string | null;
ownerUserId: string | null;
};
feedId: string;
category: string | null;
isPrivate: boolean | null;
}[];
code: 0;
};
outputFormat: "json";
status: 200;
+16 -4
View File
@@ -2,11 +2,8 @@ import { getCsrfToken } from "@hono/auth-js/react"
import type { AppType } from "@renderer/hono"
import { router } from "@renderer/router"
import { hc } from "hono/client"
import { ofetch } from "ofetch"
import { FetchError, ofetch } from "ofetch"
export abstract class RequestError extends Error {
name = "RequestError"
}
const csrfToken = await getCsrfToken()
export const apiFetch = ofetch.create({
@@ -39,3 +36,18 @@ export const apiFetch = ofetch.create({
export const apiClient = hc<AppType>("", {
fetch: async (input, options = {}) => apiFetch(input.toString(), options),
})
export const getFetchErrorMessage = (error: Error) => {
if (error instanceof FetchError) {
try {
const json = JSON.parse(error.response?._data)
// TODO get the biz code to show the error message, and for i18n
// const bizCode = json.code
return json.message || error.message
} catch {
return error.message
}
}
return error.message
}
+5 -6
View File
@@ -9,9 +9,7 @@ export type NativeMenuItem =
}
| { type: "separator" }
export const showNativeMenu = async (
items: Array<
{ type: "text", label: string, click: () => void } | { type: "separator" }
>,
items: Array<Nullable<NativeMenuItem | false>>,
e?: MouseEvent | React.MouseEvent,
) => {
const nextItems = [
@@ -55,9 +53,9 @@ export const showNativeMenu = async (
}
const unlisten = window.electron?.ipcRenderer.on("menu-click", (_, index) => {
const item = items[index]
const item = nextItems[index]
if (item && item.type === "text") {
item.click()
item.click?.()
}
})
@@ -69,10 +67,11 @@ export const showNativeMenu = async (
})
await tipcClient?.showContextMenu({
items: items.map((item) => {
items: nextItems.map((item) => {
if (item.type === "text") {
return {
...item,
enabled: item.enabled ?? item.click !== undefined,
click: undefined,
}
}
@@ -0,0 +1,127 @@
import { AutoResizeHeight } from "@renderer/components/ui/auto-resize-height"
import { StyledButton } from "@renderer/components/ui/button"
import { CopyButton } from "@renderer/components/ui/code-highlighter"
import { LoadingCircle } from "@renderer/components/ui/loading"
import {
Tabs,
TabsContent,
TabsList,
TabsTrigger,
} from "@renderer/components/ui/tabs"
import { useBizQuery } from "@renderer/hooks"
import { Queries } from "@renderer/queries"
import { useClaimFeedMutation } from "@renderer/queries/feed"
import { useFeedById } from "@renderer/store"
import type { FC } from "react"
export const FeedClaimModalContent: FC<{
feedId: string
}> = ({ feedId }) => {
const feed = useFeedById(feedId)
const {
data: claimMessage,
isLoading,
error,
} = useBizQuery(Queries.feed.claimMessage({ feedId }), {
enabled: !!feed,
})
const {
mutateAsync: claim,
isPending,
isSuccess,
} = useClaimFeedMutation(feedId)
if (!feed) return null
if (isLoading) {
return (
<div className="center h-32 w-[650px]">
<LoadingCircle size="large" />
</div>
)
}
if (error) {
return <div>Failed to load claim message</div>
}
return (
<div className="w-[650px] max-w-full">
<p>To claim this feed as your own, you need to verify ownership.</p>
<p>
There are three ways to choose from, you can choose one of them to
verify.
</p>
<Tabs defaultValue="content" className="mt-4">
<TabsList className="w-full justify-start">
<TabsTrigger value="content">Content</TabsTrigger>
<TabsTrigger value="description">Description</TabsTrigger>
<TabsTrigger value="rss">RSS Tag</TabsTrigger>
</TabsList>
<AutoResizeHeight duration={0.1}>
<TabsContent className="mt-0 pt-3" value="content">
<p>Copy the content below and post it to your latest RSS feed.</p>
<BaseCodeBlock>{claimMessage?.data.content || ""}</BaseCodeBlock>
</TabsContent>
<TabsContent className="pt-3" value="description">
<p>
Copy the following content and paste it into the
{" "}
<code className="text-sm">{`<description />`}</code>
{" "}
field of your
RSS feed.
</p>
<BaseCodeBlock>
{claimMessage?.data.description || ""}
</BaseCodeBlock>
</TabsContent>
<TabsContent className="mt-0 pt-3" value="rss">
<div className="space-y-3">
<p>Copy the code below and paste it into your RSS generator.</p>
<p>
RSS generators generally have two formats to choose from. Please
copy the XML and JSON formats below as needed.
</p>
<p>
<b>XML Format</b>
</p>
<BaseCodeBlock>{claimMessage?.data.xml || ""}</BaseCodeBlock>
<p>
<b>JSON Format</b>
</p>
<BaseCodeBlock>{claimMessage?.data.json || ""}</BaseCodeBlock>
</div>
</TabsContent>
</AutoResizeHeight>
</Tabs>
<div className="mt-3 flex justify-end">
<StyledButton
disabled={isSuccess}
isLoading={isPending}
onClick={() => claim()}
variant={isSuccess ? "plain" : "primary"}
>
{isSuccess && <i className="i-mgc-check-circle-filled mr-2 bg-green-500" />}
Claim
</StyledButton>
</div>
</div>
)
}
const BaseCodeBlock: FC<{
children: string
}> = ({ children }) => (
<pre className="group relative mt-3 cursor-auto select-text whitespace-pre-line break-words rounded-lg border border-border bg-zinc-100 p-2 text-sm dark:bg-neutral-800">
<code>{children}</code>
<CopyButton
value={children}
className="absolute bottom-2 right-2 z-[3] opacity-0 group-hover:opacity-100"
/>
</pre>
)
+22
View File
@@ -0,0 +1,22 @@
import { useModalStack } from "@renderer/components/ui/modal/stacked/hooks"
import { getFeedById } from "@renderer/store"
import { createElement, useCallback } from "react"
import { FeedClaimModalContent } from "./feed-claim-modal"
export const useFeedClaimModal = ({ feedId }: {
feedId: string
}) => {
const { present } = useModalStack()
return useCallback(() => {
const feed = getFeedById(feedId)
if (!feed) return
present({
title: "Feed Claim",
content: () => createElement(FeedClaimModalContent, { feedId }),
})
}, [feedId, present])
}
+2
View File
@@ -0,0 +1,2 @@
export * from "./feed-claim-modal"
export * from "./hooks"
@@ -1,4 +1,5 @@
import { getMainContainerElement } from "@renderer/atoms"
import { getUser } from "@renderer/atoms/user"
import { FeedIcon } from "@renderer/components/feed-icon"
import { useModalStack } from "@renderer/components/ui/modal/stacked/hooks"
import {
@@ -22,6 +23,7 @@ import { useMutation } from "@tanstack/react-query"
import { memo, useCallback } from "react"
import { toast } from "sonner"
import { useFeedClaimModal } from "../claim/hooks"
import { FeedForm } from "../discover/feed-form"
type FeedItemData = SubscriptionPlainModel
@@ -114,6 +116,10 @@ const FeedItemImpl = ({
const feed = useFeedById(subscription.feedId)
const claimFeed = useFeedClaimModal({
feedId: subscription.feedId,
})
if (!feed) return null
return (
<div
@@ -159,6 +165,22 @@ const FeedItemImpl = ({
{
type: "separator",
},
!feed.ownerUserId &&
!!feed.id && {
type: "text",
label: "Claim",
click: () => {
claimFeed()
},
},
feed.ownerUserId === getUser()?.id && {
type: "text",
label: "This feed is owned by you",
},
{
type: "separator",
},
{
type: "text",
label: "Open Feed in Browser",
@@ -1,3 +1,4 @@
import { useUser } from "@renderer/atoms/user"
import {
Avatar,
AvatarFallback,
@@ -8,19 +9,18 @@ import { useSignOut } from "@renderer/hooks"
import { views } from "@renderer/lib/constants"
import { cn } from "@renderer/lib/utils"
import { FeedList } from "@renderer/modules/feed-column/list"
import { useSession } from "@renderer/queries/auth"
export function Component() {
const { session } = useSession()
const user = useUser()
const signOut = useSignOut()
return (
<div className="flex w-full gap-10 px-10 py-16">
<div className="flex min-w-40 flex-1 flex-col items-center gap-8 pt-20">
<Avatar className="aspect-square size-32">
<AvatarImage src={session?.user?.image || undefined} />
<AvatarFallback>{session?.user?.name?.slice(0, 2)}</AvatarFallback>
<AvatarImage src={user?.image || undefined} />
<AvatarFallback>{user?.name?.slice(0, 2)}</AvatarFallback>
</Avatar>
<div className="text-4xl font-bold">{session?.user?.name}</div>
<div className="text-4xl font-bold">{user?.name}</div>
<div>
<StyledButton
+27 -16
View File
@@ -1,10 +1,11 @@
import { Logo } from "@renderer/components/icons/logo"
import { Vibrancy } from "@renderer/components/ui/background"
import { settingTabs } from "@renderer/lib/constants"
import { APP_NAME, settingTabs } from "@renderer/lib/constants"
import { preventDefault } from "@renderer/lib/dom"
import { SettingsTitle } from "@renderer/modules/settings/title"
import { Link, Outlet, useLocation } from "react-router-dom"
// TODO Web UI
export function Component() {
const location = useLocation()
const tab = location.pathname.replace(/^\/settings\/?/, "")
@@ -12,22 +13,32 @@ export function Component() {
return (
<div className="flex h-screen flex-col" onContextMenu={preventDefault}>
<div className="flex flex-1">
<Vibrancy className="w-44 border-r px-2.5 py-3 pt-3.5">
<div className="mb-3 flex justify-end">
<Logo className="size-6" />
</div>
{settingTabs.map((t) => (
<Link
key={t.path}
className={`my-1 flex items-center rounded-md px-2.5 py-0.5 leading-loose text-theme-foreground/70 transition-colors ${
tab === t.path ? "bg-native-active text-theme-foreground/90" : ""
<Vibrancy className="flex h-full w-44 flex-col border-r px-2.5 py-3 pt-3.5">
<div className="grow pt-8">
{settingTabs.map((t) => (
<Link
key={t.path}
className={`my-1 flex items-center rounded-md px-2.5 py-0.5 leading-loose text-theme-foreground/70 transition-colors ${
tab === t.path ?
"bg-native-active text-theme-foreground/90" :
""
}`}
to={`/settings/${t.path}`}
>
<SettingsTitle path={t.path} className="text-[15px] font-medium" />
</Link>
))}
to={`/settings/${t.path}`}
>
<SettingsTitle
path={t.path}
className="text-[15px] font-medium"
/>
</Link>
))}
</div>
<div className="center my-3 flex">
<Logo className="size-6" />
<span className="ml-2 font-semibold">
{APP_NAME}
</span>
</div>
</Vibrancy>
<div className="h-screen flex-1 overflow-y-auto bg-theme-background p-8">
<Outlet />
+5 -5
View File
@@ -1,4 +1,5 @@
import { zodResolver } from "@hookform/resolvers/zod"
import { useUser } from "@renderer/atoms/user"
import { StyledButton } from "@renderer/components/ui/button"
import {
Form,
@@ -12,7 +13,6 @@ import {
import { Input } from "@renderer/components/ui/input"
import { apiClient } from "@renderer/lib/api-fetch"
import { SettingsTitle } from "@renderer/modules/settings/title"
import { useSession } from "@renderer/queries/auth"
import { useMutation } from "@tanstack/react-query"
import { useForm } from "react-hook-form"
import { toast } from "sonner"
@@ -25,14 +25,14 @@ const formSchema = z.object({
})
export function Component() {
const { session } = useSession()
const user = useUser()
const form = useForm<z.infer<typeof formSchema>>({
resolver: zodResolver(formSchema),
defaultValues: {
handle: session?.user?.handle || "",
name: session?.user?.name || "",
avatar: session?.user?.image || "",
handle: user?.handle || "",
name: user?.name || "",
avatar: user?.image || "",
},
})
@@ -11,6 +11,7 @@ import { HelmetProvider } from "react-helmet-async"
import { BizRouterProvider } from "./biz-router-provider"
import { ContextMenuProvider } from "./context-menu-provider"
import { UserProvider } from "./user-provider"
const loadFeatures = () =>
import("../framer-lazy-feature").then((res) => res.default)
@@ -29,6 +30,7 @@ export const RootProviders: FC<PropsWithChildren> = ({ children }) => (
>
<TooltipProvider>
<Provider store={jotaiStore}>
<UserProvider />
<ModalStackProvider />
<ContextMenuProvider />
<HelmetProvider>{children}</HelmetProvider>
@@ -0,0 +1,14 @@
import { useSetUser } from "@renderer/atoms/user"
import { useSession } from "@renderer/queries/auth"
import { useEffect } from "react"
export const UserProvider = () => {
const { session } = useSession()
const setUser = useSetUser()
useEffect(() => {
if (!session?.user) return
setUser(session.user)
}, [session?.user, setUser])
return null
}
+1 -1
View File
@@ -41,7 +41,7 @@ export const useSession = () => {
/**
* Fetch session data, copy and patch code from @hono/auth-js/react
*/
export async function fetchData<T = any>(
async function fetchData<T = any>(
path: string,
req: any = {},
+38 -21
View File
@@ -1,15 +1,13 @@
import { getUser } from "@renderer/atoms/user"
import { useBizQuery } from "@renderer/hooks"
import { apiClient } from "@renderer/lib/api-fetch"
import { apiClient, getFetchErrorMessage } from "@renderer/lib/api-fetch"
import { defineQuery } from "@renderer/lib/defineQuery"
import { feedActions } from "@renderer/store"
import { useMutation } from "@tanstack/react-query"
import { toast } from "sonner"
export const feed = {
byId: ({
id,
url,
}: {
id?: string
url?: string
}) =>
byId: ({ id, url }: { id?: string, url?: string }) =>
defineQuery(
["feed", id, url],
async () => {
@@ -26,18 +24,37 @@ export const feed = {
rootKey: ["feed"],
},
),
claimMessage: ({ feedId }: { feedId: string }) =>
defineQuery(["feed", "claimMessage", feedId], async () =>
apiClient.feeds.claim.message.$get({ query: { feedId } })),
}
export const useFeed = ({
id,
url,
}: {
id?: string
url?: string
}) =>
useBizQuery(feed.byId({
id,
url,
}), {
enabled: !!id || !!url,
})
export const useFeed = ({ id, url }: { id?: string, url?: string }) =>
useBizQuery(
feed.byId({
id,
url,
}),
{
enabled: !!id || !!url,
},
)
export const useClaimFeedMutation = (feedId: string) => useMutation({
mutationKey: ["claimFeed", feedId],
mutationFn: () =>
apiClient.feeds.claim.challenge.$post({
json: {
feedId,
},
}),
async onError(err) {
toast.error(await getFetchErrorMessage(err))
},
onSuccess() {
feedActions.patch(feedId, {
ownerUserId: getUser()?.id,
})
},
})
+16 -2
View File
@@ -18,7 +18,9 @@ export const useFeedStore = createZustandStore<FeedState & FeedActions>(
set((state) =>
produce(state, (state) => {
for (const feed of feeds) {
if (feed.id) { state.feeds[feed.id] = feed }
if (feed.id) {
state.feeds[feed.id] = feed
}
}
}),
)
@@ -34,7 +36,19 @@ export const useFeedStore = createZustandStore<FeedState & FeedActions>(
}),
)
},
patch(feedId, patch) {
set((state) =>
produce(state, (state) => {
const feed = state.feeds[feedId]
if (!feed) return
Object.assign(feed, patch)
}),
)
},
}))
export const feedActions = getStoreActions(useFeedStore)
export const getFeedById = (feedId: string): Nullable<FeedModel> => useFeedStore.getState().feeds[feedId]
export const getFeedById = (feedId: string): Nullable<FeedModel> =>
useFeedStore.getState().feeds[feedId]
+1
View File
@@ -10,4 +10,5 @@ export interface FeedActions {
upsertMany: (feeds: FeedModel[]) => void
optimisticUpdate: (feedId: FeedId, changed: Partial<FeedModel>) => void
clear: () => void
patch: (feedId: FeedId, patch: Partial<FeedModel>) => void
}