accomadesc 0.3.30 → 0.3.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,15 +1,13 @@
1
1
  <script lang="ts">
2
2
  import { DateTime } from 'luxon';
3
3
  import { normalizeDate } from '../helpers/normalizeDate.js';
4
- import { getContext, onMount, setContext, type Snippet } from 'svelte';
4
+ import { onMount, type Snippet } from 'svelte';
5
5
  import {
6
- OCCUPATION_STATE,
7
6
  OccupationState,
8
7
  getOccupationState,
9
8
  type AvailableSpans,
10
9
  } from './state.svelte.js';
11
10
  import Spinner from '../basic/Spinner.svelte';
12
- import { browser } from '$app/environment';
13
11
 
14
12
  let {
15
13
  url,
@@ -25,16 +23,13 @@
25
23
  children: Snippet<[AvailableSpans]>;
26
24
  } = $props();
27
25
 
28
- const oStateID = `i-${url}-${OCCUPATION_STATE}`;
29
- let occupationState: OccupationState = $state(getContext(oStateID));
30
- onMount(() => {
31
- if (!occupationState && browser) {
32
- occupationState = getOccupationState(url, debug);
33
- setContext(oStateID, occupationState);
34
- }
35
- });
26
+ let occupationState: OccupationState = getOccupationState(url, debug);
36
27
 
37
28
  let av = $derived(occupationState ? occupationState.calcAvailability(search, maxFutureDate) : {});
29
+
30
+ onMount(() => {
31
+ occupationState.loadOccupations();
32
+ });
38
33
  </script>
39
34
 
40
35
  {#if !occupationState || occupationState.loading}
@@ -4,7 +4,6 @@
4
4
  defaultMonthHeaderFormat,
5
5
  defaultMonthLabels,
6
6
  defaultWeekdayLabels,
7
- OCCUPATION_STATE,
8
7
  OccupationState,
9
8
  getOccupationState,
10
9
  occupationTypeFormatting,
@@ -13,11 +12,10 @@
13
12
  type OccupationType,
14
13
  type OccuplanTranslations,
15
14
  } from './state.svelte.js';
16
- import { getContext, onMount, setContext } from 'svelte';
17
15
  import Button from '../basic/Button.svelte';
18
- import { browser } from '$app/environment';
19
16
  import Spinner from '../basic/Spinner.svelte';
20
17
  import { randomID } from '../names/gen.js';
18
+ import { onMount } from 'svelte';
21
19
 
22
20
  let {
23
21
  url,
@@ -51,14 +49,7 @@
51
49
 
52
50
  const id = randomID();
53
51
 
54
- const oStateID = `i-${url}-${OCCUPATION_STATE}`;
55
- let occupationState: OccupationState = $state(getContext(oStateID));
56
- onMount(() => {
57
- if (!occupationState && browser) {
58
- occupationState = getOccupationState(url, debug);
59
- setContext(oStateID, occupationState);
60
- }
61
- });
52
+ let occupationState: OccupationState = getOccupationState(url, debug);
62
53
 
63
54
  //let formatFun = $derived(Sqrl.compile(monthHeaderFormat, { useWith: true }));
64
55
  const monthHeader = (monthNum: MonthNumbers, year: number): string => {
@@ -153,6 +144,10 @@
153
144
  return res;
154
145
  }, [] as OccupationType[]),
155
146
  );
147
+
148
+ onMount(() => {
149
+ occupationState.loadOccupations();
150
+ });
156
151
  </script>
157
152
 
158
153
  {#if !occupationState || occupationState.loading}
@@ -4,15 +4,13 @@
4
4
  defaultMonthHeaderFormat,
5
5
  defaultMonthLabels,
6
6
  defaultWeekdayLabels,
7
- OCCUPATION_STATE,
8
7
  OccupationState,
9
8
  getOccupationState,
10
9
  realFirstMonth,
11
10
  type OccuplanTranslations,
12
11
  } from './state.svelte.js';
13
- import { getContext, onMount, setContext, untrack } from 'svelte';
12
+ import { onMount, untrack } from 'svelte';
14
13
  import Button from '../basic/Button.svelte';
15
- import { browser } from '$app/environment';
16
14
  import Spinner from '../basic/Spinner.svelte';
17
15
  import { normalizeDate } from '../helpers/normalizeDate.js';
18
16
 
@@ -58,14 +56,7 @@
58
56
  dateSelected?: (arrival: DateTime, leave: DateTime) => void;
59
57
  } = $props();
60
58
 
61
- const oStateID = `i-${url}-${OCCUPATION_STATE}`;
62
- let occupationState: OccupationState = $state(getContext(oStateID));
63
- onMount(() => {
64
- if (!occupationState && browser) {
65
- occupationState = getOccupationState(url, debug);
66
- setContext(oStateID, occupationState);
67
- }
68
- });
59
+ let occupationState: OccupationState = getOccupationState(url, debug);
69
60
 
70
61
  const monthHeader = (monthNum: MonthNumbers, year: number): string => {
71
62
  const monthLabel = monthLabels[monthNum];
@@ -200,6 +191,10 @@
200
191
  let firstDayOfWeek = w.startOf('week');
201
192
  return lastDayOfMonth < firstDayOfWeek;
202
193
  };
194
+
195
+ onMount(() => {
196
+ occupationState.loadOccupations();
197
+ });
203
198
  </script>
204
199
 
205
200
  {#if !occupationState || occupationState.loading}
@@ -8,16 +8,15 @@
8
8
  occupationTypeFormatting,
9
9
  type OccupationType,
10
10
  type OccuplanTranslations,
11
- OCCUPATION_STATE,
12
11
  type DayHelper,
13
12
  type FirstMonth,
14
13
  realFirstMonth,
15
14
  } from './state.svelte.js';
16
15
  import Button from '../basic/Button.svelte';
17
16
  import { browser } from '$app/environment';
18
- import { getContext, onMount, setContext } from 'svelte';
19
17
  import Spinner from '../basic/Spinner.svelte';
20
18
  import { randomID } from '../names/gen.js';
19
+ import { onMount } from 'svelte';
21
20
 
22
21
  let {
23
22
  url,
@@ -48,14 +47,7 @@
48
47
 
49
48
  const id = randomID();
50
49
 
51
- const oStateID = `i-${url}-${OCCUPATION_STATE}`;
52
- let occupationState: OccupationState = $state(getContext(oStateID));
53
- onMount(() => {
54
- if (!occupationState && browser) {
55
- occupationState = getOccupationState(url, debug);
56
- setContext(oStateID, occupationState);
57
- }
58
- });
50
+ let occupationState: OccupationState = getOccupationState(url, debug);
59
51
 
60
52
  let page: number = $state(0);
61
53
  let rfMonth: number | DateTime = $derived(realFirstMonth(firstMonth, numberOfMonth, page));
@@ -134,6 +126,10 @@
134
126
  }, [] as OccupationType[])
135
127
  : [],
136
128
  );
129
+
130
+ onMount(() => {
131
+ occupationState.loadOccupations();
132
+ });
137
133
  </script>
138
134
 
139
135
  {#if !occupationState || occupationState.loading}
@@ -74,7 +74,7 @@ export declare class OccupationState {
74
74
  loading: boolean;
75
75
  debug: boolean;
76
76
  constructor(iCalURL: string, debug?: boolean);
77
- private loadOccupations;
77
+ loadOccupations: () => Promise<boolean>;
78
78
  private eventsIncomingCallback;
79
79
  private dayKey;
80
80
  private updateOccupiedDays;
@@ -2,6 +2,7 @@ import { normalizeDate } from '../helpers/normalizeDate.js';
2
2
  import { getEvents } from '../helpers/readICS.js';
3
3
  import { DateTime } from 'luxon';
4
4
  import { DateTime as luxon } from 'luxon';
5
+ import { getContext, setContext } from 'svelte';
5
6
  export const OCCUPATION_STATE = 'occupation-state';
6
7
  export const occupationTypeFormattingByOccupation = (o) => {
7
8
  return occupationTypeFormatting(o?.type);
@@ -185,7 +186,7 @@ export class OccupationState {
185
186
  if (this.debug)
186
187
  console.log('Constructing OState with CalUrl: ', iCalURL);
187
188
  this.iCalURL = iCalURL;
188
- this.loadOccupations();
189
+ //this.loadOccupations();
189
190
  }
190
191
  loadOccupations = async () => {
191
192
  if (this.debug)
@@ -392,14 +393,13 @@ export class OccupationState {
392
393
  `;
393
394
  };
394
395
  }
395
- let _instances = {};
396
396
  export const getOccupationState = (url, debug = false) => {
397
397
  if (debug)
398
398
  console.log('Get OState /w url', url);
399
- const currentInstance = _instances[url];
400
- if (currentInstance)
401
- return currentInstance;
402
- const newInstance = new OccupationState(url, debug);
403
- _instances[url] = newInstance;
404
- return _instances[url];
399
+ const stateID = `i-${url}-${OCCUPATION_STATE}`;
400
+ let _instance = getContext(stateID);
401
+ if (_instance)
402
+ return _instance;
403
+ setContext(stateID, new OccupationState(url, debug));
404
+ return getContext(stateID);
405
405
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "accomadesc",
3
- "version": "0.3.30",
3
+ "version": "0.3.31",
4
4
  "files": [
5
5
  "dist",
6
6
  "!dist/**/*.test.*",