Skip to content

Commit

Permalink
feat(bookmark-module): added functionality fro bookmark favorites
Browse files Browse the repository at this point in the history
  • Loading branch information
Noggling authored and odinr committed Apr 11, 2023
1 parent 1886bed commit 0d66c30
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
33 changes: 33 additions & 0 deletions packages/modules/bookmark/src/bookmark-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,27 @@ export interface IBookmarkModuleProvider {
*/
deleteBookmarkByIdAsync(bookmarkId: string): Promise<string>;

/**
* Function for adding external bookmark to user's bookmarks.
* @param {string} bookmarkId
* @return {Promise<string>} void
*/
addBookmarkFavoriteAsync(bookmarkId: string): Promise<void>;

/**
* Function for removing external bookmark to user's bookmarks.
* @param {string} bookmarkId
* @return {Promise<void>} - void
*/
removeBookmarkFavoriteAsync(bookmarkId: string): Promise<void>;

/**
* Function for verifying that a bookmark belongs to the current user.
* @param {string} bookmarkId
* @return {Promise<string>} - void
*/
verifyBookmarkFavoriteAsync(bookmarkId: string): Promise<boolean>;

/**
* Function for setting the current bookmark, when successful this will update the bookmark list.
* @template TData - Bookmark payload type.
Expand Down Expand Up @@ -207,6 +228,18 @@ export class BookmarkModuleProvider implements IBookmarkModuleProvider {
return this._bookmarkClient.deleteBookmarkByIdAsync(bookmarkId);
}

public async addBookmarkFavoriteAsync(bookmarkId: string): Promise<void> {
await this._bookmarkClient.addBookmarkFavoriteAsync(bookmarkId);
}

public async removeBookmarkFavoriteAsync(bookmarkId: string): Promise<void> {
await this._bookmarkClient.removeBookmarkFavoriteAsync(bookmarkId);
}

public async verifyBookmarkFavoriteAsync(bookmarkId: string): Promise<boolean> {
return await this._bookmarkClient.verifyBookmarkFavoriteAsync(bookmarkId);
}

public addStateCreator<T>(cb: CreateBookmarkFn<T>, key?: keyof T): VoidFunction {
const bookmarkCreatorKey = key ? key : '#creator';

Expand Down
14 changes: 14 additions & 0 deletions packages/modules/bookmark/src/client/bookmarkClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,20 @@ export class BookmarkClient {
return lastValueFrom(this.deleteBookmarkById(bookmarkId));
}

public async addBookmarkFavoriteAsync(bookmarkId: string): Promise<void> {
this.#bookmarkAPiClient.addFavorite('v1', { bookmarkId });
}

public async removeBookmarkFavoriteAsync(bookmarkId: string): Promise<void> {
this.#bookmarkAPiClient.removeFavorite('v1', { bookmarkId });
}

public async verifyBookmarkFavoriteAsync(bookmarkId: string): Promise<boolean> {
const response = await this.#bookmarkAPiClient.verifyFavorite('v1', { bookmarkId });
if (response.ok) return true;
return false;
}

dispose(): void {
this.#subscriptions.unsubscribe();
}
Expand Down
25 changes: 25 additions & 0 deletions vue-press/src/modules/bookmark/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,31 @@ If not provided the current bookmark state will be set to undefined.
setCurrentBookmark<TData>(idOrItem?: string | Bookmark<TData>): void;
```

#### addBookmarkFavoriteAsync

A bookmark can be sheared with other users, when reserving a sheared bookmark this can be added to you collection of bookmarks.
Function for adding external bookmark to users bookmarks .

```ts
addBookmarkFavoriteAsync(bookmarkId: string): Promise<void>;
```

#### removeBookmarkFavoriteAsync

Function for removing external bookmark to user's bookmarks.

```ts
removeBookmarkFavoriteAsync(bookmarkId: string): Promise<void>;
```

#### verifyBookmarkFavoriteAsync

Function for verifying that a bookmark belongs to the current user.

```ts
verifyBookmarkFavoriteAsync(bookmarkId: string): Promise<boolean>;
```

#### dispose

disposes of the class and unsubscribes all subscriptions.
Expand Down

0 comments on commit 0d66c30

Please sign in to comment.