Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
community update complete
  • Loading branch information
nandcoder committed Apr 13, 2023
commit f9db793e8b77a99517433c4f75ed9ef01b85b8b2
38 changes: 27 additions & 11 deletions src/pages/Community/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import CreateRoundedIcon from '@mui/icons-material/CreateRounded';
import ChatBubbleOutlineRoundedIcon from '@mui/icons-material/ChatBubbleOutlineRounded';
import DeleteOutlineRoundedIcon from '@mui/icons-material/DeleteOutlineRounded';
import { Button, Card, Container, ListGroup, Modal } from 'react-bootstrap'
import { Button as BTN, Box, Avatar, FormControl, FormLabel, Select, FormErrorMessage, Input, useToast } from '@chakra-ui/react'
import { Button as BTN, Box, Avatar, FormControl, FormLabel, Select, FormErrorMessage, Input, useToast, Badge } from '@chakra-ui/react'
// import { Heading, useToast } from "@chakra-ui/react";

import { useForm } from "react-hook-form";
Expand All @@ -26,12 +26,12 @@ const Community = () => {
const {
handleSubmit,
register,
formState: { errors, isSubmitting },
formState: { errors },
// setError,
// clearErrors,
} = useForm({ resolver: addPostResolver });
useEffect(() => {
let temp = [];
const temp = [];
const groupIds = []
groups.forEach(grp => groupIds.push(grp.id))
db.collection("posts")
Expand All @@ -48,7 +48,7 @@ const Community = () => {
})
.finally(() => {
setPosts(temp)
console.log(temp);
// console.log(temp);
setLoading(false)
});
}, [user, requestPosts, groups]);
Expand All @@ -57,12 +57,21 @@ const Community = () => {
// }
const addPost = ({ group, msg, image }) => {
let groupData;
groups.forEach(grp => {
if (grp.id === group) {
groupData = grp;
if (group !== 'public') {
groups.forEach(grp => {
if (grp.id === group) {
groupData = grp;
}
});
} else {
groupData = {
id: 'public',
data: {
title: 'Public',
}
}
});
console.log(image);
}
// console.log(image);

const finalDoc = {
groupId: groupData.id,
Expand Down Expand Up @@ -133,6 +142,7 @@ const Community = () => {
{...register("group")}
/> */}
<Select isInvalid={errors.group} name='group' placeholder='Select group' {...register("group")} >
<option value={'public'}>Public</option>
{groups?.map((group) => (
<option key={group.id} value={group.id}>{group.data.title}</option>
))}
Expand Down Expand Up @@ -177,7 +187,7 @@ const Community = () => {
<Button variant="secondary" onClick={handleClose}>
Close
</Button>
<Button isLoading={isSubmitting} type="submit" variant="success">
<Button type="submit" variant="success">
Submit
</Button>
</Modal.Footer>
Expand Down Expand Up @@ -223,7 +233,13 @@ const Community = () => {
{loading ? <Loader /> : posts?.map((post) => (
<Card key={post.id} style={{ width: '100', margin: '10px auto' }}>
<Card.Body>
<Card.Title>{post.data.authorName}</Card.Title>
{Object.keys(users).length !== 0 && (
<Card.Title>
{users[post.data.authorId].name}
{' '}
<Badge borderRadius={'50px'} variant='outline' colorScheme={'green'}>{post.data.groupTitle}</Badge>
</Card.Title>
)}
<Card.Text>
{post.data.message}
</Card.Text>
Expand Down