Skip to content

Commit 1cf324e

Browse files
committed
fix(bookmarks): updated bookmarks
1 parent 35212d5 commit 1cf324e

7 files changed

Lines changed: 71 additions & 136 deletions

File tree

src/app/features/my-projects/my-projects.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@ export class MyProjectsComponent implements OnInit {
237237
createFilters(params: QueryParams): MyResourcesSearchFilters {
238238
return {
239239
searchValue: params.search || '',
240-
searchFields: ['title', 'tags', 'description'],
240+
searchFields:
241+
this.selectedTab() === MyProjectsTab.Preprints ? ['title', 'tags'] : ['title', 'tags', 'description'],
241242
sortColumn: params.sortColumn,
242243
sortOrder: params.sortOrder,
243244
};

src/app/features/project/overview/components/overview-toolbar/overview-toolbar.component.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,12 @@ export class OverviewToolbarComponent {
5858
private translateService = inject(TranslateService);
5959
private toastService = inject(ToastService);
6060
private socialShareService = inject(SocialShareService);
61-
protected destroyRef = inject(DestroyRef);
6261
private readonly router = inject(Router);
6362
private readonly route = inject(ActivatedRoute);
64-
protected isPublic = signal(false);
65-
protected isBookmarked = signal(false);
63+
64+
destroyRef = inject(DestroyRef);
65+
isPublic = signal(false);
66+
isBookmarked = signal(false);
6667

6768
isCollectionsRoute = input<boolean>(false);
6869
isAdmin = input.required<boolean>();
@@ -71,16 +72,16 @@ export class OverviewToolbarComponent {
7172
projectDescription = input<string>('');
7273
showViewOnlyLinks = input<boolean>(true);
7374

74-
protected isBookmarksLoading = select(MyResourcesSelectors.getBookmarksLoading);
75-
protected isBookmarksSubmitting = select(BookmarksSelectors.getBookmarksCollectionIdSubmitting);
76-
protected bookmarksCollectionId = select(BookmarksSelectors.getBookmarksCollectionId);
77-
protected bookmarkedProjects = select(MyResourcesSelectors.getBookmarks);
78-
protected socialsActionItems = computed(() => {
75+
isBookmarksLoading = select(MyResourcesSelectors.getBookmarksLoading);
76+
isBookmarksSubmitting = select(BookmarksSelectors.getBookmarksCollectionIdSubmitting);
77+
bookmarksCollectionId = select(BookmarksSelectors.getBookmarksCollectionId);
78+
bookmarkedProjects = select(MyResourcesSelectors.getBookmarks);
79+
socialsActionItems = computed(() => {
7980
const shareableContent = this.createShareableContent();
8081
return shareableContent ? this.buildSocialActionItems(shareableContent) : [];
8182
});
8283

83-
protected readonly forkActionItems = [
84+
readonly forkActionItems = [
8485
{
8586
label: 'project.overview.actions.forkProject',
8687
command: () => this.handleForkResource(),
@@ -96,7 +97,7 @@ export class OverviewToolbarComponent {
9697
},
9798
},
9899
];
99-
protected readonly ResourceType = ResourceType;
100+
readonly ResourceType = ResourceType;
100101

101102
get isRegistration(): boolean {
102103
return this.currentResource()?.resourceType === ResourceType.Registration;
@@ -134,7 +135,7 @@ export class OverviewToolbarComponent {
134135
});
135136
}
136137

137-
protected handleToggleProjectPublicity(): void {
138+
handleToggleProjectPublicity(): void {
138139
const resource = this.currentResource();
139140
if (!resource) return;
140141

@@ -162,7 +163,7 @@ export class OverviewToolbarComponent {
162163
});
163164
}
164165

165-
protected toggleBookmark(): void {
166+
toggleBookmark(): void {
166167
const resource = this.currentResource();
167168
const bookmarksId = this.bookmarksCollectionId();
168169

src/app/shared/services/bookmarks.service.ts

Lines changed: 17 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,24 @@ import { inject, Injectable } from '@angular/core';
55
import { SparseCollectionsResponseJsonApi } from '@shared/models';
66
import { JsonApiService } from '@shared/services';
77

8+
import { ResourceType } from '../enums';
9+
810
import { environment } from 'src/environments/environment';
911

1012
@Injectable({
1113
providedIn: 'root',
1214
})
1315
export class BookmarksService {
1416
private jsonApiService = inject(JsonApiService);
17+
private readonly urlMap = new Map<ResourceType, string>([
18+
[ResourceType.Project, 'linked_nodes'],
19+
[ResourceType.Registration, 'linked_registrations'],
20+
]);
21+
22+
private readonly resourceMap = new Map<ResourceType, string>([
23+
[ResourceType.Project, 'nodes'],
24+
[ResourceType.Registration, 'registrations'],
25+
]);
1526

1627
getBookmarksCollectionId(): Observable<string> {
1728
const params: Record<string, unknown> = {
@@ -28,58 +39,16 @@ export class BookmarksService {
2839
);
2940
}
3041

31-
addProjectToBookmarks(bookmarksId: string, projectId: string): Observable<void> {
32-
const url = `${environment.apiUrl}/collections/${bookmarksId}/relationships/linked_nodes/`;
33-
const payload = {
34-
data: [
35-
{
36-
type: 'nodes',
37-
id: projectId,
38-
},
39-
],
40-
};
41-
42-
return this.jsonApiService.post<void>(url, payload);
43-
}
44-
45-
removeProjectFromBookmarks(bookmarksId: string, projectId: string): Observable<void> {
46-
const url = `${environment.apiUrl}/collections/${bookmarksId}/relationships/linked_nodes/`;
47-
const payload = {
48-
data: [
49-
{
50-
type: 'nodes',
51-
id: projectId,
52-
},
53-
],
54-
};
55-
56-
return this.jsonApiService.delete(url, payload);
57-
}
58-
59-
addRegistrationToBookmarks(bookmarksId: string, registryId: string): Observable<void> {
60-
const url = `${environment.apiUrl}/collections/${bookmarksId}/relationships/linked_registrations/`;
61-
const payload = {
62-
data: [
63-
{
64-
type: 'registrations',
65-
id: registryId,
66-
},
67-
],
68-
};
42+
addResourceToBookmarks(bookmarksId: string, resourceId: string, resourceType: ResourceType): Observable<void> {
43+
const url = `${environment.apiUrl}/collections/${bookmarksId}/relationships/${this.urlMap.get(resourceType)}/`;
44+
const payload = { data: [{ type: this.resourceMap.get(resourceType), id: resourceId }] };
6945

7046
return this.jsonApiService.post<void>(url, payload);
7147
}
7248

73-
removeRegistrationFromBookmarks(bookmarksId: string, registryId: string): Observable<void> {
74-
const url = `${environment.apiUrl}/collections/${bookmarksId}/relationships/linked_registrations/`;
75-
const payload = {
76-
data: [
77-
{
78-
type: 'registrations',
79-
id: registryId,
80-
},
81-
],
82-
};
49+
removeResourceFromBookmarks(bookmarksId: string, resourceId: string, resourceType: ResourceType): Observable<void> {
50+
const url = `${environment.apiUrl}/collections/${bookmarksId}/relationships/${this.urlMap.get(resourceType)}/`;
51+
const payload = { data: [{ type: this.resourceMap.get(resourceType), id: resourceId }] };
8352

8453
return this.jsonApiService.delete(url, payload);
8554
}

src/app/shared/stores/bookmarks/bookmarks.model.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,12 @@ import { AsyncStateModel } from '@shared/models/store';
33
export interface BookmarksStateModel {
44
bookmarksId: AsyncStateModel<string>;
55
}
6+
7+
export const BOOKMARKS_DEFAULTS: BookmarksStateModel = {
8+
bookmarksId: {
9+
data: '',
10+
isLoading: false,
11+
isSubmitting: false,
12+
error: null,
13+
},
14+
};

src/app/shared/stores/bookmarks/bookmarks.selectors.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,4 @@ export class BookmarksSelectors {
1818
static getBookmarksCollectionIdSubmitting(state: BookmarksStateModel) {
1919
return state.bookmarksId.isSubmitting;
2020
}
21-
22-
@Selector([BookmarksState])
23-
static getBookmarksError(state: BookmarksStateModel) {
24-
return state.bookmarksId.error;
25-
}
2621
}
Lines changed: 28 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,14 @@
11
import { Action, State, StateContext } from '@ngxs/store';
22

3-
import { catchError, EMPTY, tap } from 'rxjs';
3+
import { catchError, tap } from 'rxjs';
44

55
import { inject, Injectable } from '@angular/core';
66

7-
import { ResourceType } from '@shared/enums';
87
import { handleSectionError } from '@shared/helpers';
98
import { BookmarksService } from '@shared/services';
109

1110
import { AddResourceToBookmarks, GetBookmarksCollectionId, RemoveResourceFromBookmarks } from './bookmarks.actions';
12-
import { BookmarksStateModel } from './bookmarks.model';
13-
14-
const BOOKMARKS_DEFAULTS: BookmarksStateModel = {
15-
bookmarksId: {
16-
data: '',
17-
isLoading: false,
18-
isSubmitting: false,
19-
error: null,
20-
},
21-
};
11+
import { BOOKMARKS_DEFAULTS, BookmarksStateModel } from './bookmarks.model';
2212

2313
@State<BookmarksStateModel>({
2414
name: 'bookmarks',
@@ -63,34 +53,19 @@ export class BookmarksState {
6353
},
6454
});
6555

66-
switch (action.resourceType) {
67-
case ResourceType.Project:
68-
return this.bookmarksService.addProjectToBookmarks(action.bookmarksId, action.resourceId).pipe(
69-
tap(() => {
70-
ctx.patchState({
71-
bookmarksId: {
72-
...state.bookmarksId,
73-
isSubmitting: false,
74-
},
75-
});
76-
}),
77-
catchError((error) => handleSectionError(ctx, 'bookmarksId', error))
78-
);
79-
case ResourceType.Registration:
80-
return this.bookmarksService.addRegistrationToBookmarks(action.bookmarksId, action.resourceId).pipe(
81-
tap(() => {
82-
ctx.patchState({
83-
bookmarksId: {
84-
...state.bookmarksId,
85-
isSubmitting: false,
86-
},
87-
});
88-
}),
89-
catchError((error) => handleSectionError(ctx, 'bookmarksId', error))
90-
);
91-
default:
92-
return EMPTY;
93-
}
56+
return this.bookmarksService
57+
.addResourceToBookmarks(action.bookmarksId, action.resourceId, action.resourceType)
58+
.pipe(
59+
tap(() => {
60+
ctx.patchState({
61+
bookmarksId: {
62+
...state.bookmarksId,
63+
isSubmitting: false,
64+
},
65+
});
66+
}),
67+
catchError((error) => handleSectionError(ctx, 'bookmarksId', error))
68+
);
9469
}
9570

9671
@Action(RemoveResourceFromBookmarks)
@@ -103,33 +78,18 @@ export class BookmarksState {
10378
},
10479
});
10580

106-
switch (action.resourceType) {
107-
case ResourceType.Project:
108-
return this.bookmarksService.removeProjectFromBookmarks(action.bookmarksId, action.resourceId).pipe(
109-
tap(() => {
110-
ctx.patchState({
111-
bookmarksId: {
112-
...state.bookmarksId,
113-
isSubmitting: false,
114-
},
115-
});
116-
}),
117-
catchError((error) => handleSectionError(ctx, 'bookmarksId', error))
118-
);
119-
case ResourceType.Registration:
120-
return this.bookmarksService.removeRegistrationFromBookmarks(action.bookmarksId, action.resourceId).pipe(
121-
tap(() => {
122-
ctx.patchState({
123-
bookmarksId: {
124-
...state.bookmarksId,
125-
isSubmitting: false,
126-
},
127-
});
128-
}),
129-
catchError((error) => handleSectionError(ctx, 'bookmarksId', error))
130-
);
131-
default:
132-
return EMPTY;
133-
}
81+
return this.bookmarksService
82+
.removeResourceFromBookmarks(action.bookmarksId, action.resourceId, action.resourceType)
83+
.pipe(
84+
tap(() => {
85+
ctx.patchState({
86+
bookmarksId: {
87+
...state.bookmarksId,
88+
isSubmitting: false,
89+
},
90+
});
91+
}),
92+
catchError((error) => handleSectionError(ctx, 'bookmarksId', error))
93+
);
13494
}
13595
}

src/assets/i18n/en.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -650,8 +650,8 @@
650650
"success": "Project has been duplicated successfully"
651651
},
652652
"bookmark": {
653-
"add": "Project has been added to bookmarks",
654-
"remove": "Project has been removed from bookmarks"
653+
"add": "Successfully added to bookmarks",
654+
"remove": "Successfully removed from bookmarks"
655655
}
656656
},
657657
"linkProject": {

0 commit comments

Comments
 (0)