Skip to content

Commit

Permalink
Tested and verified the functionality of the new reducer
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathaniel81 committed Mar 17, 2024
1 parent 3598bff commit b81cbf6
Show file tree
Hide file tree
Showing 25 changed files with 847 additions and 464 deletions.
Binary file modified backend/db.sqlite3
Binary file not shown.
201 changes: 0 additions & 201 deletions backend/frontend/dist/assets/index-ByRpPixD.js

This file was deleted.

1 change: 1 addition & 0 deletions backend/frontend/dist/assets/index-C1zTTvDq.css

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion backend/frontend/dist/assets/index-DBvmIWhi.css

This file was deleted.

232 changes: 232 additions & 0 deletions backend/frontend/dist/assets/index-X4iP4Nto.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions backend/frontend/dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Rabbit</title>
<script type="module" crossorigin src="/static/assets/index-ByRpPixD.js"></script>
<link rel="stylesheet" crossorigin href="/static/assets/index-DBvmIWhi.css">
<script type="module" crossorigin src="/assets/index-X4iP4Nto.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-C1zTTvDq.css">
</head>
<body>
<div id="root"></div>
Expand Down
33 changes: 33 additions & 0 deletions backend/frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions backend/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@
"axios": "^1.6.7",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.0",
"cmdk": "^1.0.0",
"date-fns": "^3.4.0",
"editorjs-react-renderer": "^3.5.1",
"lodash": "^4.17.21",
"lodash.debounce": "^4.0.8",
"lucide-react": "^0.349.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand All @@ -48,6 +51,7 @@
"zod": "^3.22.4"
},
"devDependencies": {
"@types/lodash": "^4.17.0",
"@types/node": "^20.11.25",
"@types/react": "^18.2.56",
"@types/react-dom": "^18.2.19",
Expand Down
3 changes: 0 additions & 3 deletions backend/frontend/src/components/AuthenticationModal.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Button } from '@/components/ui/Button'
import { Icons } from '@/components/Icons'
import { cn } from '@/lib/utils'
// import { useToast } from '@/hooks/use-toast'
import { X } from 'lucide-react'
import { FC } from 'react'
import { useSelector } from 'react-redux'
Expand All @@ -12,9 +11,7 @@ import { RootState } from '@/redux/rootReducer'


