frontend client for gemstone. decentralised workplace app
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: shard registration

serenity 0e7d5ba2 dd022caf

+53 -27
+53 -27
src/components/Settings/RegisterShardModalContent.tsx
··· 1 + import { Loading } from "@/components/primitives/Loading"; 1 2 import { Text } from "@/components/primitives/Text"; 2 3 import { useFacet } from "@/lib/facet"; 3 4 import { registerNewShard } from "@/lib/utils/gmstn"; 4 - import { useOAuthAgentGuaranteed } from "@/providers/OAuthProvider"; 5 + import { 6 + useOAuthAgentGuaranteed, 7 + useOAuthSessionGuaranteed, 8 + } from "@/providers/OAuthProvider"; 5 9 import { useCurrentPalette } from "@/providers/ThemeProvider"; 6 - import type { Dispatch, SetStateAction} from "react"; 10 + import { useMutation, useQueryClient } from "@tanstack/react-query"; 11 + import type { Dispatch, SetStateAction } from "react"; 7 12 import { useState } from "react"; 8 13 import { Pressable, TextInput, View } from "react-native"; 9 14 ··· 19 24 undefined, 20 25 ); 21 26 const agent = useOAuthAgentGuaranteed(); 22 - const handleSubmit = async () => { 23 - const registerResult = await registerNewShard({ 24 - shardDomain: inputText, 25 - agent, 27 + const session = useOAuthSessionGuaranteed(); 28 + const queryClient = useQueryClient(); 29 + const { mutate: newShardMutation, isPending: mutationPending } = 30 + useMutation({ 31 + mutationFn: async () => { 32 + const registerResult = await registerNewShard({ 33 + shardDomain: inputText, 34 + agent, 35 + }); 36 + if (!registerResult.ok) { 37 + console.error( 38 + "Something went wrong when registering the shard.", 39 + registerResult.error, 40 + ); 41 + throw new Error( 42 + `Something went wrong when registering the shard. ${registerResult.error}`, 43 + ); 44 + } 45 + setShowRegisterModal(false); 46 + }, 47 + onSuccess: async () => { 48 + await queryClient.invalidateQueries({ 49 + queryKey: ["shard", session.did], 50 + }); 51 + setShowRegisterModal(false); 52 + }, 53 + onError: (err) => { 54 + console.error( 55 + "Something went wrong when registering the shard.", 56 + err, 57 + ); 58 + setRegisterError(err.message); 59 + }, 26 60 }); 27 - if (!registerResult.ok) { 28 - console.error( 29 - "Something went wrong when registering the shard.", 30 - registerResult.error, 31 - ); 32 - setRegisterError(registerResult.error); 33 - return; 34 - } 35 - setShowRegisterModal(false); 36 - }; 37 61 38 62 return ( 39 63 <View ··· 82 106 paddingVertical: 10, 83 107 }} 84 108 onPress={() => { 85 - handleSubmit().catch((e: unknown) => { 86 - console.error(e); 87 - }); 109 + newShardMutation(); 88 110 }} 89 111 > 90 - <Text 91 - style={[ 92 - typography.weights.byName.normal, 93 - { color: semantic.textInverse }, 94 - ]} 95 - > 96 - Register 97 - </Text> 112 + {mutationPending ? ( 113 + <Loading size="small" /> 114 + ) : ( 115 + <Text 116 + style={[ 117 + typography.weights.byName.normal, 118 + { color: semantic.textInverse }, 119 + ]} 120 + > 121 + Register 122 + </Text> 123 + )} 98 124 </Pressable> 99 125 </View> 100 126 );