Skip to content

Commit 442647c

Browse files
authored
Merge pull request #82 from CS3219-AY2324S1/fix-questions-table
Fix managing questions table and fix questions table for normal users
2 parents a3763a6 + 6f84d76 commit 442647c

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

frontend/src/components/Questions/EditQuestionsTable.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ interface EditQuestionsTableProps {
2626

2727
const EditQuestionsTable: React.FC<EditQuestionsTableProps> = ({onEdit, onDelete}) => {
2828
const [questionsData, setQuestions] = useState<Question[]>([]);
29-
const [currentPage, setCurrentPage] = useState<number>(1);
29+
const [currentPage, setCurrentPage] = useState<number>(0);
3030
const [itemsPerPage, setItemsPerPage] = useState<number>(ITEMS_PER_PAGE_OPTIONS[0]);
3131
const [expandedQuestion, setExpandedQuestion] = useState<string | false>(false);
3232

@@ -61,7 +61,7 @@ const EditQuestionsTable: React.FC<EditQuestionsTableProps> = ({onEdit, onDelete
6161
expandedQuestion === id ? setExpandedQuestion(false) : setExpandedQuestion(id);
6262
}
6363

64-
const indexOfLastQuestion = currentPage * itemsPerPage;
64+
const indexOfLastQuestion = (currentPage + 1) * itemsPerPage;
6565
const indexOfFirstQuestion = indexOfLastQuestion - itemsPerPage;
6666
const currentQuestions = questionsData.slice(indexOfFirstQuestion, indexOfLastQuestion);
6767

@@ -130,7 +130,7 @@ const EditQuestionsTable: React.FC<EditQuestionsTableProps> = ({onEdit, onDelete
130130
component="div"
131131
count={questionsData.length}
132132
rowsPerPage={itemsPerPage}
133-
page={currentPage - 1}
133+
page={currentPage}
134134
onPageChange={handlePageChange} />
135135
</div></>
136136

frontend/src/components/Questions/QuestionsTable.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const ITEMS_PER_PAGE_OPTIONS = [5, 10]; // Number of items to display per page
3333
const InterviewQuestionsTable: React.FC = () => {
3434
const [questionsData, setQuestions] = useState<Question[]>([]);
3535
const [selectedCategories, setSelectedCategories] = useState<string[]>([]);
36-
const [currentPage, setCurrentPage] = useState<number>(1);
36+
const [currentPage, setCurrentPage] = useState<number>(0);
3737
const [itemsPerPage, setItemsPerPage] = useState<number>(
3838
ITEMS_PER_PAGE_OPTIONS[0]
3939
);
@@ -73,7 +73,7 @@ const filteredQuestions = questionsData.filter(question =>
7373
setCurrentPage(1);
7474
};
7575

76-
const indexOfLastQuestion = currentPage * itemsPerPage;
76+
const indexOfLastQuestion = (currentPage + 1) * itemsPerPage;
7777
const indexOfFirstQuestion = indexOfLastQuestion - itemsPerPage;
7878
const currentQuestions = filteredQuestions.slice(
7979
indexOfFirstQuestion,
@@ -157,7 +157,7 @@ const filteredQuestions = questionsData.filter(question =>
157157
component="div"
158158
count={questionsData.length}
159159
rowsPerPage={itemsPerPage}
160-
page={currentPage - 1}
160+
page={currentPage}
161161
onPageChange={handlePageChange}
162162
/>
163163
</div>

0 commit comments

Comments
 (0)