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

Fix: follow & like & comment issues #246

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion JoyboyCommunity/src/hooks/nostr/useContacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const useContacts = (options?: UseContactsOptions) => {
const {ndk} = useNostrContext();

return useQuery({
queryKey: ['contacts', ndk, options?.authors, options?.search],
queryKey: ['contacts', options?.authors, options?.search, ndk],
queryFn: async () => {
const contacts = await ndk.fetchEvent({
kinds: [NDKKind.Contacts],
Expand Down
5 changes: 5 additions & 0 deletions JoyboyCommunity/src/hooks/nostr/useEditContacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,17 @@ export const useEditContacts = () => {
contacts.tags = [];
}

// Resetting the id and created_at to avoid conflicts
contacts.id = undefined as any;
contacts.created_at = undefined;

if (data.type === 'add') {
contacts.tags.push(['p', data.pubkey, '', '']);
} else {
contacts.tags = contacts.tags.filter((tag) => tag[1] !== data.pubkey);
}

await contacts.sign();
return contacts.publish();
},
});
Expand Down
2 changes: 1 addition & 1 deletion JoyboyCommunity/src/hooks/nostr/useNote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const useNote = (options: UseNoteOptions) => {
const {ndk} = useNostrContext();

return useQuery({
queryKey: ['note', ndk, options.noteId],
queryKey: ['note', options.noteId, ndk],
queryFn: async () => {
const note = await ndk.fetchEvent({
kinds: [NDKKind.Text],
Expand Down
2 changes: 1 addition & 1 deletion JoyboyCommunity/src/hooks/nostr/useProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const useProfile = (options: UseProfileOptions) => {
const {ndk} = useNostrContext();

return useQuery({
queryKey: ['profile', ndk, options.publicKey],
queryKey: ['profile', options.publicKey, ndk],
queryFn: async () => {
const user = ndk.getUser({pubkey: options.publicKey});

Expand Down
2 changes: 1 addition & 1 deletion JoyboyCommunity/src/hooks/nostr/useReactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const useReactions = (options?: UseReactionsOptions) => {
const {ndk} = useNostrContext();

return useQuery({
queryKey: ['reactions', ndk, options?.noteId, options?.authors, options?.search],
queryKey: ['reactions', options?.noteId, options?.authors, options?.search, ndk],
queryFn: async () => {
const notes = await ndk.fetchEvents({
kinds: [NDKKind.Reaction],
Expand Down
2 changes: 1 addition & 1 deletion JoyboyCommunity/src/hooks/nostr/useReplyNotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const useReplyNotes = (options?: UseReplyNotesOptions) => {

return useInfiniteQuery({
initialPageParam: 0,
queryKey: ['replyNotes', ndk, options?.noteId, options?.authors, options?.search],
queryKey: ['replyNotes', options?.noteId, options?.authors, options?.search, ndk],
getNextPageParam: (lastPage: any, allPages, lastPageParam) => {
if (!lastPage?.length) return undefined;

Expand Down
2 changes: 1 addition & 1 deletion JoyboyCommunity/src/hooks/nostr/useReposts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const useReposts = (options?: UseRepostsOptions) => {

return useInfiniteQuery({
initialPageParam: 0,
queryKey: ['reposts', ndk, options?.authors, options?.search],
queryKey: ['reposts', options?.authors, options?.search, ndk],
getNextPageParam: (lastPage: any, allPages, lastPageParam) => {
if (!lastPage?.length) return undefined;

Expand Down
2 changes: 1 addition & 1 deletion JoyboyCommunity/src/hooks/nostr/useRootNotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const useRootNotes = (options?: UseRootNotesOptions) => {

return useInfiniteQuery({
initialPageParam: 0,
queryKey: ['rootNotes', ndk, options?.authors, options?.search],
queryKey: ['rootNotes', options?.authors, options?.search, ndk],
getNextPageParam: (lastPage: any, allPages, lastPageParam) => {
if (!lastPage?.length) return undefined;

Expand Down
12 changes: 9 additions & 3 deletions JoyboyCommunity/src/screens/Profile/Info/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {Pressable, View} from 'react-native';
import {UserPlusIcon} from '../../../assets/icons';
import {Button, IconButton, Menu, Text} from '../../../components';
import {useContacts, useEditContacts, useProfile, useStyles, useTheme} from '../../../hooks';
import {useToast} from '../../../hooks/modals';
import {useAuth} from '../../../store/auth';
import {ProfileScreenProps} from '../../../types';
import {ProfileHead} from '../Head';
Expand All @@ -26,6 +27,7 @@ export const ProfileInfo: React.FC<ProfileInfoProps> = ({publicKey: userPublicKe
const [menuOpen, setMenuOpen] = useState(false);
const publicKey = useAuth((state) => state.publicKey);

const {showToast} = useToast();
const queryClient = useQueryClient();
const userContacts = useContacts({authors: [userPublicKey]});
const contacts = useContacts({authors: [publicKey]});
Expand All @@ -40,12 +42,16 @@ export const ProfileInfo: React.FC<ProfileInfoProps> = ({publicKey: userPublicKe

const onConnectionPress = () => {
editContacts.mutateAsync(
{pubkey: publicKey, type: isConnected ? 'remove' : 'add'},
{pubkey: userPublicKey, type: isConnected ? 'remove' : 'add'},
{
onSuccess: () => {
queryClient.invalidateQueries({queryKey: ['contacts']});
userContacts.refetch();
contacts.refetch();
},
onError: () => {
showToast({
type: 'error',
title: isConnected ? 'Failed to unfollow user' : 'Failed to follow user',
});
},
},
);
Expand Down
Loading