const AuthenticationModal: FC = () => {

const isLoading = false;
// const { toast } = useToast();
const modalState = useSelector((state: RootState) => state.modal);
const { isOpen, modalType } = modalState;
const dispatch = useDispatch();
Expand Down
112 changes: 56 additions & 56 deletions backend/frontend/src/components/CommentsSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,64 +11,64 @@ const CommentsSection = ({ post }: { post: Post }) => {

return (
<div className='flex flex-col gap-y-4 mt-4'>
<hr className='w-full h-px my-6' />
<CreateComment postId={post?.id ?? ''} />
<hr className='w-full h-px my-6' />
<CreateComment postId={post?.id ?? ''} />
<div className='flex flex-col gap-y-6 mt-4'>
{post?.comments
.filter((comment) => !comment.parent_comment)
.map((topLevelComment) => {
const topLevelCommentVotesAmt = topLevelComment.comment_votes.reduce(
(acc, vote) => {
if (vote.type === 'UP') return acc + 1;
if (vote.type === 'DOWN') return acc - 1;
return acc;
},
0
);
const topLevelCommentVote = topLevelComment.comment_votes.find(
(vote) => vote.user === user?.user_id
);

return (
<div key={topLevelComment.id} className='flex flex-col'>
<div className='mb-2'>
<PostComment
comment={topLevelComment}
currentVote={topLevelCommentVote}
votesAmt={topLevelCommentVotesAmt}
postId={post.id}
/>
</div>
{/* Render replies */}
{post.comments
.filter((comment) => comment.parent_comment?.id === topLevelComment.id)
.sort((a, b) => b.comment_votes.length - a.comment_votes.length)
.map((reply) => {
const replyVotesAmt = reply.comment_votes.reduce((acc, vote) => {
if (vote.type === 'UP') return acc + 1;
if (vote.type === 'DOWN') return acc - 1;
return acc;
}, 0);
const replyVote = reply.comment_votes.find(
(vote) => vote.user === user?.user_id
);
return (
<div
key={reply.id}
className='ml-2 py-2 pl-4 border-l-2 border-zinc-200'>
<PostComment
comment={reply}
currentVote={replyVote}
votesAmt={replyVotesAmt}
postId={post.id}
/>
</div>
);
})
}
{post?.comments
.filter((comment) => !comment.parent_comment)
.map((topLevelComment) => {
const topLevelCommentVotesAmt = topLevelComment.comment_votes.reduce(
(acc, vote) => {
if (vote.type === 'UP') return acc + 1;
if (vote.type === 'DOWN') return acc - 1;
return acc;
},
0
);
const topLevelCommentVote = topLevelComment.comment_votes.find(
(vote) => vote.user === user?.user_id
);

return (
<div key={topLevelComment.id} className='flex flex-col'>
<div className='mb-2'>
<PostComment
comment={topLevelComment}
currentVote={topLevelCommentVote}
votesAmt={topLevelCommentVotesAmt}
postId={post.id}
/>
</div>
);
})}
{/* Render replies */}
{post.comments
.filter((comment) => comment.parent_comment?.id === topLevelComment.id)
.sort((a, b) => b.comment_votes.length - a.comment_votes.length)
.map((reply) => {
const replyVotesAmt = reply.comment_votes.reduce((acc, vote) => {
if (vote.type === 'UP') return acc + 1;
if (vote.type === 'DOWN') return acc - 1;
return acc;
}, 0);
const replyVote = reply.comment_votes.find(
(vote) => vote.user === user?.user_id
);
return (
<div
key={reply.id}
className='ml-2 py-2 pl-4 border-l-2 border-zinc-200'>
<PostComment
comment={reply}
currentVote={replyVote}
votesAmt={replyVotesAmt}
postId={post.id}
/>
</div>
);
})
}
</div>
);
})}
</div>
</div>
);
Expand Down
13 changes: 6 additions & 7 deletions backend/frontend/src/components/CreateComment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const CreateComment: FC<CreateCommentProps> = ({ postId, replyToId }) => {
const dispatch = useDispatch<AppDispatch>();
const [input, setInput] = useState<string>('');


const { mutate: comment, isPending } = useMutation({
mutationFn: async ({ postId, content, replyToId }: CommentRequest) => {
const payload: CommentRequest = { postId, content, replyToId }
Expand All @@ -47,12 +46,12 @@ const CreateComment: FC<CreateCommentProps> = ({ postId, replyToId }) => {
onError: (err) => {
if (err instanceof AxiosError) {
if (err.response?.status === 401) {
dispatch(openModal('signin'))
return toast({
title: 'Unauthorized',
description: 'Please Login.',
variant: 'destructive',
});
dispatch(openModal('signin'))
return toast({
title: 'Unauthorized',
description: 'Please Login.',
variant: 'destructive',
});
}
}

Expand Down
21 changes: 21 additions & 0 deletions backend/frontend/src/components/Icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,26 @@ export const Icons = {
<path d='M1 1h22v22H1z' fill='none' />
</svg>
),
users: (props: LucideProps) => (
<svg {...props} viewBox="0 0 24 24">
<path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"/>
<circle cx="9" cy="7" r="4"/>
<path d="M22 21v-2a4 4 0 0 0-3-3.87"/>
<path d="M16 3.13a4 4 0 0 1 0 7.75"/>
</svg>
),
pencil: (props: LucideProps) => (
<svg {...props}
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M17 3a2.85 2.83 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5Z"/>
<path d="m15 5 4 4"/>
</svg>
),
commentReply: MessageSquare,
}
Loading

0 comments on commit b81cbf6

Please sign in to comment.