mirror of
https://github.com/yusufipk/OpenFrame.git
synced 2026-09-11 17:46:06 +00:00
feat: add sorting functionality to project videos and update search parameters
This commit is contained in:
@@ -36,7 +36,7 @@ function formatRelativeTime(date: Date): string {
|
|||||||
|
|
||||||
interface ProjectPageProps {
|
interface ProjectPageProps {
|
||||||
params: Promise<{ projectId: string }>;
|
params: Promise<{ projectId: string }>;
|
||||||
searchParams: Promise<{ page?: string }>;
|
searchParams: Promise<{ page?: string; sort?: string }>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function ProjectPage({ params, searchParams }: ProjectPageProps) {
|
export default async function ProjectPage({ params, searchParams }: ProjectPageProps) {
|
||||||
@@ -45,7 +45,8 @@ export default async function ProjectPage({ params, searchParams }: ProjectPageP
|
|||||||
const resolvedSearchParams = await searchParams;
|
const resolvedSearchParams = await searchParams;
|
||||||
|
|
||||||
const page = Number(resolvedSearchParams?.page) || 1;
|
const page = Number(resolvedSearchParams?.page) || 1;
|
||||||
const pageSize = 20;
|
const sortOrder = resolvedSearchParams?.sort === 'asc' ? 'asc' : 'desc';
|
||||||
|
const pageSize = 21;
|
||||||
const skip = (page - 1) * pageSize;
|
const skip = (page - 1) * pageSize;
|
||||||
|
|
||||||
// Fetch project with videos
|
// Fetch project with videos
|
||||||
@@ -107,7 +108,10 @@ export default async function ProjectPage({ params, searchParams }: ProjectPageP
|
|||||||
where: { projectId: project.id },
|
where: { projectId: project.id },
|
||||||
skip,
|
skip,
|
||||||
take: pageSize,
|
take: pageSize,
|
||||||
orderBy: { position: 'asc' },
|
orderBy: [
|
||||||
|
{ updatedAt: sortOrder },
|
||||||
|
{ id: sortOrder },
|
||||||
|
],
|
||||||
include: {
|
include: {
|
||||||
versions: {
|
versions: {
|
||||||
where: { isActive: true },
|
where: { isActive: true },
|
||||||
|
|||||||
@@ -82,12 +82,6 @@ export function ProjectContentClient({
|
|||||||
[searchParams]
|
[searchParams]
|
||||||
);
|
);
|
||||||
|
|
||||||
const sortedVideos = [...localVideos].sort((a, b) => {
|
|
||||||
const dateA = new Date(a.updatedAt).getTime();
|
|
||||||
const dateB = new Date(b.updatedAt).getTime();
|
|
||||||
return sortOrder === 'desc' ? dateB - dateA : dateA - dateB;
|
|
||||||
});
|
|
||||||
|
|
||||||
const handleVideoDeleted = useCallback((videoId: string) => {
|
const handleVideoDeleted = useCallback((videoId: string) => {
|
||||||
setLocalVideos((prev) => prev.filter((video) => video.id !== videoId));
|
setLocalVideos((prev) => prev.filter((video) => video.id !== videoId));
|
||||||
}, []);
|
}, []);
|
||||||
@@ -188,7 +182,7 @@ export function ProjectContentClient({
|
|||||||
{/* Videos Grid */}
|
{/* Videos Grid */}
|
||||||
{localVideos.length > 0 ? (
|
{localVideos.length > 0 ? (
|
||||||
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-3">
|
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-3">
|
||||||
{sortedVideos.map((video) => (
|
{localVideos.map((video) => (
|
||||||
<VideoCard
|
<VideoCard
|
||||||
key={video.id}
|
key={video.id}
|
||||||
video={video}
|
video={video}
|
||||||
|
|||||||
Reference in New Issue
Block a user