Skip to content

Commit

Permalink
Merge pull request #314 from DAOmasons/mobileGrantsPage
Browse files Browse the repository at this point in the history
Mobile grants page
  • Loading branch information
jordanlesich authored Aug 22, 2024
2 parents ea6d72a + 5c63f26 commit 368eb7c
Show file tree
Hide file tree
Showing 16 changed files with 386 additions and 51 deletions.
4 changes: 2 additions & 2 deletions src/components/feed/RichTextUpdate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { MainSection, PageTitle } from '../../layout/Sections';
import { useQuery } from '@tanstack/react-query';
import { useParams } from 'react-router-dom';
import { getBuiltGraphSDK } from '../../.graphclient';
import { useChainId } from 'wagmi';
import { useChainId, useConfig } from 'wagmi';
import { resolveProjectMetadata } from '../../resolvers/projectResolvers';
import { Box, Divider, Group, Skeleton, Text } from '@mantine/core';
import { resolveRichTextMetadata } from '../../resolvers/updates';
Expand All @@ -16,7 +16,7 @@ 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 = async (id: string, chainId: number) => {
const { getRTUpdate } = getBuiltGraphSDK();

const { Update } = await getRTUpdate({
Expand Down
5 changes: 4 additions & 1 deletion src/components/grant/ApplicationDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { GameStatus } from '../../types/common';
import classes from '../../styles/Spoiler.module.css';
import { ApplicationVerdictControls } from './ApplicationVerdictControls';
import { useMemo } from 'react';
import { useMobile } from '../../hooks/useBreakpoint';

export const ApplicationDisplay = ({
amountRequested,
Expand All @@ -56,6 +57,8 @@ export const ApplicationDisplay = ({
const theme = useMantineTheme();
const { project, grant, isShipOperator } = useGrant();

const isMobile = useMobile();

const formattedTime = secondsToLongDate(dueDate);
const formattedAmount = formatEther(BigInt(amountRequested));

Expand Down Expand Up @@ -135,7 +138,7 @@ export const ApplicationDisplay = ({
</>
)}
</Group>
<Box pl={50} mb="lg">
<Box pl={isMobile ? 0 : 50} mb="lg">
<Group gap={8} mb={'lg'}>
<PlayerAvatar
playerType={Player.Project}
Expand Down
51 changes: 50 additions & 1 deletion src/components/grant/FacilitatorActions.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Button, Stack, Text } from '@mantine/core';
import { Button, Group, Stack, Text } from '@mantine/core';
import { useDisclosure } from '@mantine/hooks';
import { IconPlus } from '@tabler/icons-react';
import { FacilitatorApprovalDrawer } from './FacilitatorApprovalDrawer';
Expand Down Expand Up @@ -50,3 +50,52 @@ export const FacilitatorActions = () => {
</>
);
};

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

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

const isReadyToApprove = grant?.status === GrantStatus.MilestonesApproved;

return (
<>
<Group gap="sm">
{isReadyToApprove && (
<Button
variant="menu"
leftSection={<IconPlus />}
onClick={openApprove}
size="xs"
>
Review Grantee
</Button>
)}
<Button
variant="menu"
leftSection={<IconPlus size={14} />}
onClick={openPost}
size="xs"
>
Message
</Button>
</Group>
<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}
/>
</>
);
};
11 changes: 7 additions & 4 deletions src/components/grant/InsetUpdate.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Box, Divider, Group, Text } from '@mantine/core';
import { Box, Divider, Flex, Group, Text } from '@mantine/core';
import { ReactNode, useMemo } from 'react';
import { Bold } from '../Typography';
import { secondsToShortRelativeTime } from '../../utils/time';
import { useMobile } from '../../hooks/useBreakpoint';

export const InsetUpdate = ({
posterName,
Expand All @@ -16,14 +17,16 @@ export const InsetUpdate = ({
posterName: string;
timestamp: number;
}) => {
const isMobile = useMobile();

const time = useMemo(() => {
if (!timestamp) return '';
return secondsToShortRelativeTime(timestamp);
}, [timestamp]);
return (
<>
<Box pl={50}>
<Group gap={8} mb="xs">
<Box pl={isMobile ? 0 : 50}>
<Flex gap={8} mb="xs" style={{ flexShrink: 0, flexWrap: 'wrap' }}>
{symbolUI}
<Text size="sm">
<Bold>{posterName}</Bold> {tagline}
Expand All @@ -34,7 +37,7 @@ export const InsetUpdate = ({
<Text size="sm" opacity={0.8}>
{time}
</Text>
</Group>
</Flex>
<Box mb="lg">{bodyUI}</Box>
</Box>
<Divider mb="lg" />
Expand Down
5 changes: 4 additions & 1 deletion src/components/grant/MilestoneDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ import { formatEther } from 'viem';
import { secondsToLongDate } from '../../utils/time';
import { RTDisplay } from '../RTDisplay';
import { MilestoneVerdictControls } from './MilestoneVerdictControls';
import { useMobile } from '../../hooks/useBreakpoint';

export const MilestoneDisplay = ({
updateData,
}: {
updateData: GrantUpdate;
}) => {
const theme = useMantineTheme();
const isMobile = useMobile();

const { currentMilestoneSet, project, isShipOperator } = useGrant();

const milestoneId = updateData.id.split(':')[0];
Expand Down Expand Up @@ -88,7 +91,7 @@ export const MilestoneDisplay = ({
</Text>
</Group>
</Box>
<Box pl={50} mb="lg">
<Box pl={isMobile ? 0 : 50} mb="lg">
<Group gap="8" mb="lg">
<PlayerAvatar
playerType={Player.Project}
Expand Down
5 changes: 4 additions & 1 deletion src/components/grant/MilestoneSetDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ import {
import { MilestoneSetVerdictControls } from './MilestoneSetVerdictControls';
import { useMemo } from 'react';
import classes from '../../styles/Spoiler.module.css';
import { useMobile } from '../../hooks/useBreakpoint';

export const MilestoneSetDisplay = ({ doc }: { doc: MilestonesDisplay }) => {
const theme = useMantineTheme();
const isMobile = useMobile();

const { status, id, resolvedMilestones } = doc;
const { project, grant, isShipOperator } = useGrant();

Expand Down Expand Up @@ -135,7 +138,7 @@ export const MilestoneSetDisplay = ({ doc }: { doc: MilestonesDisplay }) => {
</Text>
</Group>
</Box>
<Box pl={50} mb="lg">
<Box pl={isMobile ? 0 : 50} mb="lg">
<Group gap={8} mb={'lg'}>
<PlayerAvatar
playerType={Player.Project}
Expand Down
4 changes: 3 additions & 1 deletion src/components/grant/NextStep.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Box, Divider, Flex } from '@mantine/core';
import { ReactNode } from 'react';
import { useMobile } from '../../hooks/useBreakpoint';

export const NextStep = ({
text,
Expand All @@ -8,9 +9,10 @@ export const NextStep = ({
text: ReactNode;
icon?: ReactNode;
}) => {
const isMobile = useMobile();
return (
<Box mb="lg">
<Box pl={50} mb="sm" opacity={0.8}>
<Box pl={isMobile ? 0 : 50} mb="sm" opacity={0.8}>
<Flex gap="8">
<Box style={{ flexShrink: 0 }}>{icon}</Box>
<Box style={{ minWidth: 0, flexGrow: 1 }}>{text}</Box>
Expand Down
145 changes: 144 additions & 1 deletion src/components/grant/ProjectActions.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useDisclosure } from '@mantine/hooks';
import { useGrant } from '../../hooks/useGrant';
import { GameStatus, GrantStatus } from '../../types/common';
import { Button, Stack, Text } from '@mantine/core';
import { Button, Group, Stack, Text } from '@mantine/core';
import { IconPencil, IconPlus } from '@tabler/icons-react';
import { ApplicationDrawer } from './ApplicationDrawer';
import { formatEther } from 'viem';
Expand Down Expand Up @@ -143,3 +143,146 @@ export const ProjectActions = () => {
</>
);
};

export const ProjectActionsMobile = () => {
const {
project,
ship,
refetchGrant,
applicationTemplate,
grant,
currentApplication,
} = useGrant();
const [postOpened, { open: openPost, close: closePost }] = useDisclosure();
const [
applicationOpened,
{ open: openApplication, close: closeApplication },
] = useDisclosure();
const [milestonesOpened, { open: openMilestones, close: closeMilestones }] =
useDisclosure();

const isApplicationStage =
!grant || (grant?.status && grant.status < GrantStatus.MilestonesApproved);

const isMilestonePlanning =
grant?.status &&
grant.status >= GrantStatus.ApplicationApproved &&
grant?.status < GrantStatus.MilestonesApproved;

const areMilestonesLocked =
grant?.status &&
grant.status === GrantStatus.Allocated &&
grant?.currentMilestones?.status === GameStatus.Accepted;

const alreadyHasApplication = !!currentApplication;
const alreadyHasMilestoneSet = !!grant?.currentMilestones;

return (
<>
<Group gap="sm">
{isApplicationStage && alreadyHasApplication && (
<Button
variant={
grant?.status && grant.status > GrantStatus.ApplicationApproved
? 'menu-fade'
: 'menu'
}
leftSection={<IconPencil size={14} />}
onClick={openApplication}
size="xs"
>
Application
</Button>
)}

{isMilestonePlanning && (
<Button
variant="menu"
size="xs"
leftSection={
alreadyHasMilestoneSet &&
grant?.status !== GrantStatus.Allocated ? (
<IconPencil size={14} />
) : (
<IconPlus size={14} />
)
}
onClick={openMilestones}
>
Milestones
</Button>
)}
{areMilestonesLocked && (
<Button
variant="menu"
size="xs"
leftSection={<IconPlus size={14} />}
onClick={openMilestones}
>
Milestones
</Button>
)}
{isApplicationStage && !alreadyHasApplication && (
<Button
variant="menu"
size="xs"
leftSection={<IconPlus size={14} />}
onClick={openApplication}
>
Application
</Button>
)}
<Button
size="xs"
variant="menu"
leftSection={<IconPlus size={14} />}
onClick={openPost}
>
Message
</Button>
</Group>
{alreadyHasApplication ? (
<ApplicationDrawer
key={`application-drawer-${currentApplication?.id}`}
opened={applicationOpened}
onClose={closeApplication}
content={currentApplication?.content?.content}
initialDueDate={
new Date(currentApplication?.content.dueDate * 1000 || '')
}
initialAmount={
currentApplication?.amount
? formatEther(currentApplication?.amount)
: ''
}
initialSendAddress={currentApplication?.receivingAddress}
/>
) : (
<ApplicationDrawer
key={`application-drawer-new`}
opened={applicationOpened}
onClose={closeApplication}
content={applicationTemplate}
/>
)}
<PostGrantDrawer
opened={postOpened}
onClose={closePost}
projectId={project?.id || ''}
avatarImg={project?.metadata?.imgUrl || ''}
avatarName={project?.name || ''}
shipSrcAddress={ship?.shipContractAddress || ''}
playerType={Player.Project}
refetch={refetchGrant}
/>
{areMilestonesLocked ? (
<SubmitMilestoneDrawer
opened={milestonesOpened}
onClose={closeMilestones}
/>
) : (
<MilestonesDrawer opened={milestonesOpened} onClose={closeMilestones} />
)}
</>
);
};
Loading

0 comments on commit 368eb7c

Please sign in to comment.