Skip to content

Commit

Permalink
fix: Disconnected backend - static
Browse files Browse the repository at this point in the history
Contributor @aishikanandi
  • Loading branch information
tusharbansal22 authored Jan 5, 2024
2 parents d2067c2 + 8f7ce0c commit 13fad26
Show file tree
Hide file tree
Showing 10 changed files with 379 additions and 120 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
.env
next/cache/
next/
.next/
# dependencies
/node_modules
/.pnp
Expand Down
45 changes: 17 additions & 28 deletions package-lock.json

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

10 changes: 6 additions & 4 deletions src/components/Common/UpvoteButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ export const UpvoteButton: FC<{
}, [upvotesCount])

useEffect(() => {
users.find((user: any) => currentUser?.user_id === user.user_id)
? setIsUpvoted(true)
: setIsUpvoted(false)
}, [users, currentUser])
if (Array.isArray(users)) {
users.find((user: any) => currentUser?.user_id === user.user_id)
? setIsUpvoted(true)
: setIsUpvoted(false);
}
}, [users, currentUser]);

return (
<div className="flex space-x-1 items-center justify-center">
Expand Down
62 changes: 52 additions & 10 deletions src/components/Notes/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,48 @@ import { removeNotesUpvote } from '../../services/db/notes/removeNotesUpvote'
import { upvoteNotes } from '../../services/db/notes/upvoteNotes'
import { IoMdArrowDropdown, IoMdArrowDropup } from 'react-icons/io'
import { GlobalFilter } from '../Common/GlobalFilter'
const dummyNotesData: notesColumnData[] = [
{
sno: '1.',
upvotes: {
count: 10,
users: [
{ user_id: 'user1' },
{ user_id: 'user2' }
],
},
title: 'Introduction to React',
subjectCode: 'CS101',
subjectName: 'Web Development',
url: 'https://example.com/notes/react-intro',
semester: 'Semester 3',
instructor: 'Dr. Smith',
branch: 'Computer Science',
uploadedBy: 'User 1',
actions: <button onClick={() => console.log('Edit')}>Edit</button>,
},
{
sno: '2.',
upvotes: {
count: 10,
users: [
{ user_id: 'user1' },
{ user_id: 'user2' }
],
},
title: 'Data Structures Basics',
subjectCode: 'CS201',
subjectName: 'Algorithms and Data Structures',
url: 'https://example.com/notes/data-structures',
semester: 'Semester 4',
instructor: 'Prof. Johnson',
branch: 'Computer Science',
uploadedBy: 'User 2',
actions: <button onClick={() => console.log('Edit')}>Edit</button>,
},
// Add more dummy data as needed
];


export const Table: FC<{
notes: notesColumnData[]
Expand Down Expand Up @@ -306,28 +348,28 @@ export const Table: FC<{
() =>
isDataFetching
? Array(8).fill({})
: notes &&
notes.map((note: any, index) => {
: dummyNotesData &&
dummyNotesData.map((note: any, index) => {
return {
sno: `${index + 1}.`,
id: note.id,
upvotes: {
count: note._count.upvotes,
users: note.upvotes,
count: note.upvotes.count,
users: note.upvotes.users,
},
title: note.title,
subjectCode: note.subject_code,
subjectName: note.subject.name,
subjectCode: note.subjectCode,
subjectName: note.subjectName,
url: note.url,
semester: note.semester,
instructor: note.instructor.name,
instructor: note.instructor,
branch: note.branch,
uploadedBy: note.created_by.name,
uploadedBy: note.uploadedBy,
anonymous: note.anonymous,
actions: note,
}
}),
[isDataFetching, notes]
[isDataFetching, dummyNotesData]
)

const {
Expand All @@ -354,7 +396,7 @@ export const Table: FC<{
}
}, [loading, setHiddenColumns, user])

return isDataFetching || notes.length ? (
return isDataFetching || dummyNotesData.length ? (
<div className="flex flex-col space-y-2 w-full">
<GlobalFilter
preGlobalFilteredRows={preGlobalFilteredRows}
Expand Down
70 changes: 58 additions & 12 deletions src/components/PYQs/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,48 @@ import { upvotePyq } from '../../services/db/pyqs/upvotePyq'
import { IoMdArrowDropdown, IoMdArrowDropup } from 'react-icons/io'
import { GlobalFilter } from '../Common/GlobalFilter'

const dummyPyqsData: pyqsColumnData[] = [
{
sno: '1.',
upvotes: {
count: 10,
users: [
{ user_id: 'user1' },
{ user_id: 'user2' }
],
},
title: 'Sample Title 1',
subjectCode: 'SC001',
subjectName: 'Sample Subject 1',
url: 'https://example.com/sample1',
semester: 'Semester 1',
instructor: 'Instructor 1',
branch: 'Branch 1',
uploadedBy: 'User 1',
actions: <button onClick={() => console.log('Edit')}>Edit</button>,
},
{
sno: '2.',
upvotes: {
count: 5,
users: [
{ user_id: 'user3' },
{ user_id: 'user4' }
],
},
title: 'Sample Title 2',
subjectCode: 'SC002',
subjectName: 'Sample Subject 2',
url: 'https://example.com/sample2',
semester: 'Semester 2',
instructor: 'Instructor 2',
branch: 'Branch 2',
uploadedBy: 'User 2',
actions: <button onClick={() => console.log('Edit')}>Edit</button>,
},
];


export const Table: FC<{
pyqs: pyqsColumnData[]
setSelectedPYQ: Dispatch<SetStateAction<any>>
Expand Down Expand Up @@ -299,29 +341,33 @@ export const Table: FC<{
() =>
isDataFetching
? Array(8).fill({})
: pyqs &&
pyqs.map((pyq: any, index) => {
: dummyPyqsData
? dummyPyqsData.map((pyq: any, index) => {
return {
sno: `${index + 1}.`,
id: pyq.id,
title: pyq.title,
upvotes: {
count: pyq._count.upvotes,
count: // Replace this with a static value or your logic
pyq.upvotes ? pyq.upvotes.length : 0, // For example, counting the length of upvotes array
users: pyq.upvotes,
},
subjectCode: pyq.subject_code,
subjectName: pyq.subject.name,
subjectCode: pyq.subjectCode,
subjectName: pyq.subjectName ? pyq.subjectName : '',
url: pyq.url,
semester: pyq.semester,
instructor: pyq.instructor.name,
instructor: pyq.instructor ? pyq.instructor: '',
branch: pyq.branch,
uploadedBy: pyq.created_by.name,
uploadedBy: pyq.created_by ? pyq.uploadedBy : '',
anonymous: pyq.anonymous,
actions: pyq,
}
}),
[isDataFetching, pyqs]
)
};
})
: [],
[isDataFetching, dummyPyqsData]
);



const {
getTableProps,
Expand All @@ -347,7 +393,7 @@ export const Table: FC<{
}
}, [loading, setHiddenColumns, user])

return isDataFetching || pyqs.length ? (
return isDataFetching || dummyPyqsData.length ? (
<div className="flex flex-col space-y-2 w-full">
<GlobalFilter
preGlobalFilteredRows={preGlobalFilteredRows}
Expand Down
Loading

0 comments on commit 13fad26

Please sign in to comment.