Skip to content
This repository has been archived by the owner on Dec 15, 2023. It is now read-only.

Commit

Permalink
fix: Move current date back to singleton
Browse files Browse the repository at this point in the history
  • Loading branch information
valentine195 committed May 14, 2023
1 parent ea34876 commit 90c3a52
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/calendar/ui/Day.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
const ephemeral = getTypedContext("ephemeralStore");
$: index = month.index;
$: year = month.year;
$: current = ephemeral.current;
$: current = $store.current;
$: eventCache = $store.eventCache;
$: viewing = ephemeral.viewing;
$: events = eventCache.getItemsOrRecalculate({
Expand Down Expand Up @@ -48,7 +48,7 @@
}
menu.addItem((item) => {
item.setTitle("Set as Today").onClick(async () => {
ephemeral.setCurrentDate({
$store.setCurrentDate({
day: number,
month: $index,
year: year.year,
Expand Down
1 change: 0 additions & 1 deletion src/calendar/ui/Month.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
$: ({ lastDay: previousLastDay, days: previousDays } = $previousMonth);
$: extraWeek = $weekdays.length - $lastDay <= 3 ? 1 : 0;
$: total = $weeks + extraWeek;
const tbody = (node: HTMLElement) => {
let row = node.createEl("tr");
if ($staticConfiguration.overflow) {
Expand Down
4 changes: 2 additions & 2 deletions src/calendar/ui/Nav.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
const ephemeral = getTypedContext("ephemeralStore");
const plugin = getTypedContext("plugin");
const store = $global;
const { displayingMonth, displayingYear, currentDisplay } = ephemeral;
const { staticStore } = store;
const { displayingMonth, displayingYear } = ephemeral;
const { staticStore, currentDisplay } = store;
const { staticConfiguration } = staticStore;
const left = (node: HTMLElement) => {
new ExtraButtonComponent(node).setIcon("left-arrow");
Expand Down
1 change: 1 addition & 0 deletions src/calendar/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export default class FantasyCalendarView extends ItemView {
this.plugin.onSettingsLoad(() => this.display());
}
async display() {
//todo: inject store here, subscribe to
new CalendarUI({
target: this.contentEl,
props: {
Expand Down
21 changes: 11 additions & 10 deletions src/stores/calendar.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ export function createCalendarStore(
update,
subscribe,

current,
currentDisplay: derived([current, store], ([current, calendar]) => {
return dateString(current, calendar);
}),
setCurrentDate: (date: FcDate) =>
store.update((cal) => {
cal.current = { ...date };
return cal;
}),
updateCalendar: (calendar: Calendar) => update((cal) => calendar),
eventCache,
addEvent: (date: FcDate) => {
Expand Down Expand Up @@ -87,21 +96,13 @@ export function getEphemeralStore(
base: Calendar,
yearCalculator: YearStoreCache
) {
const current = writable({ ...base.current });

const displaying = writable({ ...base.current });
const viewing = writable<FcDate | null>();
return {
current,
currentDisplay: derived([current, store], ([current, calendar]) => {
return dateString(current, calendar);
}),
setCurrentDate: (date: FcDate) => current.set({ ...date }),

//Displayed Date
displaying,
goToToday: () => displaying.set({ ...get(current) }),
displayDate: (date: FcDate = get(current)) =>
goToToday: () => displaying.set({ ...base.current }),
displayDate: (date: FcDate = base.current) =>
displaying.set({ ...date }),
displayingDisplay: derived(
[displaying, store],
Expand Down

0 comments on commit 90c3a52

Please sign in to comment.