Skip to content

Commit

Permalink
Merge pull request #234 from manuelc2209/fix/thread-dates
Browse files Browse the repository at this point in the history
Thread Dates
  • Loading branch information
manuelc2209 authored Jul 12, 2023
2 parents 20a65b0 + f30ddd8 commit 9ee0752
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 18 deletions.
1 change: 0 additions & 1 deletion src/pages/forum/components/header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export const Header = () => {

return (
<>
<Banner />
<StyledHeaderWrapper>
<StyledButton size="large" buttonType="border" label="Back" onClick={() => navigate(-1)} />
<StyledCTAEnd>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/forum/components/thread/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ export interface ThreadProps {
sideSection: {
replies: number;
views: number;
postTimeTracker: Date;
postTimeTracker: number;
};
}
2 changes: 1 addition & 1 deletion src/pages/forum/context/contextType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface IThread {
sideSection: {
replies: number;
views: number;
postTimeTracker: Date;
postTimeTracker: number;
};
}

Expand Down
10 changes: 7 additions & 3 deletions src/pages/forum/pages/Threads/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import React, { useContext, useEffect } from 'react';

import { ForumContext, ForumContextWrapper } from '../../context/forumContext';
import { ForumContext } from '../../context/forumContext';
import { ThreadsView } from '../../layout';
import { mockedThreads } from '../../shared/mockData';

export const Threads = () => {
const { setThreads } = useContext(ForumContext);

useEffect(() => {
setThreads(mockedThreads);
const sortedItems = mockedThreads.sort(
(item, newItem) => newItem.sideSection.postTimeTracker - item.sideSection.postTimeTracker
);

setThreads(sortedItems);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
}, [mockedThreads]);

return <ThreadsView />;
};
108 changes: 99 additions & 9 deletions src/pages/forum/shared/mockData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const mockedThreads: IThread[] = [
lastName: 'Doe'
},
sideSection: {
postTimeTracker: new Date(1674153241555),
postTimeTracker: new Date('2020-05-15T10:30:00.000Z').getTime(),
replies: Math.floor(Math.random() * 10000) + 1,
views: Math.floor(Math.random() * 10000) + 1
}
Expand All @@ -28,7 +28,7 @@ export const mockedThreads: IThread[] = [
lastName: 'Smith'
},
sideSection: {
postTimeTracker: new Date(1674153241555),
postTimeTracker: new Date(1674153241555).getTime(),
replies: Math.floor(Math.random() * 10000) + 1,
views: Math.floor(Math.random() * 10000) + 1
}
Expand All @@ -43,7 +43,7 @@ export const mockedThreads: IThread[] = [
lastName: 'Smith'
},
sideSection: {
postTimeTracker: new Date(1624151241525),
postTimeTracker: new Date(1624151241525).getTime(),
replies: Math.floor(Math.random() * 10000) + 1,
views: Math.floor(Math.random() * 10000) + 1
}
Expand All @@ -58,7 +58,7 @@ export const mockedThreads: IThread[] = [
lastName: 'Johnson'
},
sideSection: {
postTimeTracker: new Date('2022-05-15T10:30:00.000Z'),
postTimeTracker: new Date('2022-05-15T10:30:00.000Z').getTime(),
replies: Math.floor(Math.random() * 10000) + 1,
views: Math.floor(Math.random() * 10000) + 1
}
Expand All @@ -73,7 +73,7 @@ export const mockedThreads: IThread[] = [
lastName: 'Garcia'
},
sideSection: {
postTimeTracker: new Date('2022-11-30T08:15:00.000Z'),
postTimeTracker: new Date('2022-11-30T08:15:00.000Z').getTime(),
replies: Math.floor(Math.random() * 10000) + 1,
views: Math.floor(Math.random() * 10000) + 1
}
Expand All @@ -88,7 +88,7 @@ export const mockedThreads: IThread[] = [
lastName: 'Lee'
},
sideSection: {
postTimeTracker: new Date('2022-07-10T16:20:00.000Z'),
postTimeTracker: new Date('2022-07-10T16:20:00.000Z').getTime(),
replies: Math.floor(Math.random() * 10000) + 1,
views: Math.floor(Math.random() * 10000) + 1
}
Expand All @@ -103,22 +103,112 @@ export const mockedThreads: IThread[] = [
lastName: 'Wilson'
},
sideSection: {
postTimeTracker: new Date('2022-12-05T11:55:00.000Z'),
postTimeTracker: new Date('2022-12-05T11:55:00.000Z').getTime(),
replies: 932,
views: 4620
}
},
{
avatar: faker.image.avatarGitHub(),
title: 'JavaScript Frameworks Comparison',
subtitle: 'Analyzing the pros and cons of popular JS frameworks',
subtitle: 'Analyzing the pros and cons of JS frameworks',
user: {
id: 'userxyz',
firstName: 'David',
lastName: 'Thompson'
},
sideSection: {
postTimeTracker: new Date('2022-08-18T09:10:00.000Z'),
postTimeTracker: new Date('2022-08-18T09:10:00.000Z').getTime(),
replies: 1537,
views: 6241
}
},
{
avatar: faker.image.avatarGitHub(),
title: 'Typescript Comparison',
subtitle: 'Analyzing the pros and cons of TS',
user: {
id: 'userxyz',
firstName: 'David',
lastName: 'Thompson'
},
sideSection: {
postTimeTracker: new Date('2022-08-18T09:10:00.000Z').getTime(),
replies: 1537,
views: 6241
}
},
{
avatar: faker.image.avatarGitHub(),
title: 'Some Random Comparison',
subtitle: 'Analyzing the pros and cons of Randomness',
user: {
id: 'userxyz',
firstName: 'David',
lastName: 'Thompson'
},
sideSection: {
postTimeTracker: new Date('2022-08-18T09:10:00.000Z').getTime(),
replies: 1537,
views: 6241
}
},
{
avatar: faker.image.avatarGitHub(),
title: 'Artificial Intelligence in Healthcare',
subtitle: 'Applications of AI in the medical field',
user: {
id: 'userdef',
firstName: 'Olivia',
lastName: 'Wilson'
},
sideSection: {
postTimeTracker: new Date('2022-12-05T11:55:00.000Z').getTime(),
replies: 932,
views: 4620
}
},
{
avatar: faker.image.avatarGitHub(),
title: 'JavaScript Frameworks Comparison',
subtitle: 'Analyzing the pros and cons of JS frameworks',
user: {
id: 'userxyz',
firstName: 'David',
lastName: 'Thompson'
},
sideSection: {
postTimeTracker: new Date('2022-08-18T09:10:00.000Z').getTime(),
replies: 1537,
views: 6241
}
},
{
avatar: faker.image.avatarGitHub(),
title: 'Typescript Comparison',
subtitle: 'Analyzing the pros and cons of TS',
user: {
id: 'userxyz',
firstName: 'David',
lastName: 'Thompson'
},
sideSection: {
postTimeTracker: new Date('2022-08-18T09:10:00.000Z').getTime(),
replies: 1537,
views: 6241
}
},
{
avatar: faker.image.avatarGitHub(),
title: 'Some Random Comparison',
subtitle: 'Analyzing the pros and cons of Randomness',
user: {
id: 'userxyz',
firstName: 'David',
lastName: 'Thompson'
},
sideSection: {
postTimeTracker: new Date('2022-08-18T09:10:00.000Z').getTime(),
replies: 1537,
views: 6241
}
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5527,9 +5527,9 @@ caniuse-api@^3.0.0:
lodash.uniq "^4.5.0"

caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001109, caniuse-lite@^1.0.30001400, caniuse-lite@^1.0.30001407:
version "1.0.30001422"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001422.tgz#f2d7c6202c49a8359e6e35add894d88ef93edba1"
integrity sha512-hSesn02u1QacQHhaxl/kNMZwqVG35Sz/8DgvmgedxSH8z9UUpcDYSPYgsj3x5dQNRcNp6BwpSfQfVzYUTm+fog==
version "1.0.30001515"
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001515.tgz"
integrity sha512-eEFDwUOZbE24sb+Ecsx3+OvNETqjWIdabMy52oOkIgcUtAsQifjUG9q4U9dgTHJM2mfk4uEPxc0+xuFdJ629QA==

capital-case@^1.0.4:
version "1.0.4"
Expand Down

0 comments on commit 9ee0752

Please sign in to comment.