@hyvor/design 2.0.9 → 2.0.11

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,6 +1,6 @@
1
1
  <script lang="ts">
2
2
  import { onMount } from 'svelte';
3
- import { barUnreadUpdates, UnreadUpdatesTimeLocalStorage, type BarUpdate } from './bar.js';
3
+ import { barUnreadUpdates, barLastReadUpdatesAt, type BarUpdate } from './bar.js';
4
4
  import IconBoxArrowUpRight from '@hyvor/icons/IconBoxArrowUpRight';
5
5
 
6
6
  import {
@@ -17,23 +17,23 @@
17
17
  let loading = $state(true);
18
18
  let error = $state(false);
19
19
 
20
- let lastReadTime: null | number = $state(null);
20
+ let lastReadTime: null | number = $derived($barLastReadUpdatesAt);
21
21
 
22
22
  const cloudContext = $derived(getCloudContext());
23
23
 
24
24
  function fetchUpdates() {
25
25
  error = false;
26
- lastReadTime = UnreadUpdatesTimeLocalStorage.get();
27
26
  loading = true;
28
27
 
29
- fetch(cloudContext.instance + '/api/public/updates?types=company,' + cloudContext.component)
28
+ fetch(cloudContext.instance + '/api/public/updates?types=company,' + cloudContext.component, {
29
+ credentials: 'include'
30
+ })
30
31
  .then((response) => response.json())
31
32
  .then((data) => {
32
33
  updates = data;
33
34
 
34
35
  barUnreadUpdates.set(0);
35
- // set as last read now
36
- UnreadUpdatesTimeLocalStorage.setNow();
36
+ barLastReadUpdatesAt.set(Math.floor(Date.now() / 1000));
37
37
  })
38
38
  .catch(() => {
39
39
  error = true;
@@ -15,13 +15,8 @@ export interface BarUpdate {
15
15
  export type BarUpdateType = 'company' | 'core' | 'talk' | 'blogs' | 'post' | 'relay' | 'fortguard';
16
16
  export declare const barUnreadUpdates: import("svelte/store").Writable<number>;
17
17
  export declare const barHasFailedInvoices: import("svelte/store").Writable<boolean>;
18
+ export declare const barLastReadUpdatesAt: import("svelte/store").Writable<number | null>;
18
19
  export declare function initBar(): Promise<void>;
19
- export declare class UnreadUpdatesTimeLocalStorage {
20
- static KEY: string;
21
- static get(): number | null;
22
- static set(value: string): void;
23
- static setNow(): void;
24
- }
25
20
  export declare const bar: {
26
21
  /**
27
22
  * Refetches data like user info, unread updates, billing data, etc.
@@ -2,6 +2,7 @@ import { writable } from 'svelte/store';
2
2
  import { getCloudContext } from '../CloudContext/cloudContextState.svelte.js';
3
3
  export const barUnreadUpdates = writable(0);
4
4
  export const barHasFailedInvoices = writable(false);
5
+ export const barLastReadUpdatesAt = writable(null);
5
6
  export async function initBar() {
6
7
  const { user, organization, instance, component, deployment } = getCloudContext();
7
8
  if (deployment !== 'cloud') {
@@ -9,10 +10,6 @@ export async function initBar() {
9
10
  }
10
11
  const query = new URLSearchParams();
11
12
  query.set('component', component);
12
- const lastUnreadTime = UnreadUpdatesTimeLocalStorage.get();
13
- if (lastUnreadTime) {
14
- query.set('last_read_updates_at', lastUnreadTime.toString());
15
- }
16
13
  const response = await fetch(instance + '/api/v2/cloud/bar/init?' + query.toString(), {
17
14
  credentials: 'include'
18
15
  });
@@ -27,57 +24,11 @@ export async function initBar() {
27
24
  }
28
25
  barHasFailedInvoices.set(data.has_failed_invoices);
29
26
  barUnreadUpdates.set(data.unread_updates);
30
- if (lastUnreadTime === null) {
31
- UnreadUpdatesTimeLocalStorage.setNow();
32
- }
33
- }
34
- export class UnreadUpdatesTimeLocalStorage {
35
- static KEY = 'unread_updates';
36
- static get() {
37
- const val = BarLocalStorage.get(UnreadUpdatesTimeLocalStorage.KEY);
38
- if (val) {
39
- return Number(val);
40
- }
41
- return null;
42
- }
43
- static set(value) {
44
- BarLocalStorage.set(UnreadUpdatesTimeLocalStorage.KEY, value);
45
- }
46
- static setNow() {
47
- UnreadUpdatesTimeLocalStorage.set(Math.floor(Date.now() / 1000).toString());
48
- }
49
- }
50
- class BarLocalStorage {
51
- static KEY = 'hyvor_bar';
52
- static getJson() {
53
- try {
54
- const data = localStorage.getItem(BarLocalStorage.KEY);
55
- if (data) {
56
- return JSON.parse(data);
57
- }
58
- }
59
- catch (e) {
60
- console.error(e);
61
- return null;
62
- }
63
- return null;
64
- }
65
- static get(key) {
66
- const data = BarLocalStorage.getJson();
67
- if (data) {
68
- return data[key];
69
- }
70
- return null;
27
+ if (data.last_read_updates_at !== null) {
28
+ barLastReadUpdatesAt.set(data.last_read_updates_at);
71
29
  }
72
- static set(key, value) {
73
- try {
74
- const data = BarLocalStorage.getJson() || {};
75
- data[key] = value;
76
- localStorage.setItem(BarLocalStorage.KEY, JSON.stringify(data));
77
- }
78
- catch (e) {
79
- console.error(e);
80
- }
30
+ else {
31
+ barLastReadUpdatesAt.set(Math.floor(Date.now() / 1000));
81
32
  }
82
33
  }
83
34
  // exported to be used from outside
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyvor/design",
3
- "version": "2.0.9",
3
+ "version": "2.0.11",
4
4
  "license": "MIT",
5
5
  "private": false,
6
6
  "repository": {