optimizirano generiranje popisa lokacija

This commit is contained in:
2024-02-06 09:56:36 +01:00
parent 38fbeebb03
commit 0ce7b11c3c

View File

@@ -7,7 +7,7 @@ import { MonthCard } from "./MonthCard";
import Pagination from "./Pagination"; import Pagination from "./Pagination";
import { LocationCard } from "./LocationCard"; import { LocationCard } from "./LocationCard";
import { BillingLocation, YearMonth } from "../lib/db-types"; import { BillingLocation, YearMonth } from "../lib/db-types";
import { useParams, useRouter, useSearchParams } from "next/navigation"; import { useRouter, useSearchParams } from "next/navigation";
const getNextYearMonth = (yearMonth:YearMonth) => { const getNextYearMonth = (yearMonth:YearMonth) => {
const {year, month} = yearMonth; const {year, month} = yearMonth;
@@ -77,11 +77,15 @@ export const MonthLocationList:React.FC<MonthLocationListProps > = ({
monthsArray.map(([monthKey, { yearMonth, locations, monthlyExpense }], monthIx) => monthsArray.map(([monthKey, { yearMonth, locations, monthlyExpense }], monthIx) =>
<MonthCard yearMonth={yearMonth} key={`month-${monthKey}`} monthlyExpense={monthlyExpense} expanded={ yearMonth.month === expandedMonth } onToggle={handleMonthToggle} > <MonthCard yearMonth={yearMonth} key={`month-${monthKey}`} monthlyExpense={monthlyExpense} expanded={ yearMonth.month === expandedMonth } onToggle={handleMonthToggle} >
{ {
locations.map((location, ix) => <LocationCard key={`location-${location._id}`} location={location} />) yearMonth.month === expandedMonth ?
locations.map((location, ix) => <LocationCard key={`location-${location._id}`} location={location} />)
: null
} }
{ {
// show AddLocationButton as a last item in the first month yearMonth.month === expandedMonth ?
monthIx === 0 ? <AddLocationButton yearMonth={yearMonth} /> : null // show AddLocationButton as a last item in the first month
(monthIx === 0 ? <AddLocationButton yearMonth={yearMonth} /> : null)
: null
} }
</MonthCard> </MonthCard>
) )