@equinor/fusion-framework-module-bookmark 1.0.2 → 1.0.3

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.
@@ -8,6 +8,12 @@ export declare const actions: {
8
8
  delete: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[id: string], string, "delete::request", never, never> & {
9
9
  success: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[id: string], string, "delete::success", never, never>;
10
10
  };
11
+ addFavorite: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[bookmark: Bookmark<unknown>], Bookmark<unknown>, "addFavorite::request", never, never> & {
12
+ success: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[bookmark: Bookmark<unknown>], Bookmark<unknown>, "addFavorite::success", never, never>;
13
+ };
14
+ removeFavorite: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[id: string], string, "removeFavorite::request", never, never> & {
15
+ success: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[id: string], string, "removeFavorite::success", never, never>;
16
+ };
11
17
  update: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[bookmark: PatchBookmark<unknown>], PatchBookmark<unknown>, "update::request", never, never> & {
12
18
  success: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[bookmark: Bookmark<unknown>], Bookmark<unknown>, "update::success", never, never>;
13
19
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@equinor/fusion-framework-module-bookmark",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "",
5
5
  "main": "./dist/esm/index.js",
6
6
  "exports": {
@@ -37,12 +37,12 @@
37
37
  "devDependencies": {
38
38
  "@equinor/fusion-framework-module": "^3.0.0",
39
39
  "@equinor/fusion-framework-module-event": "^3.0.0",
40
- "@equinor/fusion-framework-module-services": "^3.0.2",
40
+ "@equinor/fusion-framework-module-services": "^3.0.3",
41
41
  "rxjs": "^7.5.7"
42
42
  },
43
43
  "peerDependencies": {
44
44
  "@equinor/fusion-framework-module": ">=1.2.5",
45
45
  "rxjs": "^7.5.7"
46
46
  },
47
- "gitHead": "994188bbc727bc10a924eeb4d8178763a4c27ac7"
47
+ "gitHead": "6983a4f2bf1fb24c086abcba53c2349d39f34a21"
48
48
  }
@@ -229,7 +229,11 @@ export class BookmarkModuleProvider implements IBookmarkModuleProvider {
229
229
  }
230
230
 
231
231
  if (options?.updatePayload) {
232
- bookmark.payload = (await this.#createPayload()) as T;
232
+ const payload = (await this.#createPayload()) as T;
233
+ bookmark = {
234
+ ...bookmark,
235
+ payload,
236
+ };
233
237
  }
234
238
  return this._bookmarkClient.updateBookmarkAsync<T>(bookmark);
235
239
  }
@@ -14,6 +14,16 @@ export const actions = {
14
14
  (id: string) => ({ payload: id }),
15
15
  (id: string) => ({ payload: id })
16
16
  ),
17
+ addFavorite: createAsyncAction(
18
+ 'addFavorite',
19
+ (bookmark: Bookmark) => ({ payload: bookmark }),
20
+ (bookmark: Bookmark) => ({ payload: bookmark })
21
+ ),
22
+ removeFavorite: createAsyncAction(
23
+ 'removeFavorite',
24
+ (id: string) => ({ payload: id }),
25
+ (id: string) => ({ payload: id })
26
+ ),
17
27
  update: createAsyncAction(
18
28
  'update',
19
29
  (bookmark: PatchBookmark) => ({ payload: bookmark }),
@@ -155,6 +155,11 @@ export class BookmarkClient {
155
155
  this.#state.subject.addEffect('getAll::success', (action) => {
156
156
  subscriber.next(action.payload);
157
157
  subscriber.complete();
158
+
159
+ this.#event?.dispatchEvent('onBookmarksChanged', {
160
+ detail: action.payload,
161
+ source: this,
162
+ });
158
163
  })
159
164
  );
160
165
  });
@@ -228,11 +233,17 @@ export class BookmarkClient {
228
233
  }
229
234
 
230
235
  public async addBookmarkFavoriteAsync(bookmarkId: string): Promise<void> {
231
- this.#bookmarkAPiClient.addFavorite('v1', { bookmarkId });
236
+ const response = await this.#bookmarkAPiClient.addFavorite('v1', { bookmarkId });
237
+ if (response.ok && this.#currentBookmark$.value) {
238
+ this.#state.dispatch.addFavorite(this.#currentBookmark$.value);
239
+ }
232
240
  }
