Skip to content

Commit

Permalink
start updates feed
Browse files Browse the repository at this point in the history
  • Loading branch information
scottrepreneur committed Dec 14, 2022
1 parent 02ded45 commit 7f3420e
Show file tree
Hide file tree
Showing 14 changed files with 267 additions and 79 deletions.
2 changes: 1 addition & 1 deletion apps/frontend/components/MemberAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { IMember, memberDisplayName } from '../utils';
import * as blockies from 'blockies-ts';

type MemberAvatarProps = {
member: IMember;
member: Partial<IMember>;
};

const MemberAvatar = ({ member }: MemberAvatarProps) => {
Expand Down
46 changes: 23 additions & 23 deletions apps/frontend/components/RaidCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
Button,
Text,
HStack,
VStack,
Box,
Badge,
Icon,
Tooltip,
Expand Down Expand Up @@ -70,11 +70,11 @@ const RaidCard: React.FC<RaidProps> = ({ raid, consultation }: RaidProps) => {
}

return (
<Card variant="withHeader">
<Box bg="gray.800" rounded="md" p={8} w="100%">
<Flex
direction="row"
width="90%"
mx="auto"
// width="90%"
// mx="auto"
alignItems="space-apart"
justifyContent="space-between"
>
Expand Down Expand Up @@ -109,21 +109,8 @@ const RaidCard: React.FC<RaidProps> = ({ raid, consultation }: RaidProps) => {
</HStack>
</Stack>
<HStack spacing={4} align="flex-start">
{!raidCleric ? (
<Heading size="sm" color="white">
Needs Cleric!
</Heading>
) : (
<Stack>
<Heading size="sm" color="white">
Cleric
</Heading>
<MemberAvatar member={raidCleric} />
</Stack>
)}

{!_.isEmpty(rolesRequired) && (
<Stack>
<HStack>
<Heading size="sm" color="white">
Roles Required
</Heading>
Expand All @@ -142,7 +129,20 @@ const RaidCard: React.FC<RaidProps> = ({ raid, consultation }: RaidProps) => {
/>
))}
</AvatarGroup>
</Stack>
</HStack>
)}

{!raidCleric ? (
<Heading size="sm" color="white">
Needs Cleric!
</Heading>
) : (
<HStack>
<Heading size="sm" color="white">
Cleric
</Heading>
<MemberAvatar member={raidCleric} />
</HStack>
)}

<Link href={link}>
Expand All @@ -154,7 +154,7 @@ const RaidCard: React.FC<RaidProps> = ({ raid, consultation }: RaidProps) => {
</Flex>
<Flex
direction="row"
width="90%"
// width="90%"
alignItems="center"
justifyContent="space-between"
>
Expand Down Expand Up @@ -212,12 +212,12 @@ const RaidCard: React.FC<RaidProps> = ({ raid, consultation }: RaidProps) => {
/>
<InfoStack label="Project Type" details={projectType || '-'} />
</SimpleGrid>
{/* display comment */}
{/* display update */}
<Flex direction="column">
{/* todo: display first comment, truncated, with careted date. Display full text inside tooltip */}
{/* todo: display first update, truncated, with careted date. Display full text inside tooltip */}
</Flex>
</Flex>
</Card>
</Box>
);
};

Expand Down
23 changes: 5 additions & 18 deletions apps/frontend/components/RaidPartyInfo/RaidPartyCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
IMember,
memberDisplayName,
} from '../../utils';
import MemberAvatar from '../MemberAvatar';

