Skip to content

Commit

Permalink
Merge pull request #282 from DAOmasons/Aug6
Browse files Browse the repository at this point in the history
Aug6
  • Loading branch information
jordanlesich authored Aug 7, 2024
2 parents 801d5f0 + 5dcc2eb commit 917b013
Show file tree
Hide file tree
Showing 13 changed files with 176 additions and 136 deletions.
3 changes: 1 addition & 2 deletions .graphclientrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ sources:
- name: grant-ships
handler:
graphql:
endpoint: https://indexer.bigdevenergy.link/3a96753/v1/graphql
endpoint: https://indexer.bigdevenergy.link/e09c75f/v1/graphql
# endpoint: http://localhost:8080/v1/graphql
# endpoint: https://{context.apiEndpoint:api.studio.thegraph.com/query/41101/grant-ships-arb/version/latest}
# - name: gs-voting
# handler:
# graphql:
Expand Down
25 changes: 13 additions & 12 deletions src/.graphclient/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9762,7 +9762,7 @@ const grantShipsTransforms = [];
const additionalTypeDefs = [] as any[];
const grantShipsHandler = new GraphqlHandler({
name: "grant-ships",
config: {"endpoint":"https://indexer.bigdevenergy.link/3a96753/v1/graphql"},
config: {"endpoint":"https://indexer.bigdevenergy.link/e09c75f/v1/graphql"},
baseDir,
cache,
pubsub,
Expand Down Expand Up @@ -9916,11 +9916,11 @@ const merger = new(BareMerger as any)({
},
location: 'GetShipPoolIdDocument.graphql'
},{
document: GetUpdatesDocument,
document: GetUpdatesQueryDocument,
get rawSDL() {
return printWithCache(GetUpdatesDocument);
return printWithCache(GetUpdatesQueryDocument);
},
location: 'GetUpdatesDocument.graphql'
location: 'GetUpdatesQueryDocument.graphql'
},{
document: GetUserDataDocument,
get rawSDL() {
Expand Down Expand Up @@ -10359,13 +10359,13 @@ export type getShipPoolIdQueryVariables = Exact<{

export type getShipPoolIdQuery = { GrantShip: Array<Pick<GrantShip, 'poolId'>> };

export type getUpdatesQueryVariables = Exact<{
export type getUpdatesQueryQueryVariables = Exact<{
entityAddress: Scalars['String'];
scope?: InputMaybe<Scalars['Int']>;
}>;


export type getUpdatesQuery = { Update: Array<(
export type getUpdatesQueryQuery = { Update: Array<(
Pick<Update, 'id' | 'postedBy' | 'entityAddress' | 'timestamp'>
& { content?: Maybe<Pick<RawMetadata, 'pointer'>> }
)> };
Expand Down Expand Up @@ -10421,7 +10421,7 @@ export type shipPageQueryQueryVariables = Exact<{


export type shipPageQueryQuery = { GrantShip: Array<(
Pick<GrantShip, 'id' | 'name' | 'status' | 'poolId' | 'shipContractAddress' | 'shipApplicationBytesData' | 'owner' | 'balance' | 'totalFundsReceived' | 'totalAllocated' | 'totalDistributed' | 'totalRoundAmount'>
Pick<GrantShip, 'hatId' | 'id' | 'name' | 'status' | 'poolId' | 'shipContractAddress' | 'shipApplicationBytesData' | 'owner' | 'balance' | 'totalFundsReceived' | 'totalAllocated' | 'totalDistributed' | 'totalRoundAmount'>
& { profileMetadata?: Maybe<Pick<RawMetadata, 'pointer'>>, alloProfileMembers?: Maybe<Pick<ProfileMemberGroup, 'addresses'>> }
)> };

Expand Down Expand Up @@ -10987,16 +10987,16 @@ export const getShipPoolIdDocument = gql`
}
}
` as unknown as DocumentNode<getShipPoolIdQuery, getShipPoolIdQueryVariables>;
export const getUpdatesDocument = gql`
query getUpdates($entityAddress: String!, $scope: Int) {
export const getUpdatesQueryDocument = gql`
query getUpdatesQuery($entityAddress: String!, $scope: Int) {
Update(
where: {entityAddress: {_eq: $entityAddress}, scope: {_eq: $scope}}
order_by: {timestamp: desc}
) {
...UpdateBody
}
}
${UpdateBodyFragmentDoc}` as unknown as DocumentNode<getUpdatesQuery, getUpdatesQueryVariables>;
${UpdateBodyFragmentDoc}` as unknown as DocumentNode<getUpdatesQueryQuery, getUpdatesQueryQueryVariables>;
export const getUserDataDocument = gql`
query getUserData($id: String!, $chainId: Int!) {
projects: Project(where: {owner: {_eq: $id}, chainId: {_eq: $chainId}}) {
Expand Down Expand Up @@ -11063,6 +11063,7 @@ export const shipPageQueryDocument = gql`
query shipPageQuery($id: String!) {
GrantShip(where: {id: {_eq: $id}}) {
...BaseShipData
hatId
}
}
${BaseShipDataFragmentDoc}` as unknown as DocumentNode<shipPageQueryQuery, shipPageQueryQueryVariables>;
Expand Down Expand Up @@ -11165,8 +11166,8 @@ export function getSdk<C, E>(requester: Requester<C, E>) {
getShipPoolId(variables: getShipPoolIdQueryVariables, options?: C): Promise<getShipPoolIdQuery> {
return requester<getShipPoolIdQuery, getShipPoolIdQueryVariables>(getShipPoolIdDocument, variables, options) as Promise<getShipPoolIdQuery>;
},
getUpdates(variables: getUpdatesQueryVariables, options?: C): Promise<getUpdatesQuery> {
return requester<getUpdatesQuery, getUpdatesQueryVariables>(getUpdatesDocument, variables, options) as Promise<getUpdatesQuery>;
getUpdatesQuery(variables: getUpdatesQueryQueryVariables, options?: C): Promise<getUpdatesQueryQuery> {
return requester<getUpdatesQueryQuery, getUpdatesQueryQueryVariables>(getUpdatesQueryDocument, variables, options) as Promise<getUpdatesQueryQuery>;
},
getUserData(variables: getUserDataQueryVariables, options?: C): Promise<getUserDataQuery> {
return requester<getUserDataQuery, getUserDataQueryVariables>(getUserDataDocument, variables, options) as Promise<getUserDataQuery>;
Expand Down
75 changes: 41 additions & 34 deletions src/components/PostDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,26 @@ import { pinJSONToIPFS } from '../utils/ipfs/pin';
import { notifications } from '@mantine/notifications';
import { TxButton } from './TxButton';
import { PlayerAvatar } from './PlayerAvatar';
import { GAME_MANAGER } from '../constants/gameSetup';
import { GAME_MANAGER, ZER0_ADDRESS } from '../constants/gameSetup';
import { RTEditor } from './RTEditor';
import { PageDrawer } from './PageDrawer';
import GrantShipAbi from '../abi/GrantShip.json';
import { Address } from 'viem';

type PostDrawerProps = {
avatarImg?: string;
name?: string;
posterType: Player;
posterId: string;
postType: string;
refetch: () => void;
content?: Content;
};

export const PostDrawer = ({
avatarImg,
name,
postType,
posterType,
posterId,

refetch,
content = { type: 'doc', content: [] },
}: PostDrawerProps) => {
Expand All @@ -48,20 +48,18 @@ export const PostDrawer = ({
],
onUpdate({ editor }) {
const newContent = editor.getJSON();
localStorage.setItem(postId, JSON.stringify(newContent));
localStorage.setItem(posterId, JSON.stringify(newContent));
},
content,
});
const { tx } = useTx();

const postId = `${postType}-${posterId}`;

useEffect(() => {
const draft = localStorage.getItem(postId);
const draft = localStorage.getItem(posterId);
if (editor && draft) {
editor.commands.setContent(JSON.parse(draft));
}
}, [postId, editor]);
}, [posterId, editor]);

const isOpen = location.pathname.includes('post');

Expand Down Expand Up @@ -93,38 +91,47 @@ export const PostDrawer = ({

onClose();

// tag: TAG tells the indexer to await for instructions
// action: PROJECT_POST action code to be executed index side
// postId:
// - posterId: the id of the poster, in this case it's the profileID
/// - GAME_MANAGER.ADDRESS ensures that this post is only available within this game scope

const tag = `TAG:PROJECT_POST:${postId}:${GAME_MANAGER.ADDRESS}`;
if (posterType === Player.Project) {
const tag = `TAG:PROJECT_POST:${GAME_MANAGER.ADDRESS}`;

tx({
writeContractParams: {
abi: AlloPoster,
address: ADDR.ALLO_POSTER,
functionName: 'postUpdate',
args: [tag, posterId, [1n, pinRes.IpfsHash]],
},
writeContractOptions: {
onPollSuccess() {
refetch();
localStorage.removeItem(postId);
tx({
writeContractParams: {
abi: AlloPoster,
address: ADDR.ALLO_POSTER,
functionName: 'postUpdate',
args: [tag, posterId, [1n, pinRes.IpfsHash]],
},
},
});
writeContractOptions: {
onPollSuccess() {
refetch();
localStorage.removeItem(posterId);
},
},
});
} else if (Player.Ship === posterType) {
const tag = `TAG:SHIP_POST:${GAME_MANAGER.ADDRESS}`;

tx({
writeContractParams: {
abi: GrantShipAbi,
address: posterId as Address,
functionName: 'postUpdate',
args: [tag, [1n, pinRes.IpfsHash], ZER0_ADDRESS],
},
writeContractOptions: {
onPollSuccess() {
refetch?.();
localStorage.removeItem(posterId);
},
},
});
}
};

return (
<PageDrawer pageTitle="Post Update" opened={isOpen} onClose={onClose}>
<Group mt="40" mb="lg" w="100%" justify="space-between">
<PlayerAvatar
playerType={Player.Project}
imgUrl={avatarImg}
name={name}
/>
<PlayerAvatar playerType={posterType} imgUrl={avatarImg} name={name} />
<Group gap="sm">
<TxButton leftSection={<IconPlus />} onClick={postContent}>
Post
Expand Down
72 changes: 72 additions & 0 deletions src/components/UpdatesPanel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { Box, Divider, Group, Skeleton, Text } from '@mantine/core';
import { ResolvedUpdate } from '../resolvers/updates';
import { Display } from './Display';
import { PlayerAvatar } from './PlayerAvatar';
import { secondsToShortRelativeTime } from '../utils/time';
import { Player } from '../types/ui';
import { RTDisplay } from './RTDisplay';

export const UpdatesPanel = ({
updates,
name,
isLoading,
error,
imgUrl,
playerType,
}: {
playerType: Player;
updates?: ResolvedUpdate[];
imgUrl?: string;
name: string;
isLoading: boolean;
error: Error | null;
}) => {
if (isLoading) {
return (
<Box>
<Box mt="200" />
<Skeleton h={1} mb={200} />
<Skeleton h={1} mb={200} />
</Box>
);
}

if (error) {
return <Display title="Error" description={error.message} />;
}

if (!updates || updates?.length === 0) {
return (
<Display
title="Just Getting Started"
description={`${name} hasn't posted any updates yet.`}
/>
);
}

return (
<Box>
{updates.map((update) => (
<Box pb="lg" key={update.id}>
<Group mb="sm" gap={8}>
<PlayerAvatar
imgUrl={imgUrl || ''}
name={name}
playerType={playerType}
/>
<Text size="sm" opacity={0.8}>
·
</Text>
<Text size="sm" opacity={0.8}>
{secondsToShortRelativeTime(update.timestamp)}
</Text>
</Group>
<Box mb="lg" pl={50}>
<RTDisplay content={update.content} />
</Box>
<Divider mb="lg" />
</Box>
))}
</Box>
);
};
1 change: 0 additions & 1 deletion src/components/projectItems/ProjectUpdatesPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// import { FeedSkeletonCard } from '../skeletons';
// import { AppAlert } from '../UnderContruction';
// import { IconX } from '@tabler/icons-react';
// import { getUpdates } from '../../queries/getUpdates';
// import { FeedCard } from '../feed/FeedCard';
// import { DashGrant } from '../../resolvers/grantResolvers';
// import { useState } from 'react';
Expand Down
2 changes: 1 addition & 1 deletion src/graphql/newQueries/getUpdates.graphql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
query getUpdates($entityAddress: String!, $scope: Int) {
query getUpdatesQuery($entityAddress: String!, $scope: Int) {
Update(
where: { entityAddress: { _eq: $entityAddress }, scope: { _eq: $scope } }
order_by: { timestamp: desc }
Expand Down
1 change: 1 addition & 0 deletions src/graphql/newQueries/shipPage.graphql
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
query shipPageQuery($id: String!) {
GrantShip(where: { id: { _eq: $id } }) {
...BaseShipData
hatId
}
}
Loading

0 comments on commit 917b013

Please sign in to comment.