233
241
 
234
242
  public async removeBookmarkFavoriteAsync(bookmarkId: string): Promise<void> {
235
- this.#bookmarkAPiClient.removeFavorite('v1', { bookmarkId });
243
+ const response = await this.#bookmarkAPiClient.removeFavorite('v1', { bookmarkId });
244
+ if (response.ok) {
245
+ this.#state.dispatch.removeFavorite(bookmarkId);
246
+ }
236
247
  }
237
248
 
238
249
  public async verifyBookmarkFavoriteAsync(bookmarkId: string): Promise<boolean> {
@@ -247,6 +258,7 @@ export class BookmarkClient {
247
258
 
248
259
  #addStateEffects() {
249
260
  this.#state.subject.addEffect('create::success', (action) => {
261
+ this.#queryAllBookmarks.cache.invalidate('all-bookmarks');
250
262
  this.#currentBookmark$.next(action.payload);
251
263
  this.#event?.dispatchEvent('onBookmarkCreated', {
252
264
  detail: action.payload,
@@ -255,6 +267,8 @@ export class BookmarkClient {
255
267
  });
256
268
  });
257
269
  this.#state.subject.addEffect('delete::success', (action) => {
270
+ console.log('here');
271
+ this.#queryAllBookmarks.cache.invalidate('all-bookmarks');
258
272
  this.#event?.dispatchEvent('onBookmarkDeleted', {
259
273
  detail: action.payload,
260
274
  canBubble: true,
@@ -262,12 +276,20 @@ export class BookmarkClient {
262
276
  });
263
277
  });
264
278
  this.#state.subject.addEffect('update::success', (action) => {
279
+ this.#queryAllBookmarks.cache.invalidate('all-bookmarks');
265
280
  this.#event?.dispatchEvent('onBookmarkUpdated', {
266
281
  detail: action.payload,
267
282
  canBubble: true,
268
283
  source: this,
269
284
  });
270
285
  });
286
+ this.#state.subject.addEffect('addFavorite::request', () => {
287
+ this.#queryAllBookmarks.cache.invalidate('all-bookmarks');
288
+ });
289
+
290
+ this.#state.subject.addEffect('removeFavorite::request', () => {
291
+ this.#queryAllBookmarks.cache.invalidate('all-bookmarks');
292
+ });
271
293
  }
272
294
 
273
295
  #addSubjectFlows() {
@@ -3,7 +3,7 @@ import { BookmarksApiClient } from '@equinor/fusion-framework-module-services/bo
3
3
  import { Observable } from '@equinor/fusion-observable';
4
4
  import { filterAction } from '@equinor/fusion-observable/operators';
5
5
  import { Query } from '@equinor/fusion-query';
6
- import { switchMap, map, catchError, EMPTY } from 'rxjs';
6
+ import { switchMap, map, catchError, EMPTY, last } from 'rxjs';
7
7
  import { GetAllBookmarksParameters, Bookmark } from '../types';
8
8
  import { actions, Actions } from './bookmarkActions';
9
9
 
@@ -17,6 +17,7 @@ export const handleBookmarkGetAll =
17
17
  filterAction(actions.getAll.type),
18
18
  switchMap((action) => {
19
19
  return queryAllBookmarks.query({ isValid: action.payload }).pipe(
20
+ last(),
20
21
  map((bookmarks) =>
21
22
  actions.getAll.success(
22
23
  bookmarks.value.filter(
@@ -23,6 +23,12 @@ export const reducer = createReducer<State>(initialState, (builder) => {
23
23
  .addCase(actions.delete.success, (state, { payload }) => {
24
24
  delete state.bookmarks[payload];
25
25
  })
26
+ .addCase(actions.removeFavorite, (state, { payload }) => {
27
+ delete state.bookmarks[payload];
28
+ })
29
+ .addCase(actions.addFavorite, (state, { payload }) => {
30
+ state.bookmarks[payload.id] = payload;
31
+ })
26
32
  .addCase(actions.update.success, (state, { payload }) => {
27
33
  state.bookmarks[payload.id] = payload;
28
34
  });