type RaidPartyCardProps = {
/*
Expand Down Expand Up @@ -99,21 +100,14 @@ const RaidPartyCard = ({
_hover={{ cursor: 'pointer', color: 'red.100' }}
transition="all ease-in-out 0.25"
>
{_.get(member, 'guildClass') && (
<RoleBadge
width="40px"
height="40px"
border="2px solid"
roleName={GUILD_CLASS_ICON[_.get(member, 'guildClass')]}
/>
)}
{member && <MemberAvatar member={member} />}

<Flex direction="column">
<Text as="span" color="white" fontSize="md">
{_.get(member, 'name')}
</Text>
<Text color="primary.500" fontSize="sm">
{GUILD_CLASS_DISPLAY[_.get(member, 'guildClass')]}
{GUILD_CLASS_DISPLAY[_.get(member, 'guildClass.guildClass')]}
</Text>
</Flex>
</HStack>
Expand Down Expand Up @@ -224,21 +218,14 @@ const RaidPartyCard = ({
_hover={{ cursor: 'pointer', color: 'red.100' }}
transition="all ease-in-out 0.25"
>
{_.get(member, 'guildClass') && (
<RoleBadge
width="40px"
height="40px"
border="2px solid"
roleName={GUILD_CLASS_ICON[_.get(member, 'guildClass')]}
/>
)}
{member && <MemberAvatar member={member} />}

<Flex direction="column">
<Text as="span" color="white" fontSize="md">
{_.get(member, 'name')}
</Text>
<Text color="primary.500" fontSize="sm">
{GUILD_CLASS_DISPLAY[_.get(member, 'guildClass')]}
{GUILD_CLASS_DISPLAY[_.get(member, 'guildClass.guildClass')]}
</Text>
</Flex>
</HStack>
Expand Down
4 changes: 2 additions & 2 deletions apps/frontend/components/RaidPartyInfo/RaidPartyInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ const RaidPartyInfo: React.FC<RaidInfoProps> = ({ raid }: RaidInfoProps) => {
const token = _.get(session, 'token');
const { data: members } = useSlimMemberList({ token });

const cleric = _.get(raid, 'memberByCleric');
const raidParty = _.map(_.get(raid, 'raidParty'), 'memberByMember');
const cleric = _.get(raid, 'cleric');
const raidParty = _.map(_.get(raid, 'raidParties'), 'member');

const removeLocalRole = (role) => {
setLocalRoles(localRoles.filter((r) => r !== role));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,22 @@ import React from 'react';
import { Flex, HStack, Text, Divider } from '@raidguild/design-system';
import { format } from 'date-fns';

interface RaidCommentProps {
interface RaidUpdateProps {
// id?: string;
comment: string;
commentedBy: {
update: string;
member: {
name: string;
};
// commentedRaid?: string;
createdAt: string;
// modifiedAt?: string;
}

const RaidComment: React.FC<RaidCommentProps> = ({
const RaidUpdate: React.FC<RaidUpdateProps> = ({
// id,
comment,
commentedBy,
// commentedRaid = 'Dungeon Master v1',
update,
member,
createdAt,
}: // modifiedAt,
RaidCommentProps) => {
}) => {
return (
<>
<Flex
Expand All @@ -37,12 +34,12 @@ RaidCommentProps) => {
width="100%"
>
<Text color="white" as="p" fontSize="md" maxWidth="60%">
{comment}
{update}
</Text>
<HStack spacing={1} color="gray.100">
<Text fontSize="smaller">{commentedBy.name} @</Text>
<Text fontSize="smaller">{member.name} @</Text>
<Text fontSize="smaller">
{createdAt && format(new Date(+createdAt), 'Pp')}
{createdAt && format(new Date(createdAt), 'Pp')}
</Text>
</HStack>
</HStack>
Expand All @@ -52,4 +49,4 @@ RaidCommentProps) => {
);
};

export default RaidComment;
export default RaidUpdate;
171 changes: 171 additions & 0 deletions apps/frontend/components/RaidUpdatesFeed.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
import React, { useState, useEffect, useMemo } from 'react';
import _ from 'lodash';
import {
Flex,
Box,
Stack,
Button,
Text,
Textarea,
HStack,
Heading,
useToast,
Accordion,
AccordionButton,
AccordionIcon,
AccordionItem,
AccordionPanel,
} from '@raidguild/design-system';
import { useForm } from 'react-hook-form';
import { IUpdate, IRaid } from '../utils';
import RaidUpdate from './RaidUpdates';
// import { isAfter } from 'date-fns';
import { useAccount } from 'wagmi';
// import { useInjectedProvider } from '../contexts/InjectedProviderContexts';

interface UpdatesProps {
raid: IRaid;
}

const RaidUpdatesFeed: React.FC<UpdatesProps> = ({ raid }) => {
// const { userData } = useInjectedProvider();
console.log(raid);
const updates = _.get(raid, 'updates', null);
const { address } = useAccount();
const localForm = useForm();
const { handleSubmit, setValue } = localForm;
const toast = useToast();
const [addUpdate, setAddUpdate] = useState<boolean>(false);
const [expanded, setExpanded] = useState(false);
const [sortedUpdates, setSortedUpdates] = useState<any[]>();

const updatesCount = useMemo(() => {
if (!sortedUpdates) return 0;
return sortedUpdates.length;
}, [sortedUpdates]);

useEffect(() => {
if (!_.isEmpty(updates)) {
setSortedUpdates(_.orderBy(updates, ['createdAt'], ['desc']));
}
}, [updates]);

const showUpdateBox = () => {
setAddUpdate(true);
};

const clearUpdate = () => {
setAddUpdate(false);
setValue('update', '');
};

const submitNewUpdate = async (values: any) => {
// const result = await createRecord('update', {
// update: values.update,
// member: userData.member.id,
// raid: raidId,
// });
};

return (
<Flex
direction="column"
width="100%"
justifyContent="center"
padding={8}
bg="gray.800"
rounded="md"
>
<Flex>
<Flex direction="row" align="center" justify="space-between" w="100%">
<Heading size="md" color="white">
Status Updates
</Heading>
<Box>
{addUpdate ? (
<HStack>
<Button onClick={clearUpdate} variant="outline">
Cancel
</Button>
<Button type="submit" form="updateForm">
Submit
</Button>
</HStack>
) : (
<Button onClick={showUpdateBox}>Add Update</Button>
)}
</Box>
</Flex>
</Flex>

<Flex my={4} w="100%">
{addUpdate && (
<Box
as="form"
id="updateForm"
onSubmit={handleSubmit(submitNewUpdate)}
w="100%"
>
<Stack spacing={4} w="100%">
<Textarea
name="update"
label="Update"
localForm={localForm}
placeholder="This raid has encountered Moloch."
/>
</Stack>
</Box>
)}
</Flex>
{updatesCount > 0 &&
sortedUpdates
?.slice(0, updatesCount > 4 ? 1 : updatesCount)
.map((c: IUpdate) => (
<Stack as="ul" width="100%" key={c.createdAt}>
<RaidUpdate
// id={c.id}
update={c.update}
member={c.member}
createdAt={c.createdAt}
// modifiedAt={c.modifiedAt}
/>
</Stack>
))}
{updatesCount > 4 && (
<Accordion allowMultiple onChange={() => setExpanded(!expanded)}>
<AccordionItem border="none" key={0}>
<h2>
<AccordionButton color="raid" paddingInline={0}>
<Box flex="1" textAlign="left" color="raid">
{expanded ? 'Hide' : 'Reveal'} {sortedUpdates?.length - 1}{' '}
Comments
</Box>
<AccordionIcon />
</AccordionButton>
</h2>
<AccordionPanel padding={0}>
{sortedUpdates?.slice(1).map((c) => (
<Stack as="ul" width="100%" key={c.createdAt}>
<RaidUpdate
// id={c.id}
update={c.update}
member={c.member}
createdAt={c.createdAt}
// modifiedAt={c.modifiedAt}
/>
</Stack>
))}
</AccordionPanel>
</AccordionItem>
</Accordion>
)}
{!sortedUpdates?.length && (
<Flex align="center" justify="center" w="100%" h="100px">
<Text>Leave the first update about this raid.</Text>
</Flex>
)}
</Flex>
);
};

export default RaidUpdatesFeed;
Loading

0 comments on commit 7f3420e

Please sign in to comment.