-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f982ab4
commit 82f0639
Showing
5 changed files
with
181 additions
and
6 deletions.
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
client/src/pages/Communities/Single/components/FeedItem.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import React, { useEffect } from 'react' | ||
import { useSession } from '@clerk/clerk-react' | ||
import styled from '@emotion/styled' | ||
|
||
import { | ||
CommunityFeedItem, | ||
CommunityMemberAvatarLens, | ||
CommunityMemberIdLens, | ||
CommunityMemberNameLens, | ||
useLazyGetCommunityMemberQuery, | ||
} from '../../../../state/domains/communities' | ||
import { Avatar, Typography } from '@mui/material' | ||
|
||
const Item = styled.aside` | ||
width: 90%; | ||
margin: 0 auto; | ||
padding: 1.5rem; | ||
display: flex; | ||
flex-direction: column; | ||
` | ||
|
||
type Props = CommunityFeedItem & { | ||
communityId: string | ||
} | ||
|
||
const FeedItem = (item: Props) => { | ||
const [getCommunityMember, communityMemberResult] = | ||
useLazyGetCommunityMemberQuery() | ||
|
||
const { session } = useSession() | ||
|
||
useEffect(() => { | ||
const doWork = async () => { | ||
if (session) { | ||
const token = await session.getToken() | ||
|
||
if (token) { | ||
getCommunityMember({ | ||
community: item.communityId, | ||
member: item.author_id, | ||
token, | ||
}) | ||
} | ||
} | ||
} | ||
|
||
if (session) { | ||
doWork() | ||
} | ||
}, [session]) | ||
|
||
const data = communityMemberResult.currentData | ||
|
||
if (!data) { | ||
return 'Loading...' | ||
} | ||
|
||
const member: { [x: string]: any } = { | ||
avatar: CommunityMemberAvatarLens.get(data), | ||
name: CommunityMemberNameLens.get(data), | ||
id: CommunityMemberIdLens.get(data), | ||
} | ||
|
||
return ( | ||
<Item> | ||
<header> | ||
<Avatar src={member.avatar} alt={member.name} /> | ||
<Typography>{member.name}</Typography> | ||
</header> | ||
<main> | ||
<Typography component="div">{item.data.message as any}</Typography> | ||
</main> | ||
</Item> | ||
) | ||
} | ||
|
||
export default FeedItem |
70 changes: 70 additions & 0 deletions
70
client/src/pages/Communities/Single/components/FeedItemForm.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import React, { useCallback } from 'react' | ||
import styled from '@emotion/styled' | ||
import { Button, TextField } from '@mui/material' | ||
import { usePostFeedItemMutation } from '../../../../state/domains/communities' | ||
import { useSession } from '@clerk/clerk-react' | ||
|
||
const Form = styled.form` | ||
width: 100%; | ||
margin: 0 auto; | ||
max-width: 1440px; | ||
display: flex; | ||
flex-direction: column; | ||
padding: 1.5rem; | ||
align-items: center; | ||
` | ||
|
||
interface Props { | ||
communityId: string | ||
} | ||
|
||
const FeedItemForm = ({ communityId }: Props) => { | ||
const [submit] = usePostFeedItemMutation() | ||
const { session } = useSession() | ||
const handleFormSubmit: React.FormEventHandler = useCallback( | ||
async (e) => { | ||
e.preventDefault() | ||
if (session) { | ||
const token = await session.getToken() | ||
if (token) { | ||
const formData = new FormData(e.target as any) | ||
const body = { | ||
type: 'text', | ||
data: { | ||
message: formData.get('body'), | ||
}, | ||
} | ||
|
||
const request = { | ||
communityId, | ||
token, | ||
item: body, | ||
} | ||
|
||
submit(request) | ||
|
||
;(e.target as any).reset() | ||
} | ||
} | ||
}, | ||
[session], | ||
) | ||
|
||
return ( | ||
<Form onSubmit={handleFormSubmit}> | ||
<TextField | ||
name="body" | ||
label="What's on your mind?" | ||
fullWidth | ||
multiline | ||
minRows={4} | ||
sx={{ marginBottom: '1.5rem' }} | ||
/> | ||
<Button type="submit" variant="contained"> | ||
Share with Community | ||
</Button> | ||
</Form> | ||
) | ||
} | ||
|
||
export default FeedItemForm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters