Skip to content

Commit

Permalink
Merge pull request #47 from cabcookie:fix-fetching-dayplans
Browse files Browse the repository at this point in the history
fix fetching dayplans
  • Loading branch information
cabcookie authored Apr 29, 2024
2 parents af867e6 + 10894ec commit b4e18f8
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 41 deletions.
27 changes: 23 additions & 4 deletions api/useDayplans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,33 @@ const mapDayPlan: (dayplan: DayPlanData) => DayPlan = ({
.sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime()),
});

const fetchDayPlans = (context?: Context) => async () => {
if (!context) return;
const { data, errors } = await client.models.DayPlan.list({
type FetchDayPlansWithTokenFn = (
context: Context,
token?: string
) => Promise<DayPlanData[] | undefined>;

const fetchDayPlansWithToken: FetchDayPlansWithTokenFn = async (
context,
token
) => {
const { data, errors, nextToken } = await client.models.DayPlan.list({
filter: { done: { ne: true }, context: { eq: context } },
selectionSet: dayplanSelectionSet,
nextToken: token,
});
if (errors) throw errors;
return data.map(mapDayPlan).sort((a, b) => sortByDate(true)([a.day, b.day]));
if (!nextToken) return data;
return [
...data,
...((await fetchDayPlansWithToken(context, nextToken)) || []),
];
};

const fetchDayPlans = (context?: Context) => async () => {
if (!context) return;
return (await fetchDayPlansWithToken(context))
?.map(mapDayPlan)
.sort((a, b) => sortByDate(true)([a.day, b.day]));
};

export type CreateTodoFn = (props: {
Expand Down
61 changes: 30 additions & 31 deletions api/useMeetings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,43 +65,42 @@ const fetchMeetingsWithToken: FetchMeetingsWithTokenFunction = async ({
token,
context,
}) => {
if (!context) return;
const toDate = flow(
addDaysToDate(-4 * (page - 1) * 7 + 1),
getDayOfDate
)(new Date());
const fromDate = flow(addDaysToDate(-4 * page * 7), getDayOfDate)(new Date());
const filter = {
and: [
{
or: [
{ context: { eq: context } },
{
and: [
{ context: { ne: "work" } },
{ context: { ne: "family" } },
{ context: { ne: "hobby" } },
],
},
],
},
{
or: [
{
and: [
{ meetingOn: { gt: fromDate } },
{ meetingOn: { le: toDate } },
],
},
{
and: [
{ meetingOn: { attributeExists: false } },
{ createdAt: { gt: fromDate } },
],
},
],
},
],
and: [
{
or: [
{ context: { eq: context } },
{
and: [
{ context: { ne: "work" } },
{ context: { ne: "family" } },
{ context: { ne: "hobby" } },
],
},
],
},
{
or: [
{
and: [
{ meetingOn: { gt: fromDate } },
{ meetingOn: { le: toDate } },
],
},
{
and: [
{ meetingOn: { attributeExists: false } },
{ createdAt: { gt: fromDate } },
],
},
],
},
],
};

const { data, errors, nextToken } = await client.models.Meeting.list({
Expand Down
9 changes: 3 additions & 6 deletions docs/releases/next.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# Projekte gruppieren (Version :VERSION)
# Tagespläne und Meetings vollständig laden (Version :VERSION)

## Neue Funktionen und Änderungen
## Fehlerbehebungen

- Die Ansicht in der App ist stabilisiert worden und zoomt nicht mehr in Eingabefelder ([#40](https://github.com/cabcookie/personal-crm/issues/40))
- Projektlisten lassen sich jetzt filtern nach Work In Progress, On Hold und Done ([#41](https://github.com/cabcookie/personal-crm/issues/41))
- Bei Aktivitäten kann nun das Datum geändert werden.
- In der Navigation kann nun auch zu Projekten und Accounts gewechselt werden. Mit ^+p und ^+a kann man auch direkt hinspringen.
Es wurden nicht alle Tagespläne und Meetings geladen, da wir im Moment einen Table Scan durchführen und nur bis zu 100 Datensätze prüfen und dann einen `nextToken` erhalten. Den verwenden wir jetzt, um weitere Datensätze zu laden, bis kein `nextToken` mehr zurück gegeben wird.

0 comments on commit b4e18f8

Please sign in to comment.