Hey is a decentralized and permissionless social media app built with Lens Protocol 🌿

Add refresh metadata action (#5733)

authored by yoginth.com and committed by

GitHub cc04c83b bc7934dc

+78 -1
+55
apps/web/src/components/Post/Actions/Menu/RefreshMetadata.tsx
··· 1 + import cn from "@/helpers/cn"; 2 + import errorToast from "@/helpers/errorToast"; 3 + import stopEventPropagation from "@/helpers/stopEventPropagation"; 4 + import {} from "@apollo/client"; 5 + import { MenuItem } from "@headlessui/react"; 6 + import { ArrowPathIcon } from "@heroicons/react/24/outline"; 7 + import { type PostFragment, useRefreshMetadataMutation } from "@hey/indexer"; 8 + import type { ApolloClientError } from "@hey/types/errors"; 9 + import { toast } from "sonner"; 10 + 11 + interface RefreshMetadataProps { 12 + post: PostFragment; 13 + } 14 + 15 + const RefreshMetadata = ({ post }: RefreshMetadataProps) => { 16 + const [refreshMetadata] = useRefreshMetadataMutation({ 17 + variables: { request: { entity: { post: post.id } } }, 18 + onError: (error: ApolloClientError) => errorToast(error) 19 + }); 20 + 21 + const handleRefreshMetadata = async () => { 22 + try { 23 + toast.promise(refreshMetadata(), { 24 + loading: "Refreshing metadata...", 25 + success: "Metadata refresh requested", 26 + error: "Failed to refresh metadata" 27 + }); 28 + } catch (error) { 29 + errorToast(error); 30 + } 31 + }; 32 + 33 + return ( 34 + <MenuItem 35 + as="div" 36 + className={({ focus }) => 37 + cn( 38 + { "dropdown-active": focus }, 39 + "m-2 block cursor-pointer rounded-lg px-2 py-1.5 text-sm" 40 + ) 41 + } 42 + onClick={(event) => { 43 + stopEventPropagation(event); 44 + handleRefreshMetadata(); 45 + }} 46 + > 47 + <div className="flex items-center space-x-2"> 48 + <ArrowPathIcon className="size-4" /> 49 + <div>Refresh metadata</div> 50 + </div> 51 + </MenuItem> 52 + ); 53 + }; 54 + 55 + export default RefreshMetadata;
+5 -1
apps/web/src/components/Post/Actions/Menu/index.tsx
··· 11 11 import Delete from "./Delete"; 12 12 import HideComment from "./HideComment"; 13 13 import NotInterested from "./NotInterested"; 14 + import RefreshMetadata from "./RefreshMetadata"; 14 15 import Report from "./Report"; 15 16 import Share from "./Share"; 16 17 ··· 54 55 <CopyPostText post={post} /> 55 56 <div className="divider" /> 56 57 {currentAccount?.address === post?.author?.address ? ( 57 - <Delete post={post} /> 58 + <> 59 + <RefreshMetadata post={post} /> 60 + <Delete post={post} /> 61 + </> 58 62 ) : ( 59 63 <Report post={post} /> 60 64 )}
+5
packages/indexer/documents/mutations/RefreshMetadata.graphql
··· 1 + mutation RefreshMetadata($request: RefreshMetadataRequest!) { 2 + refreshMetadata(request: $request) { 3 + id 4 + } 5 + }
+13
packages/indexer/generated.ts
··· 7493 7493 7494 7494 export type TransactionWillFailFragment = { __typename?: 'TransactionWillFail', reason: string }; 7495 7495 7496 + export type RefreshMetadataMutationVariables = Exact<{ 7497 + request: RefreshMetadataRequest; 7498 + }>; 7499 + 7500 + 7501 + export type RefreshMetadataMutation = { __typename?: 'Mutation', refreshMetadata: { __typename?: 'RefreshMetadataResult', id: any } }; 7502 + 7496 7503 export type AddAccountManagerMutationVariables = Exact<{ 7497 7504 request: AddAccountManagerRequest; 7498 7505 }>; ··· 8629 8636 export const SelfFundedTransactionRequestFragmentDoc = {"kind":"Document","definitions":[{"kind":"FragmentDefinition","name":{"kind":"Name","value":"SelfFundedTransactionRequest"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"SelfFundedTransactionRequest"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"raw"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"chainId"}},{"kind":"Field","name":{"kind":"Name","value":"data"}},{"kind":"Field","name":{"kind":"Name","value":"from"}},{"kind":"Field","name":{"kind":"Name","value":"gasLimit"}},{"kind":"Field","name":{"kind":"Name","value":"maxFeePerGas"}},{"kind":"Field","name":{"kind":"Name","value":"maxPriorityFeePerGas"}},{"kind":"Field","name":{"kind":"Name","value":"nonce"}},{"kind":"Field","name":{"kind":"Name","value":"to"}},{"kind":"Field","name":{"kind":"Name","value":"type"}},{"kind":"Field","name":{"kind":"Name","value":"value"}}]}}]}}]} as unknown as DocumentNode; 8630 8637 export const SponsoredTransactionRequestFragmentDoc = {"kind":"Document","definitions":[{"kind":"FragmentDefinition","name":{"kind":"Name","value":"SponsoredTransactionRequest"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"SponsoredTransactionRequest"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"raw"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"chainId"}},{"kind":"Field","name":{"kind":"Name","value":"data"}},{"kind":"Field","name":{"kind":"Name","value":"from"}},{"kind":"Field","name":{"kind":"Name","value":"gasLimit"}},{"kind":"Field","name":{"kind":"Name","value":"maxFeePerGas"}},{"kind":"Field","name":{"kind":"Name","value":"maxPriorityFeePerGas"}},{"kind":"Field","name":{"kind":"Name","value":"nonce"}},{"kind":"Field","name":{"kind":"Name","value":"to"}},{"kind":"Field","name":{"kind":"Name","value":"type"}},{"kind":"Field","name":{"kind":"Name","value":"value"}},{"kind":"Field","name":{"kind":"Name","value":"customData"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"customSignature"}},{"kind":"Field","name":{"kind":"Name","value":"factoryDeps"}},{"kind":"Field","name":{"kind":"Name","value":"gasPerPubdata"}},{"kind":"Field","name":{"kind":"Name","value":"paymasterParams"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"paymaster"}},{"kind":"Field","name":{"kind":"Name","value":"paymasterInput"}}]}}]}}]}}]}}]} as unknown as DocumentNode; 8631 8638 export const TransactionWillFailFragmentDoc = {"kind":"Document","definitions":[{"kind":"FragmentDefinition","name":{"kind":"Name","value":"TransactionWillFail"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"TransactionWillFail"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"reason"}}]}}]} as unknown as DocumentNode; 8639 + export const RefreshMetadataDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"RefreshMetadata"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"request"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"RefreshMetadataRequest"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"refreshMetadata"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"request"},"value":{"kind":"Variable","name":{"kind":"Name","value":"request"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}}]}}]}}]} as unknown as DocumentNode; 8640 + export function useRefreshMetadataMutation(baseOptions?: Apollo.MutationHookOptions<RefreshMetadataMutation, RefreshMetadataMutationVariables>) { 8641 + const options = {...defaultOptions, ...baseOptions} 8642 + return Apollo.useMutation<RefreshMetadataMutation, RefreshMetadataMutationVariables>(RefreshMetadataDocument, options); 8643 + } 8644 + export type RefreshMetadataMutationHookResult = ReturnType<typeof useRefreshMetadataMutation>; 8632 8645 export const AddAccountManagerDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"AddAccountManager"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"request"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"AddAccountManagerRequest"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"addAccountManager"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"request"},"value":{"kind":"Variable","name":{"kind":"Name","value":"request"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"InlineFragment","typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"SelfFundedTransactionRequest"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"SelfFundedTransactionRequest"}}]}},{"kind":"InlineFragment","typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"SponsoredTransactionRequest"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"SponsoredTransactionRequest"}}]}},{"kind":"InlineFragment","typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"TransactionWillFail"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"TransactionWillFail"}}]}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"SelfFundedTransactionRequest"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"SelfFundedTransactionRequest"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"raw"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"chainId"}},{"kind":"Field","name":{"kind":"Name","value":"data"}},{"kind":"Field","name":{"kind":"Name","value":"from"}},{"kind":"Field","name":{"kind":"Name","value":"gasLimit"}},{"kind":"Field","name":{"kind":"Name","value":"maxFeePerGas"}},{"kind":"Field","name":{"kind":"Name","value":"maxPriorityFeePerGas"}},{"kind":"Field","name":{"kind":"Name","value":"nonce"}},{"kind":"Field","name":{"kind":"Name","value":"to"}},{"kind":"Field","name":{"kind":"Name","value":"type"}},{"kind":"Field","name":{"kind":"Name","value":"value"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"SponsoredTransactionRequest"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"SponsoredTransactionRequest"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"raw"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"chainId"}},{"kind":"Field","name":{"kind":"Name","value":"data"}},{"kind":"Field","name":{"kind":"Name","value":"from"}},{"kind":"Field","name":{"kind":"Name","value":"gasLimit"}},{"kind":"Field","name":{"kind":"Name","value":"maxFeePerGas"}},{"kind":"Field","name":{"kind":"Name","value":"maxPriorityFeePerGas"}},{"kind":"Field","name":{"kind":"Name","value":"nonce"}},{"kind":"Field","name":{"kind":"Name","value":"to"}},{"kind":"Field","name":{"kind":"Name","value":"type"}},{"kind":"Field","name":{"kind":"Name","value":"value"}},{"kind":"Field","name":{"kind":"Name","value":"customData"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"customSignature"}},{"kind":"Field","name":{"kind":"Name","value":"factoryDeps"}},{"kind":"Field","name":{"kind":"Name","value":"gasPerPubdata"}},{"kind":"Field","name":{"kind":"Name","value":"paymasterParams"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"paymaster"}},{"kind":"Field","name":{"kind":"Name","value":"paymasterInput"}}]}}]}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"TransactionWillFail"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"TransactionWillFail"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"reason"}}]}}]} as unknown as DocumentNode; 8633 8646 export function useAddAccountManagerMutation(baseOptions?: Apollo.MutationHookOptions<AddAccountManagerMutation, AddAccountManagerMutationVariables>) { 8634 8647 const options = {...defaultOptions, ...baseOptions}