From ce2167914abc5d24fc0cee354d8d6291bc6bd9da Mon Sep 17 00:00:00 2001 From: Howard Sun Date: Fri, 14 Jun 2024 16:36:36 -0400 Subject: [PATCH 01/17] CHE-120 Added post count to individual threads Changes to be committed: modified: client/src/components/Forums/ThreadDetails/ThreadDetails.tsx --- .../src/components/Forums/ThreadDetails/ThreadDetails.tsx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/client/src/components/Forums/ThreadDetails/ThreadDetails.tsx b/client/src/components/Forums/ThreadDetails/ThreadDetails.tsx index 1ca8192..8096555 100644 --- a/client/src/components/Forums/ThreadDetails/ThreadDetails.tsx +++ b/client/src/components/Forums/ThreadDetails/ThreadDetails.tsx @@ -63,6 +63,9 @@ const ThreadDetail = ({ forumId, threadId }: ThreadDetailProps) => { if (error) return
Error: {error}
; if (!thread) return
Thread not found.
; + const totalPosts = posts.length + 1; + console.log(posts) + return (

{thread.title}

@@ -96,6 +99,9 @@ const ThreadDetail = ({ forumId, threadId }: ThreadDetailProps) => {
))} +
+ Total Posts: {totalPosts} +
); }; From dc1920d9c008b171df11cdb0d42f7f9a9eab37e8 Mon Sep 17 00:00:00 2001 From: Howard Sun Date: Sat, 15 Jun 2024 00:13:30 -0400 Subject: [PATCH 02/17] CHE-120 Working replies count on all threads, working on typing --- .../Forums/ThreadDetails/ThreadDetails.tsx | 5 +-- .../Forums/ThreadsDisplay/ThreadsDisplay.tsx | 10 +++++ server/controllers/forumController.ts | 41 ++++++++++++++++++- server/controllers/threadController.ts | 32 ++++++++++++++- 4 files changed, 81 insertions(+), 7 deletions(-) diff --git a/client/src/components/Forums/ThreadDetails/ThreadDetails.tsx b/client/src/components/Forums/ThreadDetails/ThreadDetails.tsx index 8096555..ecf01af 100644 --- a/client/src/components/Forums/ThreadDetails/ThreadDetails.tsx +++ b/client/src/components/Forums/ThreadDetails/ThreadDetails.tsx @@ -59,13 +59,12 @@ const ThreadDetail = ({ forumId, threadId }: ThreadDetailProps) => { } }; + const totalPosts = posts.length + 1; + if (loading) return
Loading...
; if (error) return
Error: {error}
; if (!thread) return
Thread not found.
; - const totalPosts = posts.length + 1; - console.log(posts) - return (

{thread.title}

diff --git a/client/src/components/Forums/ThreadsDisplay/ThreadsDisplay.tsx b/client/src/components/Forums/ThreadsDisplay/ThreadsDisplay.tsx index 8d9f439..81c1e39 100644 --- a/client/src/components/Forums/ThreadsDisplay/ThreadsDisplay.tsx +++ b/client/src/components/Forums/ThreadsDisplay/ThreadsDisplay.tsx @@ -48,6 +48,9 @@ const ThreadsDisplay = ({ forumId, onThreadSelect }: ThreadsDisplayProps) => { if (loading) return
Loading...
; if (error) return
Error: {error}
; + // console.log('Current forum', forum); + console.log('Fetched threads:', threads); + return (

@@ -73,6 +76,13 @@ const ThreadsDisplay = ({ forumId, onThreadSelect }: ThreadsDisplayProps) => { onClick={() => onThreadSelect(thread._id)} >

{thread.title}

+ + {thread.postCount === 0 + ? 'No replies' + : thread.postCount === 1 + ? '1 reply' + : `${thread.postCount} replies`} +

{thread.content}

Started by {thread.user.firstName} on{' '} diff --git a/server/controllers/forumController.ts b/server/controllers/forumController.ts index cb4a847..8c8f157 100644 --- a/server/controllers/forumController.ts +++ b/server/controllers/forumController.ts @@ -1,7 +1,9 @@ import { Request, Response, NextFunction } from 'express'; import Forum from '../models/forumModel'; import Thread from '../models/threadModel'; +import Post from '../models/postModel'; import { sortAndPopulate } from './helpers/queryHelpers'; +import mongoose from 'mongoose'; // ENDPOINT POST api/forums // PURPOSE Create a new forum @@ -51,12 +53,47 @@ const getForumById = async (req: Request, res: Response, next: NextFunction) => try { const forum = await Forum.findById(forumId); + if (!forum) { return res.status(404).json({ message: 'Forum not found' }); } - const threadsQuery = Thread.find({ forum: forumId }); - const threads = await sortAndPopulate(threadsQuery); + // const threadsQuery = Thread.find({ forum: forumId }); + // const threads = await sortAndPopulate(threadsQuery); + + const threads = await Thread.aggregate([ + { + $match: { + forum: new mongoose.Types.ObjectId(forumId), + }, + }, + { + $lookup: { + from: 'posts', + localField: '_id', + foreignField: 'thread', + as: 'posts', + }, + }, + { + $addFields: { + postCount: { $size: '$posts' }, + }, + }, + { + $project: { + posts: 0, + }, + }, + { + $sort: { + createdAt: -1, + }, + }, + ]); + + console.log('Forum ID:', forumId); + console.log('⭐Threads with Post Counts:', threads); res.status(200).json({ forum, threads }); } catch (error) { diff --git a/server/controllers/threadController.ts b/server/controllers/threadController.ts index 9ba69eb..729e062 100644 --- a/server/controllers/threadController.ts +++ b/server/controllers/threadController.ts @@ -39,8 +39,35 @@ const createThread = async (req: CustomRequest, res: Response, next: NextFunctio // ACCESS Private const getAllThreads = async (req: CustomRequest, res: Response, next: NextFunction) => { try { - const threadsQuery = Thread.find({}); - const threads = await sortAndPopulate(threadsQuery); + // const threadsQuery = Thread.find({}); + // const threads = await sortAndPopulate(threadsQuery); + + const threads = await Thread.aggregate([ + { + $lookup: { + from: 'posts', + localField: '_id', + foreignField: 'thread', + as: 'posts', + }, + }, + { + $addFields: { + postCount: { $size: '$posts' }, + }, + }, + { + $project: { + posts: 0, + }, + }, + { + $sort: { + createdAt: -1, + }, + }, + ]); + res.status(200).json(threads); } catch (error) { next({ @@ -60,6 +87,7 @@ const listThreadsByForumId = async (req: Request, res: Response, next: NextFunct try { const threadsQuery = Thread.find({ forum: forumId }); const threads = await sortAndPopulate(threadsQuery); + res.status(200).json(threads); } catch (error) { next({ From adc49469f5bf6134cf9c414153eb003d4185450f Mon Sep 17 00:00:00 2001 From: Howard Sun Date: Sat, 15 Jun 2024 00:59:43 -0400 Subject: [PATCH 03/17] CHE-120 - Removed comments and added queryHelper for mongoose aggregate operation to align with design --- .../Forums/ThreadsDisplay/ThreadsDisplay.tsx | 3 --- server/controllers/forumController.ts | 17 +++-------------- server/controllers/helpers/queryHelpers.ts | 12 +++++++++++- server/controllers/threadController.ts | 12 +++--------- 4 files changed, 17 insertions(+), 27 deletions(-) diff --git a/client/src/components/Forums/ThreadsDisplay/ThreadsDisplay.tsx b/client/src/components/Forums/ThreadsDisplay/ThreadsDisplay.tsx index 81c1e39..3a5e028 100644 --- a/client/src/components/Forums/ThreadsDisplay/ThreadsDisplay.tsx +++ b/client/src/components/Forums/ThreadsDisplay/ThreadsDisplay.tsx @@ -48,9 +48,6 @@ const ThreadsDisplay = ({ forumId, onThreadSelect }: ThreadsDisplayProps) => { if (loading) return
Loading...
; if (error) return
Error: {error}
; - // console.log('Current forum', forum); - console.log('Fetched threads:', threads); - return (

diff --git a/server/controllers/forumController.ts b/server/controllers/forumController.ts index 8c8f157..9661a1a 100644 --- a/server/controllers/forumController.ts +++ b/server/controllers/forumController.ts @@ -1,8 +1,7 @@ import { Request, Response, NextFunction } from 'express'; import Forum from '../models/forumModel'; import Thread from '../models/threadModel'; -import Post from '../models/postModel'; -import { sortAndPopulate } from './helpers/queryHelpers'; +import { sortAndPopulate, aggregateSort } from './helpers/queryHelpers'; import mongoose from 'mongoose'; // ENDPOINT POST api/forums @@ -58,10 +57,7 @@ const getForumById = async (req: Request, res: Response, next: NextFunction) => return res.status(404).json({ message: 'Forum not found' }); } - // const threadsQuery = Thread.find({ forum: forumId }); - // const threads = await sortAndPopulate(threadsQuery); - - const threads = await Thread.aggregate([ + const threadsAggregate = Thread.aggregate([ { $match: { forum: new mongoose.Types.ObjectId(forumId), @@ -85,15 +81,8 @@ const getForumById = async (req: Request, res: Response, next: NextFunction) => posts: 0, }, }, - { - $sort: { - createdAt: -1, - }, - }, ]); - - console.log('Forum ID:', forumId); - console.log('⭐Threads with Post Counts:', threads); + const threads = await aggregateSort(threadsAggregate, 'createdAt', -1); res.status(200).json({ forum, threads }); } catch (error) { diff --git a/server/controllers/helpers/queryHelpers.ts b/server/controllers/helpers/queryHelpers.ts index 4eefcb3..097bc34 100644 --- a/server/controllers/helpers/queryHelpers.ts +++ b/server/controllers/helpers/queryHelpers.ts @@ -1,7 +1,8 @@ -import mongoose, { Query } from "mongoose"; +import mongoose, { Query, Aggregate } from "mongoose"; type SortOrder = 1 | -1; +// ? Should the sortOrder here be number or SortOrder type? export const sortAndPopulate = ( query: Query, sortField: string = "createdAt", @@ -12,3 +13,12 @@ export const sortAndPopulate = ( const sortObj = { [sortField]: sortOrder } as { [key: string]: SortOrder }; return query.sort(sortObj).populate(populateField, selectFields).exec(); }; + +export const aggregateSort = ( + pipeline: Aggregate, + sortField: string = 'createdAt', + sortOrder: SortOrder = -1, +): Aggregate => { + const sortStage = { $sort: { [sortField]: sortOrder } }; + return pipeline.append(sortStage); +}; \ No newline at end of file diff --git a/server/controllers/threadController.ts b/server/controllers/threadController.ts index 729e062..740bcf0 100644 --- a/server/controllers/threadController.ts +++ b/server/controllers/threadController.ts @@ -2,7 +2,7 @@ import { Request, Response, NextFunction } from 'express'; import Post from '../models/postModel'; import Thread from '../models/threadModel'; import { CustomRequest } from '../types/customRequest'; -import { sortAndPopulate } from './helpers/queryHelpers'; +import { sortAndPopulate, aggregateSort } from './helpers/queryHelpers'; // ENDPOINT POST api/:forumId/threads // PURPOSE Create a new thread @@ -39,10 +39,8 @@ const createThread = async (req: CustomRequest, res: Response, next: NextFunctio // ACCESS Private const getAllThreads = async (req: CustomRequest, res: Response, next: NextFunction) => { try { - // const threadsQuery = Thread.find({}); - // const threads = await sortAndPopulate(threadsQuery); - const threads = await Thread.aggregate([ + const threadsAggregate = Thread.aggregate([ { $lookup: { from: 'posts', @@ -61,12 +59,8 @@ const getAllThreads = async (req: CustomRequest, res: Response, next: NextFuncti posts: 0, }, }, - { - $sort: { - createdAt: -1, - }, - }, ]); + const threads = await aggregateSort(threadsAggregate, 'createdAt', -1); res.status(200).json(threads); } catch (error) { From c09cb3567737708518e3090fd2475db043d616ba Mon Sep 17 00:00:00 2001 From: Howard Sun Date: Sat, 15 Jun 2024 17:01:08 -0400 Subject: [PATCH 04/17] CHE-120 modified location of reply --- 110_120_diff.diff | 176 ++++++++++++++++++ .../Forums/ThreadsDisplay/ThreadsDisplay.tsx | 9 +- 2 files changed, 180 insertions(+), 5 deletions(-) create mode 100644 110_120_diff.diff diff --git a/110_120_diff.diff b/110_120_diff.diff new file mode 100644 index 0000000..b526d51 --- /dev/null +++ b/110_120_diff.diff @@ -0,0 +1,176 @@ +diff --git a/client/src/components/Forums/ThreadDetails/ThreadDetails.tsx b/client/src/components/Forums/ThreadDetails/ThreadDetails.tsx +index 1ca8192..ecf01af 100644 +--- a/client/src/components/Forums/ThreadDetails/ThreadDetails.tsx ++++ b/client/src/components/Forums/ThreadDetails/ThreadDetails.tsx +@@ -59,6 +59,8 @@ const ThreadDetail = ({ forumId, threadId }: ThreadDetailProps) => { + } + }; + ++ const totalPosts = posts.length + 1; ++ + if (loading) return
Loading...
; + if (error) return
Error: {error}
; + if (!thread) return
Thread not found.
; +@@ -96,6 +98,9 @@ const ThreadDetail = ({ forumId, threadId }: ThreadDetailProps) => { +

+ ))} +
++
++ Total Posts: {totalPosts} ++
+
+ ); + }; +diff --git a/client/src/components/Forums/ThreadsDisplay/ThreadsDisplay.tsx b/client/src/components/Forums/ThreadsDisplay/ThreadsDisplay.tsx +index 8d9f439..3a5e028 100644 +--- a/client/src/components/Forums/ThreadsDisplay/ThreadsDisplay.tsx ++++ b/client/src/components/Forums/ThreadsDisplay/ThreadsDisplay.tsx +@@ -73,6 +73,13 @@ const ThreadsDisplay = ({ forumId, onThreadSelect }: ThreadsDisplayProps) => { + onClick={() => onThreadSelect(thread._id)} + > +

{thread.title}

++ ++ {thread.postCount === 0 ++ ? 'No replies' ++ : thread.postCount === 1 ++ ? '1 reply' ++ : `${thread.postCount} replies`} ++ +

{thread.content}

+ + Started by {thread.user.firstName} on{' '} +diff --git a/server/controllers/forumController.ts b/server/controllers/forumController.ts +index cb4a847..9661a1a 100644 +--- a/server/controllers/forumController.ts ++++ b/server/controllers/forumController.ts +@@ -1,7 +1,8 @@ + import { Request, Response, NextFunction } from 'express'; + import Forum from '../models/forumModel'; + import Thread from '../models/threadModel'; +-import { sortAndPopulate } from './helpers/queryHelpers'; ++import { sortAndPopulate, aggregateSort } from './helpers/queryHelpers'; ++import mongoose from 'mongoose'; + + // ENDPOINT POST api/forums + // PURPOSE Create a new forum +@@ -51,12 +52,37 @@ const getForumById = async (req: Request, res: Response, next: NextFunction) => + + try { + const forum = await Forum.findById(forumId); ++ + if (!forum) { + return res.status(404).json({ message: 'Forum not found' }); + } + +- const threadsQuery = Thread.find({ forum: forumId }); +- const threads = await sortAndPopulate(threadsQuery); ++ const threadsAggregate = Thread.aggregate([ ++ { ++ $match: { ++ forum: new mongoose.Types.ObjectId(forumId), ++ }, ++ }, ++ { ++ $lookup: { ++ from: 'posts', ++ localField: '_id', ++ foreignField: 'thread', ++ as: 'posts', ++ }, ++ }, ++ { ++ $addFields: { ++ postCount: { $size: '$posts' }, ++ }, ++ }, ++ { ++ $project: { ++ posts: 0, ++ }, ++ }, ++ ]); ++ const threads = await aggregateSort(threadsAggregate, 'createdAt', -1); + + res.status(200).json({ forum, threads }); + } catch (error) { +diff --git a/server/controllers/helpers/queryHelpers.ts b/server/controllers/helpers/queryHelpers.ts +index 4eefcb3..097bc34 100644 +--- a/server/controllers/helpers/queryHelpers.ts ++++ b/server/controllers/helpers/queryHelpers.ts +@@ -1,7 +1,8 @@ +-import mongoose, { Query } from "mongoose"; ++import mongoose, { Query, Aggregate } from "mongoose"; + + type SortOrder = 1 | -1; + ++// ? Should the sortOrder here be number or SortOrder type? + export const sortAndPopulate = ( + query: Query, + sortField: string = "createdAt", +@@ -12,3 +13,12 @@ export const sortAndPopulate = ( + const sortObj = { [sortField]: sortOrder } as { [key: string]: SortOrder }; + return query.sort(sortObj).populate(populateField, selectFields).exec(); + }; ++ ++export const aggregateSort = ( ++ pipeline: Aggregate, ++ sortField: string = 'createdAt', ++ sortOrder: SortOrder = -1, ++): Aggregate => { ++ const sortStage = { $sort: { [sortField]: sortOrder } }; ++ return pipeline.append(sortStage); ++}; +\ No newline at end of file +diff --git a/server/controllers/threadController.ts b/server/controllers/threadController.ts +index 9ba69eb..740bcf0 100644 +--- a/server/controllers/threadController.ts ++++ b/server/controllers/threadController.ts +@@ -2,7 +2,7 @@ import { Request, Response, NextFunction } from 'express'; + import Post from '../models/postModel'; + import Thread from '../models/threadModel'; + import { CustomRequest } from '../types/customRequest'; +-import { sortAndPopulate } from './helpers/queryHelpers'; ++import { sortAndPopulate, aggregateSort } from './helpers/queryHelpers'; + + // ENDPOINT POST api/:forumId/threads + // PURPOSE Create a new thread +@@ -39,8 +39,29 @@ const createThread = async (req: CustomRequest, res: Response, next: NextFunctio + // ACCESS Private + const getAllThreads = async (req: CustomRequest, res: Response, next: NextFunction) => { + try { +- const threadsQuery = Thread.find({}); +- const threads = await sortAndPopulate(threadsQuery); ++ ++ const threadsAggregate = Thread.aggregate([ ++ { ++ $lookup: { ++ from: 'posts', ++ localField: '_id', ++ foreignField: 'thread', ++ as: 'posts', ++ }, ++ }, ++ { ++ $addFields: { ++ postCount: { $size: '$posts' }, ++ }, ++ }, ++ { ++ $project: { ++ posts: 0, ++ }, ++ }, ++ ]); ++ const threads = await aggregateSort(threadsAggregate, 'createdAt', -1); ++ + res.status(200).json(threads); + } catch (error) { + next({ +@@ -60,6 +81,7 @@ const listThreadsByForumId = async (req: Request, res: Response, next: NextFunct + try { + const threadsQuery = Thread.find({ forum: forumId }); + const threads = await sortAndPopulate(threadsQuery); ++ + res.status(200).json(threads); + } catch (error) { + next({ diff --git a/client/src/components/Forums/ThreadsDisplay/ThreadsDisplay.tsx b/client/src/components/Forums/ThreadsDisplay/ThreadsDisplay.tsx index 3a5e028..27cc199 100644 --- a/client/src/components/Forums/ThreadsDisplay/ThreadsDisplay.tsx +++ b/client/src/components/Forums/ThreadsDisplay/ThreadsDisplay.tsx @@ -73,18 +73,17 @@ const ThreadsDisplay = ({ forumId, onThreadSelect }: ThreadsDisplayProps) => { onClick={() => onThreadSelect(thread._id)} >

{thread.title}

+

{thread.content}

+ Started by {thread.user.firstName} on{' '} + {new Date(thread.createdAt).toLocaleDateString()} +  |  {thread.postCount === 0 ? 'No replies' : thread.postCount === 1 ? '1 reply' : `${thread.postCount} replies`} -

{thread.content}

- - Started by {thread.user.firstName} on{' '} - {new Date(thread.createdAt).toLocaleDateString()} - ))} From 27678febf560d7a691705f91ec865d37d945d6a4 Mon Sep 17 00:00:00 2001 From: Howard Sun Date: Sat, 15 Jun 2024 17:02:20 -0400 Subject: [PATCH 05/17] CHE-120 removed diff file --- 110_120_diff.diff | 176 ---------------------------------------------- 1 file changed, 176 deletions(-) delete mode 100644 110_120_diff.diff diff --git a/110_120_diff.diff b/110_120_diff.diff deleted file mode 100644 index b526d51..0000000 --- a/110_120_diff.diff +++ /dev/null @@ -1,176 +0,0 @@ -diff --git a/client/src/components/Forums/ThreadDetails/ThreadDetails.tsx b/client/src/components/Forums/ThreadDetails/ThreadDetails.tsx -index 1ca8192..ecf01af 100644 ---- a/client/src/components/Forums/ThreadDetails/ThreadDetails.tsx -+++ b/client/src/components/Forums/ThreadDetails/ThreadDetails.tsx -@@ -59,6 +59,8 @@ const ThreadDetail = ({ forumId, threadId }: ThreadDetailProps) => { - } - }; - -+ const totalPosts = posts.length + 1; -+ - if (loading) return
Loading...
; - if (error) return
Error: {error}
; - if (!thread) return
Thread not found.
; -@@ -96,6 +98,9 @@ const ThreadDetail = ({ forumId, threadId }: ThreadDetailProps) => { - - ))} - -+
-+ Total Posts: {totalPosts} -+
- - ); - }; -diff --git a/client/src/components/Forums/ThreadsDisplay/ThreadsDisplay.tsx b/client/src/components/Forums/ThreadsDisplay/ThreadsDisplay.tsx -index 8d9f439..3a5e028 100644 ---- a/client/src/components/Forums/ThreadsDisplay/ThreadsDisplay.tsx -+++ b/client/src/components/Forums/ThreadsDisplay/ThreadsDisplay.tsx -@@ -73,6 +73,13 @@ const ThreadsDisplay = ({ forumId, onThreadSelect }: ThreadsDisplayProps) => { - onClick={() => onThreadSelect(thread._id)} - > -

{thread.title}

-+ -+ {thread.postCount === 0 -+ ? 'No replies' -+ : thread.postCount === 1 -+ ? '1 reply' -+ : `${thread.postCount} replies`} -+ -

{thread.content}

- - Started by {thread.user.firstName} on{' '} -diff --git a/server/controllers/forumController.ts b/server/controllers/forumController.ts -index cb4a847..9661a1a 100644 ---- a/server/controllers/forumController.ts -+++ b/server/controllers/forumController.ts -@@ -1,7 +1,8 @@ - import { Request, Response, NextFunction } from 'express'; - import Forum from '../models/forumModel'; - import Thread from '../models/threadModel'; --import { sortAndPopulate } from './helpers/queryHelpers'; -+import { sortAndPopulate, aggregateSort } from './helpers/queryHelpers'; -+import mongoose from 'mongoose'; - - // ENDPOINT POST api/forums - // PURPOSE Create a new forum -@@ -51,12 +52,37 @@ const getForumById = async (req: Request, res: Response, next: NextFunction) => - - try { - const forum = await Forum.findById(forumId); -+ - if (!forum) { - return res.status(404).json({ message: 'Forum not found' }); - } - -- const threadsQuery = Thread.find({ forum: forumId }); -- const threads = await sortAndPopulate(threadsQuery); -+ const threadsAggregate = Thread.aggregate([ -+ { -+ $match: { -+ forum: new mongoose.Types.ObjectId(forumId), -+ }, -+ }, -+ { -+ $lookup: { -+ from: 'posts', -+ localField: '_id', -+ foreignField: 'thread', -+ as: 'posts', -+ }, -+ }, -+ { -+ $addFields: { -+ postCount: { $size: '$posts' }, -+ }, -+ }, -+ { -+ $project: { -+ posts: 0, -+ }, -+ }, -+ ]); -+ const threads = await aggregateSort(threadsAggregate, 'createdAt', -1); - - res.status(200).json({ forum, threads }); - } catch (error) { -diff --git a/server/controllers/helpers/queryHelpers.ts b/server/controllers/helpers/queryHelpers.ts -index 4eefcb3..097bc34 100644 ---- a/server/controllers/helpers/queryHelpers.ts -+++ b/server/controllers/helpers/queryHelpers.ts -@@ -1,7 +1,8 @@ --import mongoose, { Query } from "mongoose"; -+import mongoose, { Query, Aggregate } from "mongoose"; - - type SortOrder = 1 | -1; - -+// ? Should the sortOrder here be number or SortOrder type? - export const sortAndPopulate = ( - query: Query, - sortField: string = "createdAt", -@@ -12,3 +13,12 @@ export const sortAndPopulate = ( - const sortObj = { [sortField]: sortOrder } as { [key: string]: SortOrder }; - return query.sort(sortObj).populate(populateField, selectFields).exec(); - }; -+ -+export const aggregateSort = ( -+ pipeline: Aggregate, -+ sortField: string = 'createdAt', -+ sortOrder: SortOrder = -1, -+): Aggregate => { -+ const sortStage = { $sort: { [sortField]: sortOrder } }; -+ return pipeline.append(sortStage); -+}; -\ No newline at end of file -diff --git a/server/controllers/threadController.ts b/server/controllers/threadController.ts -index 9ba69eb..740bcf0 100644 ---- a/server/controllers/threadController.ts -+++ b/server/controllers/threadController.ts -@@ -2,7 +2,7 @@ import { Request, Response, NextFunction } from 'express'; - import Post from '../models/postModel'; - import Thread from '../models/threadModel'; - import { CustomRequest } from '../types/customRequest'; --import { sortAndPopulate } from './helpers/queryHelpers'; -+import { sortAndPopulate, aggregateSort } from './helpers/queryHelpers'; - - // ENDPOINT POST api/:forumId/threads - // PURPOSE Create a new thread -@@ -39,8 +39,29 @@ const createThread = async (req: CustomRequest, res: Response, next: NextFunctio - // ACCESS Private - const getAllThreads = async (req: CustomRequest, res: Response, next: NextFunction) => { - try { -- const threadsQuery = Thread.find({}); -- const threads = await sortAndPopulate(threadsQuery); -+ -+ const threadsAggregate = Thread.aggregate([ -+ { -+ $lookup: { -+ from: 'posts', -+ localField: '_id', -+ foreignField: 'thread', -+ as: 'posts', -+ }, -+ }, -+ { -+ $addFields: { -+ postCount: { $size: '$posts' }, -+ }, -+ }, -+ { -+ $project: { -+ posts: 0, -+ }, -+ }, -+ ]); -+ const threads = await aggregateSort(threadsAggregate, 'createdAt', -1); -+ - res.status(200).json(threads); - } catch (error) { - next({ -@@ -60,6 +81,7 @@ const listThreadsByForumId = async (req: Request, res: Response, next: NextFunct - try { - const threadsQuery = Thread.find({ forum: forumId }); - const threads = await sortAndPopulate(threadsQuery); -+ - res.status(200).json(threads); - } catch (error) { - next({ From 768ba565f788bf7e087bc0f8498c666cd2c9188f Mon Sep 17 00:00:00 2001 From: Howard Sun Date: Sat, 15 Jun 2024 17:47:21 -0400 Subject: [PATCH 06/17] CHE-120 added changes from CHE-129 to avoid merge conflict --- server/controllers/helpers/queryHelpers.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/server/controllers/helpers/queryHelpers.ts b/server/controllers/helpers/queryHelpers.ts index 097bc34..7b08ce7 100644 --- a/server/controllers/helpers/queryHelpers.ts +++ b/server/controllers/helpers/queryHelpers.ts @@ -2,13 +2,18 @@ import mongoose, { Query, Aggregate } from "mongoose"; type SortOrder = 1 | -1; -// ? Should the sortOrder here be number or SortOrder type? -export const sortAndPopulate = ( - query: Query, - sortField: string = "createdAt", +interface SortAndPopulateQuery { + sort: (arg: { [key: string]: SortOrder }) => SortAndPopulateQuery; + populate: (field: string, select?: string) => SortAndPopulateQuery; + exec: () => Promise; +} + +export const sortAndPopulate = ( + query: SortAndPopulateQuery, + sortField: string = 'createdAt', sortOrder: number = -1, - populateField: string = "user", - selectFields: string = "firstName lastName" + populateField: string = 'user', + selectFields: string = 'firstName lastName', ) => { const sortObj = { [sortField]: sortOrder } as { [key: string]: SortOrder }; return query.sort(sortObj).populate(populateField, selectFields).exec(); From 3ff59803801ac9ca8acaf55a307b7f894ae8ea9d Mon Sep 17 00:00:00 2001 From: Howard Sun Date: Sat, 15 Jun 2024 22:30:33 -0400 Subject: [PATCH 07/17] CHE-120 modified queryHelper with custom AggregateQuery interface, removed mongoose Aggregate type --- server/controllers/forumController.ts | 2 +- server/controllers/helpers/queryHelpers.ts | 23 +++++++++++++++------- server/controllers/threadController.ts | 3 ++- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/server/controllers/forumController.ts b/server/controllers/forumController.ts index 9661a1a..15da236 100644 --- a/server/controllers/forumController.ts +++ b/server/controllers/forumController.ts @@ -82,7 +82,7 @@ const getForumById = async (req: Request, res: Response, next: NextFunction) => }, }, ]); - const threads = await aggregateSort(threadsAggregate, 'createdAt', -1); + const threads = await aggregateSort(threadsAggregate); res.status(200).json({ forum, threads }); } catch (error) { diff --git a/server/controllers/helpers/queryHelpers.ts b/server/controllers/helpers/queryHelpers.ts index 7b08ce7..f81301a 100644 --- a/server/controllers/helpers/queryHelpers.ts +++ b/server/controllers/helpers/queryHelpers.ts @@ -1,5 +1,3 @@ -import mongoose, { Query, Aggregate } from "mongoose"; - type SortOrder = 1 | -1; interface SortAndPopulateQuery { @@ -7,6 +5,17 @@ interface SortAndPopulateQuery { populate: (field: string, select?: string) => SortAndPopulateQuery; exec: () => Promise; } +interface AggregateQuery { + sort: (arg: { [key: string]: SortOrder }) => AggregateQuery; + project: (field: { [key: string]: 0 | 1 }) => AggregateQuery; + lookup: (lookupOptions: { + from: string, + localField: string, + foreignField: string, + as: string + }) => AggregateQuery; + exec: () => Promise; +} export const sortAndPopulate = ( query: SortAndPopulateQuery, @@ -19,11 +28,11 @@ export const sortAndPopulate = ( return query.sort(sortObj).populate(populateField, selectFields).exec(); }; -export const aggregateSort = ( - pipeline: Aggregate, +export const aggregateSort = ( + pipeline: AggregateQuery, sortField: string = 'createdAt', sortOrder: SortOrder = -1, -): Aggregate => { - const sortStage = { $sort: { [sortField]: sortOrder } }; - return pipeline.append(sortStage); +) => { + const sortObj: Record = { [sortField]: sortOrder } + return pipeline.sort(sortObj).exec(); }; \ No newline at end of file diff --git a/server/controllers/threadController.ts b/server/controllers/threadController.ts index 740bcf0..d49fbdd 100644 --- a/server/controllers/threadController.ts +++ b/server/controllers/threadController.ts @@ -60,7 +60,8 @@ const getAllThreads = async (req: CustomRequest, res: Response, next: NextFuncti }, }, ]); - const threads = await aggregateSort(threadsAggregate, 'createdAt', -1); + const threads = await aggregateSort(threadsAggregate); + // console.log(threads) res.status(200).json(threads); } catch (error) { From 3583784e55a442f1f3f5d86c1bb40f37b4742a08 Mon Sep 17 00:00:00 2001 From: Howard Sun Date: Sat, 15 Jun 2024 22:32:01 -0400 Subject: [PATCH 08/17] CHE-120 modified queryHelper with custom AggregateQuery interface, removed mongoose Aggregate type, fixed typos --- server/controllers/helpers/queryHelpers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/controllers/helpers/queryHelpers.ts b/server/controllers/helpers/queryHelpers.ts index f81301a..67e4f5a 100644 --- a/server/controllers/helpers/queryHelpers.ts +++ b/server/controllers/helpers/queryHelpers.ts @@ -33,6 +33,6 @@ export const aggregateSort = ( sortField: string = 'createdAt', sortOrder: SortOrder = -1, ) => { - const sortObj: Record = { [sortField]: sortOrder } + const sortObj: Record = { [sortField]: sortOrder }; return pipeline.sort(sortObj).exec(); }; \ No newline at end of file From 1cd19a5d2a1ca36ff84374fbc9629ee01f54ec97 Mon Sep 17 00:00:00 2001 From: Howard Sun Date: Sat, 15 Jun 2024 22:32:48 -0400 Subject: [PATCH 09/17] CHE-120 modified queryHelper with custom AggregateQuery interface, removed mongoose Aggregate type, removed console logs --- server/controllers/threadController.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/server/controllers/threadController.ts b/server/controllers/threadController.ts index d49fbdd..afce940 100644 --- a/server/controllers/threadController.ts +++ b/server/controllers/threadController.ts @@ -61,7 +61,6 @@ const getAllThreads = async (req: CustomRequest, res: Response, next: NextFuncti }, ]); const threads = await aggregateSort(threadsAggregate); - // console.log(threads) res.status(200).json(threads); } catch (error) { From 7f54c7a2ad2c8310efeab792abfc4ecc07a8b38d Mon Sep 17 00:00:00 2001 From: Howard Sun Date: Sat, 15 Jun 2024 22:51:17 -0400 Subject: [PATCH 10/17] CHE-120 fixed formatting --- server/controllers/helpers/queryHelpers.ts | 10 +++++----- server/controllers/threadController.ts | 1 - 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/server/controllers/helpers/queryHelpers.ts b/server/controllers/helpers/queryHelpers.ts index 67e4f5a..0dfadab 100644 --- a/server/controllers/helpers/queryHelpers.ts +++ b/server/controllers/helpers/queryHelpers.ts @@ -9,10 +9,10 @@ interface AggregateQuery { sort: (arg: { [key: string]: SortOrder }) => AggregateQuery; project: (field: { [key: string]: 0 | 1 }) => AggregateQuery; lookup: (lookupOptions: { - from: string, - localField: string, - foreignField: string, - as: string + from: string; + localField: string; + foreignField: string; + as: string; }) => AggregateQuery; exec: () => Promise; } @@ -35,4 +35,4 @@ export const aggregateSort = ( ) => { const sortObj: Record = { [sortField]: sortOrder }; return pipeline.sort(sortObj).exec(); -}; \ No newline at end of file +}; diff --git a/server/controllers/threadController.ts b/server/controllers/threadController.ts index afce940..b28122a 100644 --- a/server/controllers/threadController.ts +++ b/server/controllers/threadController.ts @@ -39,7 +39,6 @@ const createThread = async (req: CustomRequest, res: Response, next: NextFunctio // ACCESS Private const getAllThreads = async (req: CustomRequest, res: Response, next: NextFunction) => { try { - const threadsAggregate = Thread.aggregate([ { $lookup: { From 2df97da474d88f6474f444fadce55221a0449e3c Mon Sep 17 00:00:00 2001 From: Howard Sun Date: Sat, 15 Jun 2024 23:02:53 -0400 Subject: [PATCH 11/17] CHE-120 Moved inline logic to separate function and added Tailwind separators --- .../Forums/ThreadsDisplay/ThreadsDisplay.tsx | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/client/src/components/Forums/ThreadsDisplay/ThreadsDisplay.tsx b/client/src/components/Forums/ThreadsDisplay/ThreadsDisplay.tsx index 27cc199..62ba8f6 100644 --- a/client/src/components/Forums/ThreadsDisplay/ThreadsDisplay.tsx +++ b/client/src/components/Forums/ThreadsDisplay/ThreadsDisplay.tsx @@ -45,6 +45,12 @@ const ThreadsDisplay = ({ forumId, onThreadSelect }: ThreadsDisplayProps) => { setCreatingThread(!creatingThread); }; + function formatReplies(count) { + if (count === 0) return 'No replies'; + if (count === 1) return '1 reply'; + return `${count} replies`; + } + if (loading) return
Loading...
; if (error) return
Error: {error}
; @@ -77,12 +83,8 @@ const ThreadsDisplay = ({ forumId, onThreadSelect }: ThreadsDisplayProps) => { Started by {thread.user.firstName} on{' '} {new Date(thread.createdAt).toLocaleDateString()} -  |  - {thread.postCount === 0 - ? 'No replies' - : thread.postCount === 1 - ? '1 reply' - : `${thread.postCount} replies`} + | + {formatReplies(thread.postCount)} ))} From 613da2ddb868c5f5b4c4488fec042c49779f143d Mon Sep 17 00:00:00 2001 From: Howard Sun Date: Sat, 15 Jun 2024 23:58:38 -0400 Subject: [PATCH 12/17] CHE-120 changed styling --- client/src/components/Forums/ThreadsDisplay/ThreadsDisplay.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/components/Forums/ThreadsDisplay/ThreadsDisplay.tsx b/client/src/components/Forums/ThreadsDisplay/ThreadsDisplay.tsx index 62ba8f6..2177c1e 100644 --- a/client/src/components/Forums/ThreadsDisplay/ThreadsDisplay.tsx +++ b/client/src/components/Forums/ThreadsDisplay/ThreadsDisplay.tsx @@ -84,7 +84,7 @@ const ThreadsDisplay = ({ forumId, onThreadSelect }: ThreadsDisplayProps) => { Started by {thread.user.firstName} on{' '} {new Date(thread.createdAt).toLocaleDateString()} | - {formatReplies(thread.postCount)} + {formatReplies(thread.postCount)}
))} From 2881ae73f203d90cb3f725658cbae716320220c2 Mon Sep 17 00:00:00 2001 From: Howard Sun Date: Mon, 17 Jun 2024 16:23:39 -0400 Subject: [PATCH 13/17] CHE-120 added typing to post-reply to pass tests --- client/src/components/Forums/ThreadDetails/ThreadDetails.tsx | 2 +- client/src/components/Forums/ThreadsDisplay/ThreadsDisplay.tsx | 2 +- client/types/forums.ts | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/client/src/components/Forums/ThreadDetails/ThreadDetails.tsx b/client/src/components/Forums/ThreadDetails/ThreadDetails.tsx index ecf01af..f655256 100644 --- a/client/src/components/Forums/ThreadDetails/ThreadDetails.tsx +++ b/client/src/components/Forums/ThreadDetails/ThreadDetails.tsx @@ -59,7 +59,7 @@ const ThreadDetail = ({ forumId, threadId }: ThreadDetailProps) => { } }; - const totalPosts = posts.length + 1; + const totalPosts: number = posts.length + 1; if (loading) return
Loading...
; if (error) return
Error: {error}
; diff --git a/client/src/components/Forums/ThreadsDisplay/ThreadsDisplay.tsx b/client/src/components/Forums/ThreadsDisplay/ThreadsDisplay.tsx index 2177c1e..2bf2bd5 100644 --- a/client/src/components/Forums/ThreadsDisplay/ThreadsDisplay.tsx +++ b/client/src/components/Forums/ThreadsDisplay/ThreadsDisplay.tsx @@ -45,7 +45,7 @@ const ThreadsDisplay = ({ forumId, onThreadSelect }: ThreadsDisplayProps) => { setCreatingThread(!creatingThread); }; - function formatReplies(count) { + function formatReplies(count: number) { if (count === 0) return 'No replies'; if (count === 1) return '1 reply'; return `${count} replies`; diff --git a/client/types/forums.ts b/client/types/forums.ts index 496cfea..6e30beb 100644 --- a/client/types/forums.ts +++ b/client/types/forums.ts @@ -12,6 +12,7 @@ export interface Thread { content: string; user: IUser; createdAt: string; + postCount: number; } export interface IForum { From a09baacad5888adf99c6b5eed15bbd2e2c119aca Mon Sep 17 00:00:00 2001 From: Howard Sun Date: Mon, 17 Jun 2024 16:54:11 -0400 Subject: [PATCH 14/17] CHE-120 removed unused imports --- client/src/components/Forums/ThreadDetails/ThreadDetails.tsx | 1 + server/controllers/forumController.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/client/src/components/Forums/ThreadDetails/ThreadDetails.tsx b/client/src/components/Forums/ThreadDetails/ThreadDetails.tsx index f655256..09c60c6 100644 --- a/client/src/components/Forums/ThreadDetails/ThreadDetails.tsx +++ b/client/src/components/Forums/ThreadDetails/ThreadDetails.tsx @@ -61,6 +61,7 @@ const ThreadDetail = ({ forumId, threadId }: ThreadDetailProps) => { const totalPosts: number = posts.length + 1; + if (pending) return null; if (loading) return
Loading...
; if (error) return
Error: {error}
; if (!thread) return
Thread not found.
; diff --git a/server/controllers/forumController.ts b/server/controllers/forumController.ts index 15da236..edd5c07 100644 --- a/server/controllers/forumController.ts +++ b/server/controllers/forumController.ts @@ -1,7 +1,7 @@ import { Request, Response, NextFunction } from 'express'; import Forum from '../models/forumModel'; import Thread from '../models/threadModel'; -import { sortAndPopulate, aggregateSort } from './helpers/queryHelpers'; +import { aggregateSort } from './helpers/queryHelpers'; import mongoose from 'mongoose'; // ENDPOINT POST api/forums From 96f66f8daed40eebc4548f2ebd0e414692e0ac30 Mon Sep 17 00:00:00 2001 From: Howard Sun Date: Tue, 18 Jun 2024 00:54:14 -0400 Subject: [PATCH 15/17] CHE-120 refactored aggregate query, moved into queryHelper with forumId as conditional --- server/controllers/forumController.ts | 31 ++--------------- server/controllers/helpers/queryHelpers.ts | 39 ++++++++++++++++++++++ server/controllers/threadController.ts | 24 ++----------- 3 files changed, 43 insertions(+), 51 deletions(-) diff --git a/server/controllers/forumController.ts b/server/controllers/forumController.ts index edd5c07..9d3f479 100644 --- a/server/controllers/forumController.ts +++ b/server/controllers/forumController.ts @@ -1,8 +1,6 @@ import { Request, Response, NextFunction } from 'express'; import Forum from '../models/forumModel'; -import Thread from '../models/threadModel'; -import { aggregateSort } from './helpers/queryHelpers'; -import mongoose from 'mongoose'; +import { aggregateThreadsWithPostCount } from './helpers/queryHelpers'; // ENDPOINT POST api/forums // PURPOSE Create a new forum @@ -57,32 +55,7 @@ const getForumById = async (req: Request, res: Response, next: NextFunction) => return res.status(404).json({ message: 'Forum not found' }); } - const threadsAggregate = Thread.aggregate([ - { - $match: { - forum: new mongoose.Types.ObjectId(forumId), - }, - }, - { - $lookup: { - from: 'posts', - localField: '_id', - foreignField: 'thread', - as: 'posts', - }, - }, - { - $addFields: { - postCount: { $size: '$posts' }, - }, - }, - { - $project: { - posts: 0, - }, - }, - ]); - const threads = await aggregateSort(threadsAggregate); + const threads = await aggregateThreadsWithPostCount(forumId); res.status(200).json({ forum, threads }); } catch (error) { diff --git a/server/controllers/helpers/queryHelpers.ts b/server/controllers/helpers/queryHelpers.ts index 0dfadab..b6e8d4a 100644 --- a/server/controllers/helpers/queryHelpers.ts +++ b/server/controllers/helpers/queryHelpers.ts @@ -1,3 +1,6 @@ +import Thread from '../../models/threadModel'; +import mongoose from 'mongoose'; + type SortOrder = 1 | -1; interface SortAndPopulateQuery { @@ -36,3 +39,39 @@ export const aggregateSort = ( const sortObj: Record = { [sortField]: sortOrder }; return pipeline.sort(sortObj).exec(); }; + +export const aggregateThreadsWithPostCount = (forumId?: string) => { + const baseStages = [ + { + $lookup: { + from: 'posts', + localField: '_id', + foreignField: 'thread', + as: 'posts', + }, + }, + { + $addFields: { + postCount: { $size: '$posts' }, + }, + }, + { + $project: { + posts: 0, + }, + }, + ]; + + const threadsAggregate = forumId + ? [ + { + $match: { + forum: new mongoose.Types.ObjectId(forumId), + }, + }, + ...baseStages, + ] + : baseStages; + + return aggregateSort(Thread.aggregate(threadsAggregate)); +}; diff --git a/server/controllers/threadController.ts b/server/controllers/threadController.ts index b28122a..027e58e 100644 --- a/server/controllers/threadController.ts +++ b/server/controllers/threadController.ts @@ -2,7 +2,7 @@ import { Request, Response, NextFunction } from 'express'; import Post from '../models/postModel'; import Thread from '../models/threadModel'; import { CustomRequest } from '../types/customRequest'; -import { sortAndPopulate, aggregateSort } from './helpers/queryHelpers'; +import { sortAndPopulate, aggregateThreadsWithPostCount } from './helpers/queryHelpers'; // ENDPOINT POST api/:forumId/threads // PURPOSE Create a new thread @@ -39,27 +39,7 @@ const createThread = async (req: CustomRequest, res: Response, next: NextFunctio // ACCESS Private const getAllThreads = async (req: CustomRequest, res: Response, next: NextFunction) => { try { - const threadsAggregate = Thread.aggregate([ - { - $lookup: { - from: 'posts', - localField: '_id', - foreignField: 'thread', - as: 'posts', - }, - }, - { - $addFields: { - postCount: { $size: '$posts' }, - }, - }, - { - $project: { - posts: 0, - }, - }, - ]); - const threads = await aggregateSort(threadsAggregate); + const threads = await aggregateThreadsWithPostCount(); res.status(200).json(threads); } catch (error) { From 1be0d3575cc2450157f03f5b96870d6a80311226 Mon Sep 17 00:00:00 2001 From: Howard Sun Date: Tue, 18 Jun 2024 01:04:14 -0400 Subject: [PATCH 16/17] CHE-120 added sorting params into aggregateThreadsWithPostCount to passthrough into aggregateSort --- server/controllers/forumController.ts | 2 +- server/controllers/helpers/queryHelpers.ts | 8 ++++++-- server/controllers/threadController.ts | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/server/controllers/forumController.ts b/server/controllers/forumController.ts index 9d3f479..c28a285 100644 --- a/server/controllers/forumController.ts +++ b/server/controllers/forumController.ts @@ -55,7 +55,7 @@ const getForumById = async (req: Request, res: Response, next: NextFunction) => return res.status(404).json({ message: 'Forum not found' }); } - const threads = await aggregateThreadsWithPostCount(forumId); + const threads = await aggregateThreadsWithPostCount(forumId, 'createdAt', -1); res.status(200).json({ forum, threads }); } catch (error) { diff --git a/server/controllers/helpers/queryHelpers.ts b/server/controllers/helpers/queryHelpers.ts index b6e8d4a..b43091b 100644 --- a/server/controllers/helpers/queryHelpers.ts +++ b/server/controllers/helpers/queryHelpers.ts @@ -40,7 +40,11 @@ export const aggregateSort = ( return pipeline.sort(sortObj).exec(); }; -export const aggregateThreadsWithPostCount = (forumId?: string) => { +export const aggregateThreadsWithPostCount = ( + forumId?: string, + sortField: string = 'createdAt', + sortOrder: SortOrder = -1, +) => { const baseStages = [ { $lookup: { @@ -73,5 +77,5 @@ export const aggregateThreadsWithPostCount = (forumId?: string) => { ] : baseStages; - return aggregateSort(Thread.aggregate(threadsAggregate)); + return aggregateSort(Thread.aggregate(threadsAggregate), sortField, sortOrder); }; diff --git a/server/controllers/threadController.ts b/server/controllers/threadController.ts index 027e58e..b19c231 100644 --- a/server/controllers/threadController.ts +++ b/server/controllers/threadController.ts @@ -39,7 +39,7 @@ const createThread = async (req: CustomRequest, res: Response, next: NextFunctio // ACCESS Private const getAllThreads = async (req: CustomRequest, res: Response, next: NextFunction) => { try { - const threads = await aggregateThreadsWithPostCount(); + const threads = await aggregateThreadsWithPostCount(undefined, 'createdAt', -1); res.status(200).json(threads); } catch (error) { From 45bf0507032122ca9a765a82241ff43f46f19a9a Mon Sep 17 00:00:00 2001 From: Howard Sun Date: Tue, 18 Jun 2024 14:27:16 -0400 Subject: [PATCH 17/17] CHE-120 removed Total Post count from individual threads --- client/src/components/Forums/ThreadDetails/ThreadDetails.tsx | 5 ----- 1 file changed, 5 deletions(-) diff --git a/client/src/components/Forums/ThreadDetails/ThreadDetails.tsx b/client/src/components/Forums/ThreadDetails/ThreadDetails.tsx index 09c60c6..c503e60 100644 --- a/client/src/components/Forums/ThreadDetails/ThreadDetails.tsx +++ b/client/src/components/Forums/ThreadDetails/ThreadDetails.tsx @@ -59,8 +59,6 @@ const ThreadDetail = ({ forumId, threadId }: ThreadDetailProps) => { } }; - const totalPosts: number = posts.length + 1; - if (pending) return null; if (loading) return
Loading...
; if (error) return
Error: {error}
; @@ -99,9 +97,6 @@ const ThreadDetail = ({ forumId, threadId }: ThreadDetailProps) => { ))} -
- Total Posts: {totalPosts} -
); };