Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 46 additions & 18 deletions app/auth/projects/[project_id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use client';
import { useCallback, useEffect, useState } from 'react';
import { useCallback, useEffect, useMemo, useState } from 'react';
import Link from 'next/link';
import {
Body1Strong,
Expand Down Expand Up @@ -57,10 +57,12 @@ import ArtifactList from '@/components/ArtifactList/ArtifactList';
import InsertImageModal from '@/components/InsertImageModal/InsertImageModal';
import { useRouter } from 'next/navigation';
import SystemPromptPanel from '@/components/SystemPromptPanel/SystemPromptPanel';
import { Pagination } from '@/components/Pagination';

const DOWNLOADS_DESC =
'This is list of the generated videos. Time format is MM/DD/YY HH:MM';
const ARTIFACTS_DESC = 'This is list of the artifacts.';
const ITEMS_PER_PAGE = 10;

function Videos({
params,
Expand All @@ -81,6 +83,7 @@ function Videos({
const [isCrateVideoOpen, setIsCreateVideoOpen] = useState(false);
const [isWorkFlowOpen, setIsWorkFlowOpen] = useState(false);
const [isAIAgentPanelOpen, setIsAIAgentPanelOpen] = useState(false);
const [currentPage, setCurrentPage] = useState(1);
Copy link

Copilot AI Nov 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pagination state should be reset to page 1 when the videos data changes. Without this, if a user is on page 3 and the videos list is updated (e.g., via a refresh or new data), they might see an empty page if the new data has fewer pages.

Consider adding a useEffect to reset the page:

useEffect(() => {
  setCurrentPage(1);
}, [videos]);
Suggested change
const [currentPage, setCurrentPage] = useState(1);
const [currentPage, setCurrentPage] = useState(1);
useEffect(() => {
setCurrentPage(1);
}, [videos]);

Copilot uses AI. Check for mistakes.
const [artifactsSt, setArtifactsSt] = useState<{
id: string;
isOpen: boolean;
Expand All @@ -99,6 +102,18 @@ function Videos({
useState<boolean>(false);
const client = useQueryClient();

const { paginatedVideos, totalPages } = useMemo(() => {
if (!videos || !videos.length) {
return { paginatedVideos: [], totalPages: 0 };
}
const startIndex = (currentPage - 1) * ITEMS_PER_PAGE;
const endIndex = startIndex + ITEMS_PER_PAGE;
return {
paginatedVideos: videos.slice(startIndex, endIndex),
totalPages: Math.ceil(videos.length / ITEMS_PER_PAGE),
};
}, [videos, currentPage]);

const invalidateProject = () => {
client.invalidateQueries({
queryKey: getProjectVideoQueryKey(params.project_id),
Expand Down Expand Up @@ -570,25 +585,38 @@ function Videos({
</Link>
</div>
</div>
{videos && videos.length && (
<DataGrid className="w-100 flex" items={videos} columns={columns}>
<DataGridHeader>
<DataGridRow>
{({ renderHeaderCell }) => (
<DataGridHeaderCell>{renderHeaderCell()}</DataGridHeaderCell>
)}
</DataGridRow>
</DataGridHeader>
<DataGridBody<IVideo>>
{({ item, rowId }) => (
<DataGridRow<IVideo> key={rowId}>
{({ renderCell }) => (
<DataGridCell>{renderCell(item)}</DataGridCell>
{paginatedVideos && paginatedVideos.length && (
<>
<DataGrid
className="w-100 flex"
items={paginatedVideos}
columns={columns}
>
<DataGridHeader>
<DataGridRow>
{({ renderHeaderCell }) => (
<DataGridHeaderCell>
{renderHeaderCell()}
</DataGridHeaderCell>
)}
</DataGridRow>
)}
</DataGridBody>
</DataGrid>
</DataGridHeader>
<DataGridBody<IVideo>>
{({ item, rowId }) => (
<DataGridRow<IVideo> key={rowId}>
{({ renderCell }) => (
<DataGridCell>{renderCell(item)}</DataGridCell>
)}
</DataGridRow>
)}
</DataGridBody>
</DataGrid>
<Pagination
currentPage={currentPage}
totalPages={totalPages}
onPageChange={setCurrentPage}
/>
</>
)}
{isCrateVideoOpen && (
<FormAddVideo
Expand Down
65 changes: 47 additions & 18 deletions app/auth/projects/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use client';
import { FC, useState } from 'react';
import { FC, useMemo, useState } from 'react';
import Link from 'next/link';
import {
Body1Strong,
Expand Down Expand Up @@ -32,16 +32,32 @@ import { useQueryClient } from '@tanstack/react-query';
import FormAddProject from '../../../components/FormAddProject/FormAddProject';
import { formatDate } from '@/src/helpers';
import { MoreVertical20Regular } from '@fluentui/react-icons';
import { Pagination } from '../../../components/Pagination';

const ITEMS_PER_PAGE = 10;

const Projects: FC = () => {
const { data: projects, isFetching, isLoading } = useQueryGetProjects();
const client = useQueryClient();
const [isOpen, setIsOpen] = useState(false);
const [currentPage, setCurrentPage] = useState(1);
Copy link

Copilot AI Nov 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pagination state should be reset to page 1 when the projects data changes. Without this, if a user is on page 3 and the projects list is updated (e.g., via a refresh or new data), they might see an empty page if the new data has fewer pages.

Consider adding a useEffect to reset the page:

useEffect(() => {
  setCurrentPage(1);
}, [projects]);

Copilot uses AI. Check for mistakes.
const [currentProject, setCurrentProject] =
useState<Partial<IProject> | null>(null);
const addProjectMutation = useMutationCreateProject();
const updateProjectMutation = useMutationUpdateProject();

const { paginatedProjects, totalPages } = useMemo(() => {
if (!projects || !projects.length) {
return { paginatedProjects: [], totalPages: 0 };
}
const startIndex = (currentPage - 1) * ITEMS_PER_PAGE;
const endIndex = startIndex + ITEMS_PER_PAGE;
return {
paginatedProjects: projects.slice(startIndex, endIndex),
totalPages: Math.ceil(projects.length / ITEMS_PER_PAGE),
};
}, [projects, currentPage]);

const columns: TableColumnDefinition<IProject>[] = [
createTableColumn<IProject>({
columnId: 'name',
Expand Down Expand Up @@ -158,25 +174,38 @@ const Projects: FC = () => {
</Button>
</div>
</div>
{projects && projects.length && (
<DataGrid className="w-100 flex" items={projects} columns={columns}>
<DataGridHeader>
<DataGridRow>
{({ renderHeaderCell }) => (
<DataGridHeaderCell>{renderHeaderCell()}</DataGridHeaderCell>
)}
</DataGridRow>
</DataGridHeader>
<DataGridBody<IVideo>>
{({ item, rowId }) => (
<DataGridRow<IVideo> key={rowId}>
{({ renderCell }) => (
<DataGridCell>{renderCell(item)}</DataGridCell>
{paginatedProjects && paginatedProjects.length && (
<>
<DataGrid
className="w-100 flex"
items={paginatedProjects}
columns={columns}
>
<DataGridHeader>
<DataGridRow>
{({ renderHeaderCell }) => (
<DataGridHeaderCell>
{renderHeaderCell()}
</DataGridHeaderCell>
)}
</DataGridRow>
)}
</DataGridBody>
</DataGrid>
</DataGridHeader>
<DataGridBody<IVideo>>
{({ item, rowId }) => (
<DataGridRow<IVideo> key={rowId}>
{({ renderCell }) => (
<DataGridCell>{renderCell(item)}</DataGridCell>
)}
</DataGridRow>
)}
</DataGridBody>
</DataGrid>
<Pagination
currentPage={currentPage}
totalPages={totalPages}
onPageChange={setCurrentPage}
/>
</>
)}
</div>
{isOpen && (
Expand Down
102 changes: 102 additions & 0 deletions components/Pagination/Pagination.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import { Button } from '@fluentui/react-components';
import {
ChevronLeft20Regular,
ChevronRight20Regular,
} from '@fluentui/react-icons';

export interface PaginationProps {
currentPage: number;
totalPages: number;
onPageChange: (page: number) => void;
}

export function Pagination({
currentPage,
totalPages,
onPageChange,
}: PaginationProps) {
const getPageNumbers = () => {
const pages: (number | string)[] = [];
const maxPagesToShow = 5;

if (totalPages <= maxPagesToShow) {
// Show all pages if total is less than max
for (let i = 1; i <= totalPages; i++) {
pages.push(i);
}
} else {
// Always show first page
pages.push(1);

if (currentPage > 3) {
pages.push('...');
}

// Show pages around current page
const startPage = Math.max(2, currentPage - 1);
const endPage = Math.min(totalPages - 1, currentPage + 1);

for (let i = startPage; i <= endPage; i++) {
pages.push(i);
}

if (currentPage < totalPages - 2) {
pages.push('...');
}

// Always show last page
pages.push(totalPages);
}

return pages;
};

if (totalPages <= 1) {
return null;
}

return (
<div className="flex items-center justify-center gap-2 py-4">
<Button
appearance="subtle"
icon={<ChevronLeft20Regular />}
disabled={currentPage === 1}
onClick={() => onPageChange(currentPage - 1)}
aria-label="Previous page"
/>

{getPageNumbers().map((page, index) => {
if (page === '...') {
return (
<span key={`ellipsis-${index}`} className="px-2 text-gray-500">
...
</span>
);
}
Comment on lines +68 to +75
Copy link

Copilot AI Nov 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ellipsis span elements are missing a unique key prop. Using index in the key like ellipsis-${index} can cause issues because when pages change, the same index could refer to different ellipsis positions, potentially causing React reconciliation problems.

Consider using a more specific key that includes position information:

<span key={`ellipsis-${index}-${page}`} className="px-2 text-gray-500">
  ...
</span>

Or better yet:

<span key={`ellipsis-before-${startPage}`} className="px-2 text-gray-500">
  ...
</span>

for the first ellipsis and ellipsis-after-${endPage} for the second.

Suggested change
{getPageNumbers().map((page, index) => {
if (page === '...') {
return (
<span key={`ellipsis-${index}`} className="px-2 text-gray-500">
...
</span>
);
}
{getPageNumbers().map((page, index, arr) => {
if (page === '...') {
// Determine if this is the first or second ellipsis
const isFirstEllipsis = arr.indexOf('...') === index;
const startPage = Math.max(2, currentPage - 1);
const endPage = Math.min(totalPages - 1, currentPage + 1);
const ellipsisKey = isFirstEllipsis
? `ellipsis-before-${startPage}`
: `ellipsis-after-${endPage}`;
return (
<span key={ellipsisKey} className="px-2 text-gray-500">
...
</span>
);

Copilot uses AI. Check for mistakes.

const pageNumber = page as number;
return (
<Button
key={pageNumber}
appearance={currentPage === pageNumber ? 'primary' : 'subtle'}
onClick={() => onPageChange(pageNumber)}
aria-label={`Page ${pageNumber}`}
aria-current={currentPage === pageNumber ? 'page' : undefined}
>
{pageNumber}
</Button>
);
})}

<Button
appearance="subtle"
icon={<ChevronRight20Regular />}
disabled={currentPage === totalPages}
onClick={() => onPageChange(currentPage + 1)}
aria-label="Next page"
/>
</div>
);
}

export default Pagination;
1 change: 1 addition & 0 deletions components/Pagination/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './Pagination';
Loading
Loading