Skip to content

Commit 1a2190c

Browse files
committed
fix: add feed when site url not match
Signed-off-by: Innei <i@innei.in>
1 parent b4f9b1b commit 1a2190c

File tree

4 files changed

+39
-19
lines changed

4 files changed

+39
-19
lines changed

src/renderer/src/components/ui/divider/Divider.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const DividerVertical: FC<
2020
return (
2121
<span
2222
className={cn(
23-
"mx-4 inline-block h-full w-[0.5px] select-none bg-black !bg-opacity-30 text-transparent dark:bg-white",
23+
"mx-4 inline-block h-full w-[0.5px] select-none bg-black text-transparent !opacity-20 dark:bg-white",
2424
className,
2525
)}
2626
{...rest}

src/renderer/src/modules/discover/feed-form.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,15 @@ export const FeedForm: Component<{
5454
asWidget?: boolean
5555

5656
onSuccess?: () => void
57-
}> = ({ id, defaultValues = defaultValue, url, asWidget, onSuccess }) => {
58-
const queryParams = { id, url }
57+
}> = ({ id: _id, defaultValues = defaultValue, url, asWidget, onSuccess }) => {
58+
const queryParams = { id: _id, url }
5959
const feedQuery = useFeed(queryParams)
6060

61-
const feed = useFeedByIdOrUrl(queryParams)
61+
const id = feedQuery.data?.feed.id || _id
62+
const feed = useFeedByIdOrUrl({
63+
id,
64+
url,
65+
})
6266

6367
const hasSub = useSubscriptionByFeedId(feed?.id || "")
6468
const isSubscribed = !!feedQuery.data?.subscription || hasSub

src/renderer/src/modules/discover/form.tsx

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,31 +31,34 @@ const info: Record<
3131
string,
3232
{
3333
label: string
34-
prefix?: string
34+
prefix?: string[]
3535
showModal?: boolean
36+
default?: string
3637
}
3738
> = {
3839
search: {
3940
label: "Any URL or Keyword",
4041
},
4142
rss: {
4243
label: "RSS URL",
43-
prefix: "https://",
44+
default: "https://",
45+
prefix: ["https://", "http://"],
4446
showModal: true,
4547
},
4648
rsshub: {
4749
label: "RSSHub Route",
48-
prefix: "rsshub://",
50+
prefix: ["rsshub://"],
51+
default: "rsshub://",
4952
showModal: true,
5053
},
5154
}
5255

5356
export function DiscoverForm({ type }: { type: string }) {
54-
const { prefix } = info[type]
57+
const { prefix, default: defaultValue } = info[type]
5558
const form = useForm<z.infer<typeof formSchema>>({
5659
resolver: zodResolver(formSchema),
5760
defaultValues: {
58-
keyword: prefix || "",
61+
keyword: defaultValue || "",
5962
},
6063
})
6164
const mutation = useMutation({
@@ -95,14 +98,18 @@ export function DiscoverForm({ type }: { type: string }) {
9598

9699
const keyword = form.watch("keyword")
97100
useEffect(() => {
98-
if (prefix) {
99-
if (!keyword.startsWith(prefix)) {
100-
form.setValue("keyword", prefix)
101-
} else if (keyword.startsWith(`${prefix}${prefix}`)) {
102-
form.setValue("keyword", keyword.slice(prefix.length))
103-
}
101+
if (!prefix) return
102+
const isValidPrefix = prefix.find((p) => keyword.startsWith(p))
103+
if (!isValidPrefix) {
104+
form.setValue("keyword", prefix[0])
105+
106+
return
107+
}
108+
109+
if (keyword.startsWith(`${isValidPrefix}${isValidPrefix}`)) {
110+
form.setValue("keyword", keyword.slice(isValidPrefix.length))
104111
}
105-
}, [keyword])
112+
}, [form, keyword, prefix])
106113

107114
return (
108115
<>

src/renderer/src/store/feed/store.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,18 @@ class FeedActions {
9292
},
9393
})
9494

95-
this.upsertMany([res.data.feed])
96-
97-
return res.data
95+
const nonce = nanoid(8)
96+
97+
const finalData = {
98+
...res.data.feed,
99+
id: id || res.data.feed.id || nonce,
100+
}
101+
this.upsertMany([finalData])
102+
103+
return {
104+
...res.data,
105+
feed: finalData,
106+
}
98107
}
99108
}
100109
export const feedActions = new FeedActions()

0 commit comments

Comments
 (0)