Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: unified modal style #63

Merged
merged 6 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: remove modal
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed Jun 14, 2024
commit 0e78ff6f6ca8d24492956fe1ec4122ea3b264ff1
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
}
},

"tailwindCSS.experimental.classRegex": [
["cva\\(([^)]*)\\)", "[\"'`]([^\"'`]*).*?[\"'`]"],
["cx\\(([^)]*)\\)", "(?:'|\"|`)([^']*)(?:'|\"|`)"]
],
// You may don't need this in the future
"eslint.experimental.useFlatConfig": true,
"eslint.validate": [
Expand Down
65 changes: 29 additions & 36 deletions src/renderer/src/components/feed-column/category-remove-dialog.tsx
Original file line number Diff line number Diff line change
@@ -1,63 +1,56 @@
import {
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
} from "@renderer/components/ui/alert-dialog"
import { apiClient } from "@renderer/lib/api-fetch"
import { Queries } from "@renderer/queries"
import { subscriptionActions } from "@renderer/store"
import { useMutation } from "@tanstack/react-query"

export function CategoryRemoveDialog({
import { StyledButton } from "../ui/button"
import { useCurrentModal } from "../ui/modal"

export function CategoryRemoveDialogContent({
feedIdList,
onSuccess,
category,

view,
}: {
feedIdList: string[]
onSuccess?: () => void
category: string

view?: number
}) {
const renameMutation = useMutation({
const deleteMutation = useMutation({
mutationFn: async () =>

apiClient.categories.$delete({
json: {
feedIdList,
deleteSubscriptions: false,
},
}),

onSuccess: () => {
Queries.subscription.byView(view).invalidate()

onSuccess?.()
subscriptionActions.deleteCategory(feedIdList)
},
})

const { dismiss } = useCurrentModal()

return (
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>
Remove category
{" "}
<span className="font-bold">{category}</span>
?
</AlertDialogTitle>
<AlertDialogDescription>
This operation will delete your category, but the feeds it contains
will be retained and grouped by website.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction onClick={() => renameMutation.mutate()}>
<div className="flex w-[65ch] max-w-full flex-col gap-4">
<p>
This operation will delete your category, but the feeds it contains will
be retained and grouped by website.
</p>

<div className="flex items-center justify-end gap-3">
<StyledButton variant="plain" onClick={dismiss}>
Cancel
</StyledButton>
<StyledButton
isLoading={deleteMutation.isPending}
onClick={() => deleteMutation.mutateAsync().then(() => dismiss())}
>
Continue
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</StyledButton>
</div>
</div>
)
}
53 changes: 22 additions & 31 deletions src/renderer/src/components/feed-column/category-rename-dialog.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { zodResolver } from "@hookform/resolvers/zod"
import { Button } from "@renderer/components/ui/button"
import {
DialogContent,
DialogHeader,
DialogTitle,
} from "@renderer/components/ui/dialog"
import { StyledButton } from "@renderer/components/ui/button"
import {
Form,
FormControl,
Expand All @@ -23,7 +18,7 @@ const formSchema = z.object({
category: z.string(),
})

export function CategoryRenameDialog({
export function CategoryRenameContent({
feedIdList,
onSuccess,
category,
Expand All @@ -43,7 +38,6 @@ export function CategoryRenameDialog({

const renameMutation = useMutation({
mutationFn: async (values: z.infer<typeof formSchema>) =>

apiClient.categories.$patch({
json: {
feedIdList,
Expand All @@ -62,29 +56,26 @@ export function CategoryRenameDialog({
}

return (
<DialogContent>
<DialogHeader>
<DialogTitle>Rename Category</DialogTitle>
</DialogHeader>
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
<FormField
control={form.control}
name="category"
render={({ field }) => (
<FormItem>
<FormControl>
<Input {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<Button type="submit" isLoading={renameMutation.isPending}>
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
<FormField
control={form.control}
name="category"
render={({ field }) => (
<FormItem>
<FormControl>
<Input {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<div className="flex justify-end">
<StyledButton type="submit" isLoading={renameMutation.isPending}>
Rename
</Button>
</form>
</Form>
</DialogContent>
</StyledButton>
</div>
</form>
</Form>
)
}
156 changes: 72 additions & 84 deletions src/renderer/src/components/feed-column/category.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,23 @@ import {
Collapsible,
CollapsibleTrigger,
} from "@renderer/components/ui/collapsible"
import { Dialog } from "@renderer/components/ui/dialog"
import { apiClient } from "@renderer/lib/api-fetch"
import { client } from "@renderer/lib/client"
import { levels } from "@renderer/lib/constants"
import { showNativeMenu } from "@renderer/lib/native-menu"
import { cn } from "@renderer/lib/utils"
import type { FeedListModel } from "@renderer/models"
import { Queries } from "@renderer/queries"
import {
feedActions,
useFeedActiveList,
useUnreadStore,
} from "@renderer/store"
import { useMutation } from "@tanstack/react-query"
import { AnimatePresence, m } from "framer-motion"
import { useEffect, useState } from "react"

import { CategoryRenameDialog } from "./category-rename-dialog"
import { useModalStack } from "../ui/modal/stacked/hooks"
import { CategoryRemoveDialogContent } from "./category-remove-dialog"
import {
CategoryRenameContent,
} from "./category-rename-dialog"
import { FeedItem } from "./item"

const { setActiveList } = feedActions
Expand All @@ -36,22 +35,8 @@ export function FeedCategory({
const activeList = useFeedActiveList()

const [open, setOpen] = useState(!data.name)
const [dialogOpen, setDialogOpen] = useState(false)

const feedIdList = data.list.map((feed) => feed.feedId)
const deleteMutation = useMutation({
mutationFn: async () =>
apiClient.categories.$delete({
json: {
feedIdList,
deleteSubscriptions: false,
},
}),

onSuccess: () => {
Queries.subscription.byView(view).invalidate()
},
})

useEffect(() => {
if (data.name) {
Expand All @@ -74,81 +59,84 @@ export function FeedCategory({
data.list.reduce((acc, cur) => (state.data[cur.feedId] || 0) + acc, 0),
)

const sortByUnreadFeedList = useUnreadStore((state) => data.list.sort((a, b) => (state.data[b.feedId] || 0) - (state.data[a.feedId] || 0)))
const sortByUnreadFeedList = useUnreadStore((state) =>
data.list.sort(
(a, b) => (state.data[b.feedId] || 0) - (state.data[a.feedId] || 0),
),
)
const { present } = useModalStack()
return (
<Collapsible
open={open}
onOpenChange={(o) => setOpen(o)}
onClick={(e) => e.stopPropagation()}
>
{!!data.name && (
<Dialog open={dialogOpen} onOpenChange={setDialogOpen}>
<div
className={cn(
"flex w-full items-center justify-between rounded-md px-2.5 transition-colors",
activeList?.level === levels.folder &&
activeList.name === data.name &&
"bg-native-active",
)}
onClick={(e) => {
e.stopPropagation()
setCategoryActive()
}}
onContextMenu={(e) => {
showNativeMenu(
[
{
type: "text",
label: "Rename Category",
click: () => setDialogOpen(true),
<div
className={cn(
"flex w-full items-center justify-between rounded-md px-2.5 transition-colors",
activeList?.level === levels.folder &&
activeList.name === data.name &&
"bg-native-active",
)}
onClick={(e) => {
e.stopPropagation()
setCategoryActive()
}}
onContextMenu={(e) => {
showNativeMenu(
[
{
type: "text",
label: "Rename Category",
click: () => {
present({
title: "Rename Category",
content: ({ dismiss }) => (
<CategoryRenameContent
feedIdList={feedIdList}
category={data.name}
view={view}
onSuccess={dismiss}
/>
),
})
},
{
type: "text",
label: "Delete Category",
},
{
type: "text",
label: "Delete Category",

click: async () => {
const result = await client?.showConfirmDialog({
title: `Delete category ${data.name}?`,
message: `This operation will delete your category, but the feeds it contains will be retained and grouped by website.`,
options: {
buttons: ["Delete", "Cancel"],
},
})
if (result) {
deleteMutation.mutate()
}
},
click: async () => {
present({
title: `Delete category ${data.name}?`,
content: () => (
<CategoryRemoveDialogContent feedIdList={feedIdList} />
),
})
},
],
e,
)
}}
>
<div className="flex w-full min-w-0 items-center">
<CollapsibleTrigger
className={cn(
"flex h-8 items-center [&_.i-mingcute-right-fill]:data-[state=open]:rotate-90",
!setActiveList && "flex-1",
)}
>
<i className="i-mingcute-right-fill mr-2 transition-transform" />
{!setActiveList && (
<span className="truncate">{data.name}</span>
)}
</CollapsibleTrigger>
{!!setActiveList && <span className="truncate">{data.name}</span>}
</div>
{!!unread && (
<div className="ml-2 text-xs text-zinc-500">{unread}</div>
)}
<CategoryRenameDialog
feedIdList={feedIdList}
view={view}
category={data.name}
onSuccess={() => setDialogOpen(false)}
/>
},
],
e,
)
}}
>
<div className="flex w-full min-w-0 items-center">
<CollapsibleTrigger
className={cn(
"flex h-8 items-center [&_.i-mingcute-right-fill]:data-[state=open]:rotate-90",
!setActiveList && "flex-1",
)}
>
<i className="i-mingcute-right-fill mr-2 transition-transform" />
{!setActiveList && <span className="truncate">{data.name}</span>}
</CollapsibleTrigger>
{!!setActiveList && <span className="truncate">{data.name}</span>}
</div>
</Dialog>
{!!unread && (
<div className="ml-2 text-xs text-zinc-500">{unread}</div>
)}
</div>
)}
<AnimatePresence>
{open && (
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/src/components/feed-column/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ const useData = (view: FeedViewType) => {
for (const subscription of subscriptions) {
if (!subscription.category) {
if (subscription.feeds.siteUrl) {
// FIXME @DIYgod
// The logic here makes it impossible to remove the auto-generated category based on domain
const { domain } = parse(subscription.feeds.siteUrl)
if (domain && domains[domain] > 1) {
subscription.category =
Expand Down
Loading