Skip to content

Commit

Permalink
feat - add "clone" bookmark functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
adixchen committed Sep 4, 2023
1 parent cd5319f commit 0ab002b
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<app-save-bookmark-form
[bookmark$]="bookmark$"
[isUpdate]="false"
[cloneBookmark]="true"
></app-save-bookmark-form>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
label {
display: inline-block;
margin: 0.5em 0;
color: #607d8b;
font-weight: bold;
}
input {
height: 2em;
font-size: 1em;
padding-left: 0.4em;
}

input[type='checkbox'],
input[type='radio'] {
vertical-align: middle;
position: relative;
bottom: 1px;
}

#shared_label {
width: 100%;
}

mat-chip {
max-width: 200px;
}

.demo-chip-list {
width: 100%;
}

.markdown-link {
font-weight: normal;
margin-left: 0.15rem;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Component, OnInit } from '@angular/core';
import { Bookmark } from '../../core/model/bookmark';
import { Observable, of } from 'rxjs';

@Component({
selector: 'app-clone-bookmark',
templateUrl: './clone-bookmark.component.html',
styleUrls: ['./clone-bookmark.component.scss'],
})
export class CloneBookmarkComponent implements OnInit {
bookmark$: Observable<Bookmark>;

constructor() {}

ngOnInit(): void {
this.bookmark$ = of(window.history.state.bookmark);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { UpdatePersonalBookmarkComponent } from './update/update-personal-bookma
import { CreatePersonalBookmarkComponent } from './create/create-personal-bookmark.component';
import { CopyToMineBookmarkComponent } from './copy-to-mine/copy-to-mine-bookmark.component';
import { BookmarkDetailsComponent } from './bookmark-details/bookmark-details.component';
import { CloneBookmarkComponent } from './clone-bookmark/clone-bookmark.component';

const myBookmarksRoutes: Routes = [
{
Expand All @@ -21,6 +22,10 @@ const myBookmarksRoutes: Routes = [
path: ':id/copy-to-mine',
component: CopyToMineBookmarkComponent,
},
{
path: ':id/clone',
component: CloneBookmarkComponent,
},
{
path: ':id/details',
component: BookmarkDetailsComponent,
Expand Down
2 changes: 2 additions & 0 deletions apps/codever-ui/src/app/my-bookmarks/my-bookmarks.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ import { MatIconModule } from '@angular/material/icon';
import { MatAutocompleteModule } from '@angular/material/autocomplete';
import { MatTabsModule } from '@angular/material/tabs';
import { MatDialogModule } from '@angular/material/dialog';
import { CloneBookmarkComponent } from './clone-bookmark/clone-bookmark.component';

@NgModule({
declarations: [
CreatePersonalBookmarkComponent,
UpdatePersonalBookmarkComponent,
CopyToMineBookmarkComponent,
CloneBookmarkComponent,
MyBookmarksEntryPointComponent,
PublicBookmarkPresentDialogComponent,
SaveBookmarkFormComponent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ export class SaveBookmarkFormComponent implements OnInit {
@Input()
copyToMine = false;

@Input()
cloneBookmark = false;

bookmark: Bookmark;

constructor(
Expand Down Expand Up @@ -159,7 +162,7 @@ export class SaveBookmarkFormComponent implements OnInit {

ngOnInit(): void {
this.buildForm();
if (this.isUpdate || this.copyToMine) {
if (this.isUpdate || this.copyToMine || this.cloneBookmark) {
this.bookmark$.subscribe((bookmark) => {
this.bookmark = bookmark;
this.makePublic = this.bookmark.public;
Expand All @@ -169,6 +172,12 @@ export class SaveBookmarkFormComponent implements OnInit {
this.bookmark.public = false;
this.verifyExistenceInPersonalBookmarks(bookmark.location);
}
if (this.cloneBookmark) {
this.bookmark._id = null;
this.makePublic = false;
this.bookmark.public = false;
this.bookmark.location = 'CHANGE ME';
}
this.bookmarkForm.patchValue(this.bookmark);
this.bookmarkForm
.get('publishedOn')
Expand Down Expand Up @@ -210,7 +219,7 @@ export class SaveBookmarkFormComponent implements OnInit {
}

private onChanges() {
const isNewBookmark = !this.isUpdate && !this.copyToMine;
const isNewBookmark = !this.isUpdate && !this.copyToMine && !this.cloneBookmark
if (isNewBookmark) {
this.bookmarkForm
.get('location')
Expand Down Expand Up @@ -404,7 +413,7 @@ export class SaveBookmarkFormComponent implements OnInit {
saveBookmark(bookmark: Bookmark) {
if (this.isUpdate) {
this.updateBookmark(bookmark);
} else if (this.copyToMine) {
} else if (this.copyToMine || this.cloneBookmark) {
this.copyBookmarkToMine(bookmark);
} else {
this.createBookmark(bookmark);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { map, startWith, switchMap, takeUntil } from 'rxjs/operators';
import {
ChangeDetectionStrategy,
Component,
ElementRef,
Input,
Expand Down Expand Up @@ -55,6 +56,7 @@ import { DeleteNotificationService } from '../../core/notifications/delete-notif
@Component({
selector: 'app-note-editor',
templateUrl: './note-editor.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class NoteEditorComponent implements OnInit, OnDestroy, OnChanges {
noteForm: UntypedFormGroup;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,15 @@ <h6 class="card-subtitle mb-2 text-muted url-under-title">
>
<i class="far fa-copy"></i> Copy to mine
</button>
<button
*ngIf="bookmark.userId === (userData$ | async)?.userId"
type="button"
class="btn btn-light btn-sm"
(click)="cloneBookmark(bookmark)"
title="Clone bookmark"
>
<i class="far fa-clone"></i> Clone
</button>
<button
class="btn btn-light btn-sm float-right"
title="Share via email or on social media"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,11 @@ export class BookmarkListElementComponent
}
}

cloneBookmark(bookmark: Bookmark): void {
const link = [`./my-bookmarks/${bookmark._id}/clone`];
this.router.navigate(link, { state: { bookmark: bookmark } });
}

ngOnDestroy(): void {
if (this.navigationSubscription) {
this.navigationSubscription.unsubscribe();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Codever",
"version": "8.7.1",
"version": "8.8.0",
"description": "Codever - bookmarks, snippets and notes manager for developers & co",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
Expand Down

0 comments on commit 0ab002b

Please sign in to comment.