Files
evidencija-rezija/app/page.tsx

47 lines
1.7 KiB
TypeScript

import { LocationCard } from './ui/LocationCard';
import { MonthTitle } from './ui/MonthTitle';
import { AddMonthButton } from './ui/AddMonthButton';
import { AddLocationButton } from './ui/AddLocationButton';
import clientPromise from './lib/mongodb';
import { Location } from './lib/db-types';
export const Page = async () => {
const client = await clientPromise;
const db = client.db("rezije");
const locations = await db.collection<Location>("lokacije")
.find({})
.sort({ yearMonth: -1 }) // sort by yearMonth descending
.limit(20)
.toArray();
return (
<main className="flex min-h-screen flex-col p-6 bg-base-300">
<AddMonthButton />
{
locations.map((location, ix, array) => {
return (
<>
{
location.yearMonth !== array[0].yearMonth && location.yearMonth !== array[ix-1].yearMonth ? <AddLocationButton key={`add-loc-${location.yearMonth}`} /> : null
}
{
// show month title if it's the first location in the month
ix === 0 || location.yearMonth !== array[ix-1].yearMonth ? <MonthTitle key={location.yearMonth} yearMonth={location.yearMonth} /> : null
}
<LocationCard key={`${location._id}`} location={location} />
</>
)
})
}
<h2 className='text-xl text-sky-400/75 font-semibold mt-4'>Docs</h2>
<p><a href="https://tailwindcss.com/docs/" target="_blank">tailwindcss.com</a></p>
<p><a href="https://heroicons.com/" target="_blank">heroicons.com</a></p>
<p><a href="https://daisyui.com/components/" target="_blank">daisyui.com</a></p>
</main>
);
}
export default Page;