-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(occurrences): unify state provider (#109)
* refactor(occurrences): unify state provider * Cosmetic fixes
- Loading branch information
Showing
17 changed files
with
1,163 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './supabaseClient'; | ||
export * from './occurrencesCache'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { type Occurrence } from '@models'; | ||
|
||
export const occurrencesCache: Map<string, Occurrence[]> = new Map(); | ||
|
||
export const cacheOccurrences = ( | ||
range: [number, number], | ||
occurrences: Occurrence[] | ||
) => { | ||
occurrencesCache.set(range.toString(), occurrences); | ||
}; | ||
|
||
export const cacheOccurrence = ( | ||
range: [number, number], | ||
occurrence: Occurrence | ||
) => { | ||
const cachedOccurrences = occurrencesCache.get(range.toString()); | ||
|
||
if (cachedOccurrences) { | ||
occurrencesCache.set(range.toString(), [...cachedOccurrences, occurrence]); | ||
} | ||
}; | ||
|
||
export const uncacheOccurrence = ( | ||
range: [number, number], | ||
occurrenceId: number | ||
) => { | ||
const cachedOccurrences = occurrencesCache.get(range.toString()); | ||
|
||
if (cachedOccurrences) { | ||
occurrencesCache.set( | ||
range.toString(), | ||
cachedOccurrences.filter((o) => o.id !== occurrenceId) | ||
); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,25 @@ | ||
import type { CamelCasedPropertiesDeep } from 'type-fest'; | ||
|
||
import type { TablesInsert, Tables } from '../../supabase/database.types'; | ||
|
||
import { type Habit } from './habit.model'; | ||
import { type Trait } from './trait.model'; | ||
|
||
export type Occurrence = { | ||
id: number; | ||
createdAt: string; | ||
updatedAt: string | null; | ||
timestamp: number; | ||
day: string; | ||
time: string | null; | ||
userId: string; | ||
habitId: number; | ||
habit: | ||
| (Pick<Habit, 'name' | 'iconPath'> & { | ||
trait: Pick<Trait, 'id' | 'name' | 'color'> | null; | ||
}) | ||
| null; | ||
type BaseOccurrence = CamelCasedPropertiesDeep<Tables<'occurrences'>>; | ||
|
||
type OccurrenceHabit = Pick<Habit, 'name' | 'iconPath'>; | ||
|
||
type HabitWithTrait = OccurrenceHabit & { | ||
trait: Pick<Trait, 'id' | 'name' | 'color'> | null; | ||
}; | ||
|
||
export type Occurrence = BaseOccurrence & { | ||
habit: HabitWithTrait | null; | ||
}; | ||
|
||
type OccurrenceDate = string; | ||
export type OccurrencesDateMap = Record<OccurrenceDate, Occurrence[]>; | ||
|
||
export type OccurrencesInsert = CamelCasedPropertiesDeep< | ||
TablesInsert<'occurrences'> | ||
>; |
Oops, something went wrong.