Skip to content

Commit

Permalink
Merge pull request #309 from DAOmasons/resubmitFix
Browse files Browse the repository at this point in the history
Resubmit fix
  • Loading branch information
jordanlesich authored Aug 16, 2024
2 parents 0452b67 + 4281c72 commit 4219240
Show file tree
Hide file tree
Showing 16 changed files with 221 additions and 112 deletions.
12 changes: 0 additions & 12 deletions src/components/PostDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,10 @@ export const PostDrawer = ({
Link,
Image.configure({ inline: true, allowBase64: true }),
],
onUpdate({ editor }) {
const newContent = editor.getJSON();
localStorage.setItem(posterId, JSON.stringify(newContent));
},
content,
});
const { tx } = useTx();

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

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

const onClose = () =>
Expand Down Expand Up @@ -121,7 +110,6 @@ export const PostDrawer = ({
writeContractOptions: {
onPollSuccess() {
refetch?.();
localStorage.removeItem(posterId);
},
},
});
Expand Down
3 changes: 1 addition & 2 deletions src/components/RTEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const RTEditor = ({
ref={editorContainerRef}
bg={'transparent'}
classNames={{ root: classes.editor }}
onClick={handleContentEditorFocus}
>
<RichTextEditor.Toolbar bg={'transparent'}>
<RichTextEditor.ControlsGroup style={{ border: 'none' }}>
Expand All @@ -65,8 +66,6 @@ export const RTEditor = ({
p="lg"
fz="md"
bg={'transparent'}
// mih={editorHeight}
// h="100%"
onClick={handleContentEditorFocus}
/>
</RichTextEditor>
Expand Down
73 changes: 48 additions & 25 deletions src/components/dashboard/facilitator/FacPostUpdatePanel.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,42 @@
import React from 'react';
import { DAO_MASONS } from '../../../constants/gameSetup';
import { UpdateInput } from '../../forms/UpdateInput';
import { PINATA_GATEWAY } from '../../../utils/ipfs/get';
import { getGatewayUrl } from '../../../utils/ipfs/get';
import { useTx } from '../../../hooks/useTx';
import GameManagerAbi from '../../../abi/GameManager.json';
import { ADDR } from '../../../constants/addresses';
import { Tag } from '../../../constants/tags';
import { notifications } from '@mantine/notifications';
import {
ContentSchema,
basicUpdateSchema,
} from '../../forms/validationSchemas/updateSchemas';

import { pinJSONToIPFS } from '../../../utils/ipfs/pin';
import { Group } from '@mantine/core';
import { PlayerAvatar } from '../../PlayerAvatar';
import { Player } from '../../../types/ui';
import { TxButton } from '../../TxButton';
import { IconPlus } from '@tabler/icons-react';
import { RTEditor } from '../../RTEditor';
import { useEditor } from '@tiptap/react';
import StarterKit from '@tiptap/starter-kit';
import Link from '@tiptap/extension-link';
import Image from '@tiptap/extension-image';
import { tiptapContentSchema } from '../../forms/validationSchemas/tiptap';
import { useGameManager } from '../../../hooks/useGameMangers';

const defaultContent = { type: 'doc', content: [] };
export const FacPostUpdatePanel = () => {
const { tx } = useTx();
const { refetchGameManager } = useGameManager();

const handlePostUpdate = async (text: string, clear: () => void) => {
if (text === '' || text === null) {
notifications.show({
title: 'Error',
message: 'Update text is missing',
color: 'red',
});
const editor = useEditor({
extensions: [
StarterKit,
Link,
Image.configure({ inline: true, allowBase64: true }),
],

return;
}
content: defaultContent,
});

const metadata = basicUpdateSchema.safeParse({
text,
contentSchema: ContentSchema.BasicUpdate,
});
const handlePostUpdate = async () => {
const metadata = tiptapContentSchema.safeParse(editor?.getJSON());

if (!metadata.success) {
notifications.show({
Expand Down Expand Up @@ -61,15 +67,32 @@ export const FacPostUpdatePanel = () => {
args: [Tag.GameUpdate, [1n, pinRes.IpfsHash]],
},
onComplete() {
clear?.();
refetchGameManager();
editor?.commands.setContent(defaultContent);
},
});
};

return (
<UpdateInput
imgUrl={`${PINATA_GATEWAY}/${DAO_MASONS.AVATAR_IMG}`}
onClick={handlePostUpdate}
/>
<>
<Group mt="40" mb="lg" w="100%" justify="space-between">
<PlayerAvatar
playerType={Player.Facilitators}
imgUrl={getGatewayUrl(DAO_MASONS.AVATAR_IMG)}
name={'Facilitators'}
/>
<Group gap="sm">
<TxButton leftSection={<IconPlus />} onClick={handlePostUpdate}>
Post
</TxButton>
</Group>
</Group>
<RTEditor editor={editor} growHeight={false} />
</>
);
};

// <UpdateInput
// imgUrl={`${PINATA_GATEWAY}/${DAO_MASONS.AVATAR_IMG}`}
// onClick={handlePostUpdate}
// />
45 changes: 29 additions & 16 deletions src/components/feed/FeedCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import { Link } from 'react-router-dom';
import { GAME_TOKEN } from '../../constants/gameSetup';
import { useElementSize, useIntersection } from '@mantine/hooks';
import { IconAward } from '@tabler/icons-react';

import { PlayerAvatar } from '../PlayerAvatar';
import { Content } from '@tiptap/react';
import { RTDisplay } from '../RTDisplay';
Expand Down Expand Up @@ -246,13 +245,20 @@ export const FeedCard = ({

if (internalLink) {
return (
<Box pt={'lg'}>
<Box
component={Link}
ref={observer.ref}
to={internalLink}
style={{ textDecoration: 'none' }}
>
<Box pt={'lg'} pos="relative">
<Box ref={observer.ref} style={{ textDecoration: 'none' }}>
<Link
to={internalLink}
style={{
textDecoration: 'none',
position: 'absolute',
top: 0,
left: 0,
bottom: 0,
right: 0,
zIndex: 1,
}}
/>
{Inner}
</Box>
</Box>
Expand All @@ -261,15 +267,22 @@ export const FeedCard = ({

if (externalLink) {
return (
<Box pt={'lg'}>
<Box
component="a"
ref={observer.ref}
<Box pt={'lg'} style={{ textDecoration: 'none', position: 'relative' }}>
<a
href={externalLink}
style={{ textDecoration: 'none' }}
>
{Inner}
</Box>
target="_blank"
rel="noopener noreferrer"
style={{
textDecoration: 'none',
position: 'absolute',
top: 0,
left: 0,
bottom: 0,
right: 0,
zIndex: 1,
}}
/>
<Box ref={observer.ref}>{Inner}</Box>
</Box>
);
}
Expand Down
25 changes: 21 additions & 4 deletions src/components/feed/RichTextUpdate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import { secondsToShortRelativeTime } from '../../utils/time';
import { AddressAvatar } from '../AddressAvatar';
import { Address } from 'viem';
import { RTDisplay } from '../RTDisplay';
import { Player } from '../../types/ui';
import { getGatewayUrl } from '../../utils/ipfs/get';
import { DAO_MASONS } from '../../constants/gameSetup';

export const getRTUpdate = async (id: string, chainId: number) => {
const { getRTUpdate } = getBuiltGraphSDK();
Expand All @@ -21,7 +24,7 @@ export const getRTUpdate = async (id: string, chainId: number) => {
chainId: chainId,
});

if (!Update) {
if (!Update[0].content) {
throw new Error('No update found');
}

Expand Down Expand Up @@ -77,19 +80,33 @@ export const RichTextUpdate = () => {
return <MainSection maw={675}>Error: {error.message}</MainSection>;
}

if (!update || !update.content || !update.posterProfile) {
if (!update || !update.content) {
return <MainSection maw={675}>404: No update found</MainSection>;
}

const imgUrl =
update.playerType === Player.Facilitators
? getGatewayUrl(DAO_MASONS.AVATAR_IMG)
: update?.posterProfile?.imgUrl
? update.posterProfile.imgUrl
: '?';

const name =
update?.playerType === Player.Facilitators
? 'Facilitators'
: update?.posterProfile?.name
? update?.posterProfile?.name
: 'Unknown';

return (
<MainSection maw={675}>
<PageTitle title="Post" />
<Group mt="xl" gap={8}>
<PlayerAvatar
display="fullPage"
playerType={update.playerType}
imgUrl={update?.posterProfile.imgUrl}
name={update?.posterProfile.name}
imgUrl={imgUrl}
name={name}
/>
<Text size="sm" opacity={0.8}>
·
Expand Down
5 changes: 3 additions & 2 deletions src/components/grant/ApplicationDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,9 @@ export const ApplicationDrawer = ({
{alreadyHasApplication &&
currentApplication.status !== GameStatus.Rejected && (
<Text mb="md" size="sm" c={theme.colors.yellow[6]}>
You have already submitted an application. Resubmitting an old
application will overwrite the previous one.
WARNING: You have already submitted an application. Resubmitting an
old application will overwrite the previous one and restart the
grant process from the beginning.
</Text>
)}
<Stack mb="md">
Expand Down
22 changes: 20 additions & 2 deletions src/components/grant/FacilitatorActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ import { useDisclosure } from '@mantine/hooks';
import { IconPlus } from '@tabler/icons-react';
import { FacilitatorApprovalDrawer } from './FacilitatorApprovalDrawer';
import { useGrant } from '../../hooks/useGrant';
import { GameStatus, GrantStatus } from '../../types/common';
import { GrantStatus } from '../../types/common';
import { DAO_MASONS } from '../../constants/gameSetup';
import { Player } from '../../types/ui';
import { PostGrantDrawer } from './PostGrantDrawer';
import { getGatewayUrl } from '../../utils/ipfs/get';

export const FacilitatorActions = () => {
const [approvalOpened, { open: openApprove, close: closeApprove }] =
useDisclosure();
const [postOpened, { open: openPost, close: closePost }] = useDisclosure();

const { grant } = useGrant();
const { grant, project, ship, refetchGrant } = useGrant();

const isReadyToApprove = grant?.status === GrantStatus.MilestonesApproved;
return (
Expand All @@ -24,11 +29,24 @@ export const FacilitatorActions = () => {
<Text>Review Grantee</Text>
</Button>
)}
<Button variant="menu" leftSection={<IconPlus />} onClick={openPost}>
<Text>Message</Text>
</Button>
</Stack>
<FacilitatorApprovalDrawer
opened={approvalOpened}
onClose={closeApprove}
/>
<PostGrantDrawer
opened={postOpened}
onClose={closePost}
projectId={project?.id || ''}
avatarImg={getGatewayUrl(DAO_MASONS.AVATAR_IMG) || ''}
avatarName={'Facilitators'}
shipSrcAddress={ship?.shipContractAddress || ''}
playerType={Player.Facilitators}
refetch={refetchGrant}
/>
</>
);
};
3 changes: 0 additions & 3 deletions src/components/grant/FacilitatorApprovalDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ export const FacilitatorApprovalDrawer = ({
]
);

console.log('encoded', encoded);
console.log('ship.poolId', ship.poolId);

tx({
writeContractParams: {
abi: AlloAbi,
Expand Down
17 changes: 15 additions & 2 deletions src/components/grant/GrantTimeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { FundsDistributed } from './FundsDistributed';
import { GrantHelper } from './GrantHelpers';
import { InsetUpdate } from './InsetUpdate';
import { IconMail } from '@tabler/icons-react';
import { DAO_MASONS } from '../../constants/gameSetup';
import { getGatewayUrl } from '../../utils/ipfs/get';

export const GrantTimeline = () => {
const { timeline, ship, project } = useGrant();
Expand All @@ -42,7 +44,6 @@ export const GrantTimeline = () => {
}
if (item.tag === 'grant/update/ship') {
const update = item as GrantUpdate;

return (
<UserUpdate
key={update.id}
Expand All @@ -67,9 +68,21 @@ export const GrantTimeline = () => {
/>
);
}
if (item.tag === 'grant/update/facilitator') {
const update = item as GrantUpdate;
return (
<UserUpdate
key={update.id}
content={update.updateContent}
posterImg={getGatewayUrl(DAO_MASONS.AVATAR_IMG)}
posterName={'Facilitators'}
playerType={update.playerType}
timestamp={update.timestamp}
/>
);
}
if (item.tag === 'grant/invite/ship') {
const update = item as GrantUpdate;

return (
<InsetUpdate
key={update.id}
Expand Down
2 changes: 1 addition & 1 deletion src/components/grant/PostGrantDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export const PostGrantDrawer = ({
return;
}

const FULL_TAG = `${playerType === Player.Project ? Tag.ProjectGrantUpdate : Tag.ShipGrantUpdate}:${projectId}`;
const FULL_TAG = `${playerType === Player.Project ? Tag.ProjectGrantUpdate : playerType === Player.Ship ? Tag.ShipGrantUpdate : Tag.FacilitatorGrantUpdate}:${projectId}`;

tx({
writeContractParams: {
Expand Down
Loading

0 comments on commit 4219240

Please sign in to comment.