@@ -6,7 +6,7 @@ import { useTranslation } from "react-i18next"
|
||||
import { whoami } from "~/atoms/user"
|
||||
import { useModalStack } from "~/components/ui/modal"
|
||||
import type { FeedViewType } from "~/lib/enum"
|
||||
import type { NativeMenuItem } from "~/lib/native-menu"
|
||||
import type { NativeMenuItem, NullableNativeMenuItem } from "~/lib/native-menu"
|
||||
import { useFeedClaimModal } from "~/modules/claim"
|
||||
import { FeedForm } from "~/modules/discover/feed-form"
|
||||
import { InboxForm } from "~/modules/discover/inbox-form"
|
||||
@@ -47,8 +47,8 @@ export const useFeedActions = ({
|
||||
const navigateEntry = useNavigateEntry()
|
||||
const isEntryList = type === "entryList"
|
||||
|
||||
const addMutation = useAddFeedToFeedList()
|
||||
const removeMutation = useRemoveFeedFromFeedList()
|
||||
const { mutateAsync: addFeedToListMutation } = useAddFeedToFeedList()
|
||||
const { mutateAsync: removeFeedFromListMutation } = useRemoveFeedFromFeedList()
|
||||
|
||||
const listByView = useListByView(view!)
|
||||
|
||||
@@ -101,12 +101,12 @@ export const useFeedActions = ({
|
||||
checked: isIncluded,
|
||||
click() {
|
||||
if (!isIncluded) {
|
||||
addMutation.mutate({
|
||||
addFeedToListMutation({
|
||||
feedId,
|
||||
listId: list.id,
|
||||
})
|
||||
} else {
|
||||
removeMutation.mutate({
|
||||
removeFeedFromListMutation({
|
||||
feedId,
|
||||
listId: list.id,
|
||||
})
|
||||
@@ -209,7 +209,8 @@ export const useFeedActions = ({
|
||||
listByView,
|
||||
feedId,
|
||||
claimFeed,
|
||||
addMutation,
|
||||
addFeedToListMutation,
|
||||
removeFeedFromListMutation,
|
||||
present,
|
||||
deleteSubscription,
|
||||
subscription,
|
||||
@@ -226,25 +227,21 @@ export const useListActions = ({ listId, view }: { listId: string; view: FeedVie
|
||||
const subscription = useSubscriptionByFeedId(listId)
|
||||
|
||||
const { present } = useModalStack()
|
||||
const deleteSubscription = useDeleteSubscription({})
|
||||
const { mutateAsync: deleteSubscription } = useDeleteSubscription({})
|
||||
|
||||
const navigateEntry = useNavigateEntry()
|
||||
|
||||
const items = useMemo(() => {
|
||||
if (!list) return []
|
||||
|
||||
const items: NativeMenuItem[] = [
|
||||
...(list.ownerUserId === whoami()?.id
|
||||
? [
|
||||
{
|
||||
type: "text" as const,
|
||||
label: t("sidebar.feed_actions.list_owned_by_you"),
|
||||
},
|
||||
]
|
||||
: []),
|
||||
const items: NullableNativeMenuItem[] = [
|
||||
list.ownerUserId === whoami()?.id && {
|
||||
type: "text" as const,
|
||||
label: t("sidebar.feed_actions.list_owned_by_you"),
|
||||
},
|
||||
{
|
||||
type: "separator" as const,
|
||||
disabled: false,
|
||||
hide: list.ownerUserId !== whoami()?.id,
|
||||
},
|
||||
|
||||
{
|
||||
@@ -262,7 +259,7 @@ export const useListActions = ({ listId, view }: { listId: string; view: FeedVie
|
||||
type: "text" as const,
|
||||
label: t("sidebar.feed_actions.unfollow"),
|
||||
shortcut: "Meta+Backspace",
|
||||
click: () => deleteSubscription.mutate(subscription),
|
||||
click: () => deleteSubscription(subscription),
|
||||
},
|
||||
{
|
||||
type: "text" as const,
|
||||
|
||||
@@ -3,7 +3,7 @@ import { get } from "lodash-es"
|
||||
import { tipcClient } from "./client"
|
||||
import { getOS } from "./utils"
|
||||
|
||||
export type NativeMenuItem =
|
||||
export type NativeMenuItem = (
|
||||
| {
|
||||
type: "text"
|
||||
label: string
|
||||
@@ -17,6 +17,9 @@ export type NativeMenuItem =
|
||||
checked?: boolean
|
||||
}
|
||||
| { type: "separator"; disabled?: boolean }
|
||||
) & { hide?: boolean }
|
||||
|
||||
export type NullableNativeMenuItem = NativeMenuItem | null | undefined | false | ""
|
||||
|
||||
function sortShortcutsString(shortcut: string) {
|
||||
const order = ["Shift", "Ctrl", "Alt", "Meta"]
|
||||
@@ -32,7 +35,7 @@ function sortShortcutsString(shortcut: string) {
|
||||
return [...sortedModifiers, ...otherKeys].join("+")
|
||||
}
|
||||
export const showNativeMenu = async (
|
||||
items: Array<Nullable<NativeMenuItem | false>>,
|
||||
items: Array<NullableNativeMenuItem>,
|
||||
e?: MouseEvent | React.MouseEvent,
|
||||
) => {
|
||||
const nextItems = (items.filter(Boolean) as NativeMenuItem[]).map((item) => {
|
||||
@@ -42,6 +45,10 @@ export const showNativeMenu = async (
|
||||
shortcut: item.shortcut ? sortShortcutsString(item.shortcut) : undefined,
|
||||
}
|
||||
}
|
||||
|
||||
if (item.hide) {
|
||||
return []
|
||||
}
|
||||
return item
|
||||
}) as NativeMenuItem[]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user