Skip to content

Commit

Permalink
chore: Rename FcDate and FcEvent types
Browse files Browse the repository at this point in the history
  • Loading branch information
valentine195 committed Aug 25, 2023
1 parent 4a7f85b commit acb634a
Show file tree
Hide file tree
Showing 29 changed files with 294 additions and 254 deletions.
14 changes: 7 additions & 7 deletions src/@types/calendar.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Moon } from ".";
import { FcEvent, FcEventCategory } from ".";
import { CalEvent, CalEventCategory } from ".";

export interface FcDate {
export interface CalDate {
day: number;
month: number;
year: number;
Expand All @@ -12,9 +12,9 @@ export interface Calendar {
name: string;
description: string;
static: StaticCalendarData;
current: FcDate;
events: FcEvent[];
categories: FcEventCategory[];
current: CalDate;
events: CalEvent[];
categories: CalEventCategory[];
date?: number;
displayWeeks?: boolean;
autoParse: boolean;
Expand All @@ -39,7 +39,7 @@ export interface StaticCalendarData {
years?: Year[];
}

export interface FcDate {
export interface CalDate {
year: number;
month: number;
day: number;
Expand Down Expand Up @@ -133,7 +133,7 @@ export interface Era {
restart: boolean;
endsYear: boolean;
event: boolean;
start: FcDate;
start: CalDate;
eventDescription?: string;
eventCategory?: string;
}
18 changes: 9 additions & 9 deletions src/@types/event.d.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import { Nullable } from ".";

export interface FcEventSort {
export interface CalEventSort {
timestamp: number;
order: string;
}
export interface FcEventDate {
export interface CalEventDate {
year: Nullable<number>,
month: Nullable<number>,
day: Nullable<number>
}

export interface FcEvent {
export interface CalEvent {
name: string;
description: string;
date: FcEventDate;
end?: FcEventDate;
date: CalEventDate;
end?: CalEventDate;
id: string;
note: string;
category: string;
sort: FcEventSort;
sort: CalEventSort;
formulas?: EventFormula[];
img?: string;
}
Expand All @@ -30,14 +30,14 @@ interface FormulaInterval {
timespan: "days";
}

export interface ColorEvent extends FcEvent {
export interface ColorEvent extends CalEvent {
color: string;
}

export interface FcEventCategory {
export interface CalEventCategory {
name: string;
color: string;
id: string;
}

export interface FcEventCondition {}
export interface CalEventCondition {}
32 changes: 31 additions & 1 deletion src/api/api.ts
Original file line number Diff line number Diff line change
@@ -1 +1,31 @@
export class API {}
import type { Calendar, CalDate, CalEvent } from "src/@types";
import { CalendarStore } from "src/stores/calendar.store";
import { get } from "svelte/store";

export class API {
#store: CalendarStore;
#object: Calendar;
constructor(store: CalendarStore) {
this.#store = store;
}

/**
* Transform a day, month, year definition into a CalDate
* @param day Day number
* @param month Month number (0 indexed)
* @param year Year number
* @returns {CalDate}
*/
getDate(day: number, month: number, year: number): CalDate {
return { day, month, year };
}

/** Get all events for the loaded calendar. */
getEvents(): CalEvent[] {
return get(this.#store.eventCache.entities);
}
/** Get all events on a specific date. */
getEventsOnDay(day: CalDate): CalEvent[] {
return get(this.#store.eventCache.getItemsOrRecalculate(day));
}
}
4 changes: 2 additions & 2 deletions src/calendar/event-modal.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { MarkdownRenderer } from "obsidian";
import type { FcEvent } from "src/@types";
import type { CalEvent } from "src/@types";
import type FantasyCalendar from "src/main";
import { CalendariumModal } from "src/settings/modals/modal";

export class ViewEventModal extends CalendariumModal {
constructor(public event: FcEvent, public plugin: FantasyCalendar) {
constructor(public event: CalEvent, public plugin: FantasyCalendar) {
super(plugin.app);
this.containerEl.addClass("fantasy-calendar-view-event");
}
Expand Down
9 changes: 7 additions & 2 deletions src/calendar/ui/Day/Day.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { getTypedContext } from "../../view";
import Dots from "../Events/Dots.svelte";
import { Menu, TFile } from "obsidian";
import type { DayOrLeapDay, FcEvent } from "src/@types";
import type { DayOrLeapDay, CalEvent } from "src/@types";
import Moon from "../Moon.svelte";
import { ViewState } from "src/stores/calendar.store";
import Flags from "../Events/Flags.svelte";
Expand Down Expand Up @@ -80,7 +80,7 @@
});
})
);
let notes: { event: FcEvent; file: TFile }[] = [];
let notes: { event: CalEvent; file: TFile }[] = [];
for (const event of $events) {
if (!event.note) continue;
const file = app.vault.getAbstractFileByPath(event.note);
Expand Down Expand Up @@ -189,4 +189,9 @@
.opened {
border: 2px solid var(--background-modifier-border);
}
/* .moon-container {
display: flex;
flex-flow: row;
} */
</style>
2 changes: 1 addition & 1 deletion src/calendar/ui/Day/DayView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
$: daysBeforeMonth = displayedMonth.daysBefore;
$: daysBeforeDay = $daysBeforeMonth + $viewing.day;
$: events = store.eventCache.getItemsOrRecalculate($viewing);
$: console.log("🚀 ~ file: DayView.svelte:23 ~ events:", $events);
$: moons = store.moonCache.getItemsOrRecalculate($viewing);
$: displayDayNumber = $ephemeral.displayDayNumber;
$: displayMoons = $ephemeral.displayMoons;
const dispatch = createEventDispatcher();
const close = (node: HTMLElement) => {
new ExtraButtonComponent(node).setIcon("cross").setTooltip("Close");
Expand Down
6 changes: 3 additions & 3 deletions src/calendar/ui/Events/Dots.svelte
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<script lang="ts">
import { getTypedContext } from "../../view";
import Dot from "./Dot.svelte";
import type { FcEvent, FcEventCategory } from "src/@types";
import type { CalEvent, CalEventCategory } from "src/@types";
export let events: FcEvent[] = [];
export let events: CalEvent[] = [];
const store = getTypedContext("store");
const { categories } = $store;
const color = (event: FcEvent) => {
const color = (event: CalEvent) => {
return $categories.find((c) => c.id == event.category)?.color;
};
$: overflow = Math.max(events.length - 2, 0);
Expand Down
8 changes: 4 additions & 4 deletions src/calendar/ui/Events/Flag.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
<script lang="ts">
import { Platform, TFile, setIcon } from "obsidian";
import type { FcDate, FcEvent, FcEventCategory } from "src/@types";
import type { CalDate, CalEvent, CalEventCategory } from "src/@types";
import { DEFAULT_CATEGORY_COLOR } from "src/utils/constants";
import { createEventDispatcher } from "svelte";
import { getTypedContext } from "../../view";
import { ViewEventModal } from "../../event-modal";
const dispatch = createEventDispatcher();
export let event: FcEvent;
export let date: FcDate;
export let event: CalEvent;
export let date: CalDate;
const plugin = getTypedContext("plugin");
Expand Down Expand Up @@ -42,7 +42,7 @@
}
}
export let categories: FcEventCategory[];
export let categories: CalEventCategory[];
let color =
categories.find((c) => c.id == event.category)?.color ??
Expand Down
46 changes: 24 additions & 22 deletions src/calendar/ui/Events/Flags.svelte
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
<script lang="ts">
import Flag from "./Flag.svelte";
import type { FcDate, FcEvent } from "src/@types";
import type { CalDate, CalEvent } from "src/@types";
import { getTypedContext } from "../../view";
import { sortEventList } from "src/utils/functions";
import { onMount } from "svelte";
export let events: FcEvent[] = [];
export let events: CalEvent[] = [];
export let dayView: boolean = false;
export let date: FcDate;
export let date: CalDate;
const store = getTypedContext("store");
const { categories } = $store;
let height: number;
let target: Element;
$: events = sortEventList([...events]);
console.log("🚀 ~ file: Flags.svelte:19 ~ events:", events);
let overflow: number = 0;
let previousHeight = 0;
const addEvents = (height: number, target: Element) => {
const addEvents = () => {
if (events.length && target) {
if (
!dayView &&
Expand Down Expand Up @@ -46,7 +51,7 @@
(a, b) => b.getBoundingClientRect().height + a,
0
);
if (remaining < 0) {
if (remaining < 0 && height != 0) {
target.lastElementChild.detach();
overflow = events.length - events.indexOf(event);
break;
Expand All @@ -60,29 +65,26 @@
};
let container: HTMLElement;
const observer = new ResizeObserver((entries) =>
addEvents(entries[0].contentRect?.height, entries[0]?.target)
);
const observer = new ResizeObserver((entries) => {
height = entries[0].contentRect?.height;
target = entries[0]?.target;
});
$: {
console.log(
"🚀 ~ file: Flags.svelte:74 ~ dayView || (height != undefined && target)) && events:",
(dayView || (height != undefined && target)) && events
);
if ((dayView || (height != undefined && target)) && events) {
addEvents();
}
}
onMount(() => {
observer.observe(container);
});
</script>

<div class="flags-container">
{#key events}
<div class="flag-container" bind:this={container} />
<!-- {#each events.slice(0, 3) as event}
<Flag
{event}
categories={$categories}
{dayView}
{date}
on:event-click
on:event-mouseover
on:event-context
/>
{/each} -->
{/key}
<div class="flag-container" bind:this={container} />
<div class="overflow">
{#if overflow > 0}
<span>+{overflow}</span>
Expand Down
5 changes: 4 additions & 1 deletion src/calendar/ui/Month/Month.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
.month-container {
height: min-content;
}
.month-container.full {
height: 100%;
}
.month-header {
margin: 0;
Expand All @@ -63,7 +66,7 @@
var(--calendar-row-size)
);
}
.full {
.full .month {
height: 100%;
}
</style>
Loading

0 comments on commit acb634a

Please sign in to comment.