-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added group naming from network level Removed local handling
- Loading branch information
Alex Risch
authored and
Alex Risch
committed
May 31, 2024
1 parent
41fadbf
commit c0ba37d
Showing
11 changed files
with
75 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,14 @@ | ||
import {useMemo} from 'react'; | ||
import {mmkvStorage} from '../services/mmkvStorage'; | ||
import {formatAddress} from '../utils/formatAddress'; | ||
import {useClient} from './useClient'; | ||
import {useGroupNameMutation} from '../mutations/useGroupNameMutation'; | ||
import {useGroupNameQuery} from '../queries/useGroupNameQuery'; | ||
|
||
export const useGroupName = (addresses: string[], groupId: string) => { | ||
const {client} = useClient(); | ||
const data = useMemo(() => { | ||
const groupDisplayName = addresses.map(formatAddress).join(', '); | ||
return groupDisplayName; | ||
}, [addresses]); | ||
const savedGroupName = mmkvStorage.getGroupName( | ||
client?.address ?? '', | ||
groupId, | ||
); | ||
return savedGroupName ?? data; | ||
export const useGroupName = (groupTopic: string) => { | ||
const {data: groupName} = useGroupNameQuery(groupTopic ?? ''); | ||
const {mutateAsync} = useGroupNameMutation(groupTopic ?? ''); | ||
|
||
return { | ||
groupName, | ||
updateGroupName: async (newGroupName: string) => { | ||
await mutateAsync(newGroupName); | ||
}, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const MutationKeys = { | ||
GroupName: 'GroupName', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import {useMutation} from '@tanstack/react-query'; | ||
import {useGroup} from '../hooks/useGroup'; | ||
import {QueryKeys} from '../queries/QueryKeys'; | ||
import {queryClient} from '../services/queryClient'; | ||
import {MutationKeys} from './MutationKeys'; | ||
|
||
export interface GroupNameQueryOptions { | ||
limit?: number; | ||
} | ||
|
||
export const useGroupNameMutation = (topic: string) => { | ||
const {data: group} = useGroup(topic); | ||
|
||
return useMutation({ | ||
mutationKey: [MutationKeys.GroupName, topic], | ||
mutationFn: async (newGroupName: string) => { | ||
return group?.updateGroupName(newGroupName); | ||
}, | ||
onSuccess: (_, newGroupName) => { | ||
queryClient.setQueryData([QueryKeys.GroupName, topic], newGroupName); | ||
}, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import {useQuery} from '@tanstack/react-query'; | ||
import {useGroup} from '../hooks/useGroup'; | ||
import {QueryKeys} from './QueryKeys'; | ||
|
||
export interface GroupNameQueryOptions { | ||
limit?: number; | ||
} | ||
|
||
export const useGroupNameQuery = (topic: string) => { | ||
const {data: group} = useGroup(topic); | ||
|
||
return useQuery<string | undefined, unknown>({ | ||
queryKey: [QueryKeys.GroupName, topic], | ||
queryFn: async () => { | ||
if (!group) { | ||
return undefined; | ||
} | ||
return group.groupName(); | ||
}, | ||
enabled: !!group, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters