Skip to content

Commit

Permalink
Add favorite DVM feeds
Browse files Browse the repository at this point in the history
  • Loading branch information
hzrd149 committed Nov 28, 2024
1 parent c105c66 commit 820d8ab
Show file tree
Hide file tree
Showing 19 changed files with 158 additions and 202 deletions.
5 changes: 5 additions & 0 deletions .changeset/twelve-plums-yell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"nostrudel": minor
---

Add favorite DVM feeds
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"applesauce-channel": "next",
"applesauce-content": "next",
"applesauce-core": "next",
"applesauce-lists": "next",
"applesauce-lists": "0.0.0-next-20241127180935",
"applesauce-net": "next",
"applesauce-react": "next",
"applesauce-signer": "next",
Expand Down
157 changes: 8 additions & 149 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 52 additions & 0 deletions src/components/dvm/dvm-feed-favorite-button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { useState } from "react";
import { IconButton, IconButtonProps } from "@chakra-ui/react";
import { kinds } from "nostr-tools";
import { modifyEventTags, unixNow } from "applesauce-core/helpers";
import { AddressPointer } from "nostr-tools/nip19";
import { Operations, isAddressPointerInList } from "applesauce-lists/helpers";

import useFavoriteFeeds, { FAVORITE_FEEDS_IDENTIFIER } from "../../hooks/use-favorite-feeds";
import { usePublishEvent } from "../../providers/global/publish-provider";
import { StarEmptyIcon, StarFullIcon } from "../icons";
import { useSigningContext } from "../../providers/global/signing-provider";
import useAsyncErrorHandler from "../../hooks/use-async-error-handler";

export default function DVMFeedFavoriteButton({
pointer,
...props
}: { pointer: AddressPointer } & Omit<IconButtonProps, "children" | "aria-label" | "isLoading" | "onClick">) {
const publish = usePublishEvent();
const { finalizeDraft } = useSigningContext();
const { favorites } = useFavoriteFeeds();
const isFavorite = !!favorites && isAddressPointerInList(favorites, pointer);
const [loading, setLoading] = useState(false);

const handleClick = useAsyncErrorHandler(async () => {
const prev =
favorites ||
(await finalizeDraft({
kind: kinds.Application,
created_at: unixNow(),
content: "",
tags: [["d", FAVORITE_FEEDS_IDENTIFIER]],
}));

setLoading(true);
const draft = await modifyEventTags(prev, {
public: isFavorite ? Operations.removeCoordinateTag(pointer) : Operations.addCoordinateTag(pointer),
});
await publish(isFavorite ? "Unfavorite feed" : "Favorite feed", draft);
setLoading(false);
}, [finalizeDraft, favorites, pointer, publish, setLoading]);

return (
<IconButton
icon={isFavorite ? <StarFullIcon /> : <StarEmptyIcon />}
aria-label={isFavorite ? "Favorite feed" : "Unfavorite feed"}
onClick={handleClick}
isLoading={loading}
color={isFavorite ? "yellow.400" : undefined}
{...props}
/>
);
}
3 changes: 2 additions & 1 deletion src/components/note/bookmark-event.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import {
useDisclosure,
} from "@chakra-ui/react";
import { kinds } from "nostr-tools";
import { getEventPointersFromList } from "applesauce-lists/helpers";

import useCurrentAccount from "../../hooks/use-current-account";
import useUserSets from "../../hooks/use-user-lists";
import { listAddEvent, listRemoveEvent, getEventPointersFromList, getListName } from "../../helpers/nostr/lists";
import { listAddEvent, listRemoveEvent, getListName } from "../../helpers/nostr/lists";
import { NostrEvent } from "../../types/nostr-event";
import { getEventCoordinate } from "../../helpers/nostr/event";
import { BookmarkIcon, BookmarkedIcon, PlusCircleIcon } from "../icons";
Expand Down
4 changes: 2 additions & 2 deletions src/components/user/user-follow-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
useDisclosure,
} from "@chakra-ui/react";
import { kinds } from "nostr-tools";
import { isProfilePointerInList } from "applesauce-lists/helpers";

import useCurrentAccount from "../../hooks/use-current-account";
import { ChevronDownIcon, FollowIcon, MuteIcon, PlusCircleIcon, UnfollowIcon, UnmuteIcon } from "../icons";
Expand All @@ -22,7 +23,6 @@ import {
listRemovePerson,
getListName,
getPubkeysFromList,
isPubkeyInList,
} from "../../helpers/nostr/lists";
import { getEventCoordinate } from "../../helpers/nostr/event";
import { useSigningContext } from "../../providers/global/signing-provider";
Expand Down Expand Up @@ -111,7 +111,7 @@ export function UserFollowButton({ pubkey, showLists, ...props }: UserFollowButt
const { isMuted, unmute } = useUserMuteActions(pubkey);
const { openModal } = useMuteModalContext();

const isFollowing = isPubkeyInList(contacts, pubkey);
const isFollowing = !!contacts && isProfilePointerInList(contacts, pubkey);
const isDisabled = account?.readonly ?? true;

const [loading, setLoading] = useState(false);
Expand Down
Loading

0 comments on commit 820d8ab

Please sign in to comment.