asdfasdfasdfasdfasdf
asdfasdfasdfa

'use client'
import { useQuery } from '@tanstack/react-query'
import { BlogsForm } from './blogs-form'
import { getBlogs } from './blogs.server'
import { CirclePlus, Loader } from 'lucide-react'
import { BlogsCard } from './blogs-card'
import React, { Suspense } from 'react'
import { Button, buttonVariants } from '@zaher/ui/components/button'
import Link from 'next/link'
import { cn } from '@/lib/utils'
import { usePathname, useRouter, useSearchParams } from 'next/navigation'
import { Pagination } from '@/components/custom'
export function BlogsPage() {
return (
<div className='flex flex-col gap-3'>
<div className='flex items-end justify-end'>
<Link className={cn(buttonVariants({}), 'rounded-lg py-5 px-6')} href={'/blogs/new'}>
<span>إنشاء جديد</span>
<CirclePlus className='fill-white text-primary size-6' />
</Link>
</div>
<Suspense fallback={null}>
<BlogsPageContent />
</Suspense>
</div>
)
}
const ITEMS_PER_PAGE = 8
export function BlogsPageContent() {
const searchParams = useSearchParams()
const router = useRouter()
const pathname = usePathname()
const pageParam = searchParams.get('page')
const currentPage = pageParam ? Number.parseInt(pageParam) : 1
const [filter, setFilter] = React.useState<'all' | 'published' | 'unpublished'>('all')
const { data, status } = useQuery({
queryKey: ['blogs', currentPage],
queryFn: () =>
getBlogs({
page: currentPage,
limit: ITEMS_PER_PAGE,
}),
})
if (status === 'pending') {
return (
<div className='flex w-full h-full items-center justify-center'>
<div className='flex items-center gap-2'>
<Loader className='w-6 h-6 animate-spin' />
<span>جاري تحميل المدونات</span>
</div>
</div>
)
}
if (status === 'error' || !data) {
return (
<div className='flex w-full h-full items-center justify-center'>
فشل في تحميل بيانات المدونة
</div>
)
}
const { blogs, total } = data
const dataFiltered =
blogs?.filter((blog) =>
filter === 'all'
? blog
: filter === 'published' && blog.isPublished
? blog
: filter === 'unpublished' && !blog.isPublished && blog,
) ?? []
return (
<>
<div className='flex items-center gap-4 mb-4'>
{[
{ key: 'all', label: 'الكل' },
{ key: 'published', label: 'منشورة' },
{ key: 'unpublished', label: 'غير منشورة' },
].map((item) => (
<Button
key={item.key}
variant={filter === item.key ? 'default' : 'outline'}
className='px-8 rounded-full shadow-none'
onClick={() => {
setFilter(item.key as any)
const params = new URLSearchParams(searchParams.toString())
params.set('page', '1')
router.push${pathname}?${params.toString()}
, {
scroll: false,
})
}}>
{item.label}
</Button>
))}
</div>
<ul className='grid md:grid-cols-2 lg:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4 3xl:grid-cols-5 gap-4 mt-4'>
{dataFiltered && dataFiltered.length > 0 ? (
dataFiltered.map((blog) => <BlogsCard key={blog.id} blog={blog} />)
) : (
<p>لا يوجد مدونات</p>
)}
</ul>
<div className='mt-5'>
<Pagination currentPage={currentPage} totalItems={total?.count || 0} itemsPerPage={ITEMS_PER_PAGE} />
</div>
</>
)
}
export function BlogsAddPage() {
return <BlogsForm />
}
'use client'
import { useQuery } from '@tanstack/react-query'
import { BlogsForm } from './blogs-form'
import { getBlogs } from './blogs.server'
import { CirclePlus, Loader } from 'lucide-react'
import { BlogsCard } from './blogs-card'
import React, { Suspense } from 'react'
import { Button, buttonVariants } from '@zaher/ui/components/button'
import Link from 'next/link'
import { cn } from '@/lib/utils'
import { usePathname, useRouter, useSearchParams } from 'next/navigation'
import { Pagination } from '@/components/custom'
export function BlogsPage() {
return (
<div className='flex flex-col gap-3'>
<div className='flex items-end justify-end'>
<Link className={cn(buttonVariants({}), 'rounded-lg py-5 px-6')} href={'/blogs/new'}>
<span>إنشاء جديد</span>
<CirclePlus className='fill-white text-primary size-6' />
</Link>
</div>
<Suspense fallback={null}>
<BlogsPageContent />
</Suspense>
</div>
)
}
const ITEMS_PER_PAGE = 8
export function BlogsPageContent() {
const searchParams = useSearchParams()
const router = useRouter()
const pathname = usePathname()
const pageParam = searchParams.get('page')
const currentPage = pageParam ? Number.parseInt(pageParam) : 1
const [filter, setFilter] = React.useState<'all' | 'published' | 'unpublished'>('all')
const { data, status } = useQuery({
queryKey: ['blogs', currentPage],
queryFn: () =>
getBlogs({
page: currentPage,
limit: ITEMS_PER_PAGE,
}),
})
if (status === 'pending') {
return (
<div className='flex w-full h-full items-center justify-center'>
<div className='flex items-center gap-2'>
<Loader className='w-6 h-6 animate-spin' />
<span>جاري تحميل المدونات</span>
</div>
</div>
)
}
if (status === 'error' || !data) {
return (
<div className='flex w-full h-full items-center justify-center'>
فشل في تحميل بيانات المدونة
</div>
)
}
const { blogs, total } = data
const dataFiltered =
blogs?.filter((blog) =>
filter === 'all'
? blog
: filter === 'published' && blog.isPublished
? blog
: filter === 'unpublished' && !blog.isPublished && blog,
) ?? []
return (
<>
<div className='flex items-center gap-4 mb-4'>
{[
{ key: 'all', label: 'الكل' },
{ key: 'published', label: 'منشورة' },
{ key: 'unpublished', label: 'غير منشورة' },
].map((item) => (
<Button
key={item.key}
variant={filter === item.key ? 'default' : 'outline'}
className='px-8 rounded-full shadow-none'
onClick={() => {
setFilter(item.key as any)
const params = new URLSearchParams(searchParams.toString())
params.set('page', '1')
router.push${pathname}?${params.toString()}
, {
scroll: false,
})
}}>
{item.label}
</Button>
))}
</div>
<ul className='grid md:grid-cols-2 lg:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4 3xl:grid-cols-5 gap-4 mt-4'>
{dataFiltered && dataFiltered.length > 0 ? (
dataFiltered.map((blog) => <BlogsCard key={blog.id} blog={blog} />)
) : (
<p>لا يوجد مدونات</p>
)}
</ul>
<div className='mt-5'>
<Pagination currentPage={currentPage} totalItems={total?.count || 0} itemsPerPage={ITEMS_PER_PAGE} />
</div>
</>
)
}
export function BlogsAddPage() {
return <BlogsForm />
}
'use client'
import { useQuery } from '@tanstack/react-query'
import { BlogsForm } from './blogs-form'
import { getBlogs } from './blogs.server'
import { CirclePlus, Loader } from 'lucide-react'
import { BlogsCard } from './blogs-card'
import React, { Suspense } from 'react'
import { Button, buttonVariants } from '@zaher/ui/components/button'
import Link from 'next/link'
import { cn } from '@/lib/utils'
import { usePathname, useRouter, useSearchParams } from 'next/navigation'
import { Pagination } from '@/components/custom'
export function BlogsPage() {
return (
<div className='flex flex-col gap-3'>
<div className='flex items-end justify-end'>
<Link className={cn(buttonVariants({}), 'rounded-lg py-5 px-6')} href={'/blogs/new'}>
<span>إنشاء جديد</span>
<CirclePlus className='fill-white text-primary size-6' />
</Link>
</div>
<Suspense fallback={null}>
<BlogsPageContent />
</Suspense>
</div>
)
}
const ITEMS_PER_PAGE = 8
export function BlogsPageContent() {
const searchParams = useSearchParams()
const router = useRouter()
const pathname = usePathname()
const pageParam = searchParams.get('page')
const currentPage = pageParam ? Number.parseInt(pageParam) : 1
const [filter, setFilter] = React.useState<'all' | 'published' | 'unpublished'>('all')
const { data, status } = useQuery({
queryKey: ['blogs', currentPage],
queryFn: () =>
getBlogs({
page: currentPage,
limit: ITEMS_PER_PAGE,
}),
})
if (status === 'pending') {
return (
<div className='flex w-full h-full items-center justify-center'>
<div className='flex items-center gap-2'>
<Loader className='w-6 h-6 animate-spin' />
<span>جاري تحميل المدونات</span>
</div>
</div>
)
}
if (status === 'error' || !data) {
return (
<div className='flex w-full h-full items-center justify-center'>
فشل في تحميل بيانات المدونة
</div>
)
}
const { blogs, total } = data
const dataFiltered =
blogs?.filter((blog) =>
filter === 'all'
? blog
: filter === 'published' && blog.isPublished
? blog
: filter === 'unpublished' && !blog.isPublished && blog,
) ?? []
return (
<>
<div className='flex items-center gap-4 mb-4'>
{[
{ key: 'all', label: 'الكل' },
{ key: 'published', label: 'منشورة' },
{ key: 'unpublished', label: 'غير منشورة' },
].map((item) => (
<Button
key={item.key}
variant={filter === item.key ? 'default' : 'outline'}
className='px-8 rounded-full shadow-none'
onClick={() => {
setFilter(item.key as any)
const params = new URLSearchParams(searchParams.toString())
params.set('page', '1')
router.push${pathname}?${params.toString()}
, {
scroll: false,
})
}}>
{item.label}
</Button>
))}
</div>
<ul className='grid md:grid-cols-2 lg:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4 3xl:grid-cols-5 gap-4 mt-4'>
{dataFiltered && dataFiltered.length > 0 ? (
dataFiltered.map((blog) => <BlogsCard key={blog.id} blog={blog} />)
) : (
<p>لا يوجد مدونات</p>
)}
</ul>
<div className='mt-5'>
<Pagination currentPage={currentPage} totalItems={total?.count || 0} itemsPerPage={ITEMS_PER_PAGE} />
</div>
</>
)
}
export function BlogsAddPage() {
return <BlogsForm />
}