Skip to content

Commit cb58ac8

Browse files
committed
Delete list and other small fixes
1 parent c09de93 commit cb58ac8

17 files changed

+193
-30
lines changed

projects/budgetkey/src/app/common-components/auth/auth.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</div>
1818
<div *ngIf="user && user.authenticated" class='menu'>
1919
<a class='menu-line' (activated)="profile()" *ngIf='hasProfile' clickOnReturn>התראות שמורות</a>
20-
<a class='menu-line' (activated)="myLists()" clickOnReturn *ngIf='lists.hasCuratedLists()'>הרשימות שלי</a>
20+
<a class='menu-line' (activated)="myLists()" clickOnReturn *ngIf='lists.curatedLists().length > 0'>הרשימות שלי</a>
2121
<!-- <a class='menu-line' (activated)="profile()" clickOnReturn>פרופיל אישי</a> -->
2222
<a class='menu-line' (activated)="logout()" clickOnReturn>התנתקות</a>
2323
</div>

projects/budgetkey/src/app/common-components/services/lists.service.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export class ListContents extends ListProperties {
3434
name: string;
3535
user_id: string;
3636
items?: Array<ListItem>;
37+
success?: boolean;
3738
}
3839

3940
export const CURATED_KIND = 'curated';
@@ -43,7 +44,7 @@ export const EMPTY_LIST: ListContents = {
4344
name: '',
4445
user_id: '',
4546
url: null,
46-
title: 'רשימה ללא שם',
47+
title: 'הרשימה שלי',
4748
properties: {description: 'תיאור הרשימה...'},
4849
kind: 'curated',
4950
items: [],
@@ -190,15 +191,15 @@ export class ListsService {
190191
);
191192
}
192193

193-
public getAnonymous(user_id: string, list: string): Observable<ListContents> {
194+
public getAnonymous(user_id: string, list: string): Observable<ListContents | null> {
194195
const params = {
195196
list, user_id, items: true
196197
};
197198
return (this.http.get<ListContents>('https://next.obudget.org/lists/', {params}))
198199
.pipe(
199200
tap((resp: ListContents) => {
200201
resp.items = resp.items?.sort((a: ListItem, b: ListItem) => (b.create_time || '').localeCompare(a.create_time || ''));
201-
})
202+
}),
202203
);
203204
}
204205

@@ -277,6 +278,7 @@ export class ListsService {
277278
}
278279
} else {
279280
curatedList.items = [];
281+
curatedLists.splice(listIndex, 1);
280282
}
281283
this.curatedLists.set([...curatedLists]);
282284
}

projects/budgetkey/src/app/list-components/add-to-list-dialog/add-to-list-dialog.component.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,28 @@ export class AddToListDialogComponent implements AfterViewInit, OnChanges {
4141
return;
4242
}
4343
const currentList = this.lists.currentList();
44-
if (currentList) {
45-
this.list = currentList;
44+
let list: ListContents | null = null;
45+
if (currentList && currentList.success !== false) {
46+
list = currentList;
4647
} else {
4748
const lists = (this.lists.curatedLists() || []).sort((a, b) => (b.update_time || '').localeCompare(a.update_time || ''));
4849
if (lists.length > 0) {
49-
this.list = lists[0];
50+
list = lists[0];
5051
}
5152
}
52-
this.lists.curatedLists()?.forEach((list) => {
53-
this.originalSubscriptionState[list.name] = this.checkSubscribed(list);
54-
this.subscriptionState[list.name] = this.originalSubscriptionState[list.name];
53+
this.lists.curatedLists()?.forEach((list_) => {
54+
this.originalSubscriptionState[list_.name] = this.checkSubscribed(list_);
55+
this.subscriptionState[list_.name] = this.originalSubscriptionState[list_.name];
5556
});
56-
if (this.list && !this.listSelection) {
57-
this.originalSubscriptionState[this.list.name] = false;
58-
this.subscriptionState[this.list.name] = true;
57+
if (list && !this.listSelection) {
58+
this.originalSubscriptionState[list.name] = false;
59+
this.subscriptionState[list.name] = true;
60+
}
61+
if (!list) {
62+
this.list = this.lists.emptyList;
63+
this.newList = this.list.title;
64+
} else {
65+
this.list = list;
5966
}
6067
});
6168
}

projects/budgetkey/src/app/list-components/app-container/app-container.component.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
<ng-content></ng-content>
1010
</div>
1111
<div class='list' *ngIf='showListView()'>
12-
<app-list-view [list]="lists.currentList() || lists.emptyList" [headerControls]='true'></app-list-view>
12+
<app-list-view [list]="lists.currentList() || lists.emptyList" [headerControls]='true'
13+
(deleted)='onDeleted()'
14+
></app-list-view>
1315
</div>
1416
</div>
1517
<app-bk-footer *ngIf="showFooter" [helpWidget]='helpWidget'></app-bk-footer>

projects/budgetkey/src/app/list-components/app-container/app-container.component.less

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
max-width: 100%;
2626
display: flex;
2727
flex-flow: row;
28-
align-items: flex-start;
28+
align-items: stretch;
2929

3030
.list {
3131
flex: 0 0 auto;
@@ -43,6 +43,7 @@
4343
.main {
4444
flex: 0 1 auto;
4545
width: 100%;
46+
min-height: 100%;
4647
display: flex;
4748
flex-flow: column;
4849
align-items: center;

projects/budgetkey/src/app/list-components/app-container/app-container.component.ts

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { HttpClient } from '@angular/common/http';
22
import {Component, ViewEncapsulation, Input, signal, AfterViewInit, effect, computed} from '@angular/core';
3-
import { ActivatedRoute } from '@angular/router';
3+
import { ActivatedRoute, Router } from '@angular/router';
44
import { GlobalSettingsService } from '../../common-components/global-settings.service';
55
import { distinct, distinctUntilChanged, filter, map, switchMap, tap } from 'rxjs';
66
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
@@ -25,9 +25,26 @@ export class AppContainerComponent {
2525
configured = false;
2626

2727
maxWidth = signal<number>(0);
28-
showListView = computed(() => !!this.lists.currentList() && this.listSideView && this.layout.desktop);
28+
hasListView = computed(() => {
29+
console.log('SHOW LIST VIEW', this.layout.desktop, this.listSideView, this.lists.currentList(), this.listKey());
30+
const list = this.lists.currentList();
31+
if (!list) {
32+
return false;
33+
}
34+
if (list.success === false) {
35+
return false;
36+
}
37+
if (!this.listKey()) {
38+
return false;
39+
}
40+
if (this.listKey() !== `${list?.user_id}:${list?.name}`) {
41+
return false;
42+
}
43+
return true;
44+
});
45+
listKey = signal<string | null>(null);
2946

30-
constructor(private route: ActivatedRoute, private globalSettings: GlobalSettingsService, public lists: ListsService, public layout: LayoutService) {
47+
constructor(private route: ActivatedRoute, private globalSettings: GlobalSettingsService, public lists: ListsService, public layout: LayoutService, private router: Router) {
3148
this.globalSettings.ready.subscribe(() => {
3249
this.configured = true;
3350
});
@@ -39,7 +56,8 @@ export class AppContainerComponent {
3956
distinctUntilChanged(),
4057
).subscribe((list) => {
4158
console.log('SET LIST', list);
42-
this.lists.currentListId.set(list);
59+
this.listKey.set(list);
60+
this.lists.currentListId.set(this.listKey());
4361
});
4462
effect(() => {
4563
let maxWidth = this.layout.width();
@@ -52,4 +70,12 @@ export class AppContainerComponent {
5270
this.maxWidth.set(maxWidth);
5371
}, { allowSignalWrites: true});
5472
}
73+
74+
showListView() {
75+
return this.layout.desktop && this.listSideView && this.hasListView();
76+
}
77+
78+
onDeleted() {
79+
this.router.navigate(['.'], { relativeTo: this.route, queryParams: { list: null }, queryParamsHandling: 'merge', replaceUrl: true});
80+
}
5581
}

projects/budgetkey/src/app/list-components/list-view/list-view.component.html

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ <h1 [editedContent]='editable()' (updated)='title = $event' #titleEl>{{title}}</
2525
<a class='close-button' [routerLink]='"."' [queryParams]='{list: null}' queryParamsHandling='merge' clickOnReturn></a>
2626
</div>
2727
<div class='edit-controls' *ngIf='editable()'>
28-
<a class='delete-button' (activated)='deleteDialog.set(true)' clickOnReturn>מחיקת רשימה</a>
28+
<a class='delete-button' (activated)='deleteDialog.set(true)' clickOnReturn>
29+
<span class='icon'></span>
30+
מחיקת רשימה
31+
</a>
2932
</div>
3033
</div>
3134
<div class='list-contents'>
@@ -62,3 +65,22 @@ <h1 [editedContent]='editable()' (updated)='title = $event' #titleEl>{{title}}</
6265
<button class='done-button' clickOnReturn (activated)='shareDialog.set(false)'>אישור</button>
6366
</div>
6467
</app-modal>
68+
69+
<app-modal [standardLayout]='false'
70+
*ngIf='deleteDialog()'
71+
(close)='deleteDialog.set(false)'
72+
>
73+
<div class='dialog-header'>
74+
<span>מחיקת הרשימה:</span>
75+
<div class='title'>{{list.title}}</div>
76+
</div>
77+
<div class='dialog-explanation'>
78+
<span>לא ניתן לבטל פעולה זו.</span><br/>
79+
</div>
80+
<div class='dialog-done'>
81+
<button class='cancel-button' clickOnReturn (activated)='deleteDialog.set(false)'>
82+
ביטול
83+
</button>
84+
<button class='done-button' clickOnReturn (activated)='deleteSelf()'>מחיקה</button>
85+
</div>
86+
</app-modal>

projects/budgetkey/src/app/list-components/list-view/list-view.component.less

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,52 @@
149149
background-image: url(../../../assets/lists/icon-fullscreen-gray-500.svg);
150150
}
151151
}
152+
152153
.edit-controls {
153154
display: flex;
154155
flex-flow: row;
155156
position: absolute;
156157
top: 8px;
157158
right: 8px;
159+
160+
.delete-button {
161+
appearance: none;
162+
border: none;
163+
display: flex;
164+
flex-flow: row;
165+
align-items: center;
166+
justify-content: center;
167+
gap: 2px;
168+
padding: 2px 4px 2px 12px;
169+
border-radius: 4px;
170+
border: 1px solid @color-lists-light-blue;
171+
background: @color-white;
172+
173+
color: @color-lists-grayish-blue;
174+
.font-abraham;
175+
font-size: 16px;
176+
font-weight: 400;
177+
line-height: 28px;
178+
text-decoration: none;
179+
180+
.icon {
181+
.background-image;
182+
background-image: url(../../../assets/lists/icon-lists-trash-grayish-blue.svg);
183+
display: inline-block;
184+
width: 24px;
185+
height: 24px;
186+
}
187+
188+
&:hover {
189+
border: 1px solid @color-fill-lead;
190+
background: @color-fill-lead-lighter;
191+
color: @color-fill-lead;
192+
193+
.icon {
194+
background-image: url(../../../assets/lists/icon-lists-trash-red.svg);
195+
}
196+
}
197+
}
158198
}
159199
}
160200

@@ -229,7 +269,7 @@
229269

230270
.dialog-explanation {
231271
width: 100%;
232-
padding: 16px 24px;
272+
padding: 16px 32px;
233273
color: @color-gray-800;
234274
text-align: right;
235275
.font-abraham;
@@ -277,6 +317,22 @@
277317
}
278318
}
279319

320+
.cancel-button {
321+
appearance: none;
322+
border: none;
323+
display: flex;
324+
flex-flow: row;
325+
align-items: center;
326+
justify-content: center;
327+
color: @color-gray-500;
328+
background-color: white;
329+
padding: 0 24px;
330+
331+
&:hover {
332+
color: @color-gray-800;
333+
}
334+
}
335+
280336
.done-button {
281337
margin-right: auto;
282338
.list-button;

projects/budgetkey/src/app/list-components/list-view/list-view.component.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, ElementRef, Input, OnChanges, OnInit, SimpleChanges, ViewChild, computed, signal } from '@angular/core';
1+
import { Component, ElementRef, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges, ViewChild, computed, signal } from '@angular/core';
22
import { ListContents, ListsService } from '../../common-components/services/lists.service';
33
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
44
import { Format } from '../../format';
@@ -17,6 +17,8 @@ export class ListViewComponent implements OnChanges {
1717
@Input() list: ListContents;
1818
@Input() headerControls = false;
1919

20+
@Output() deleted = new EventEmitter<void>();
21+
2022
@ViewChild('titleEl') titleEl: ElementRef;
2123
@ViewChild('descriptionEl') descriptionEl: ElementRef;
2224

@@ -106,4 +108,12 @@ export class ListViewComponent implements OnChanges {
106108
document.body.removeChild(el);
107109
this.copied = true;
108110
}
111+
112+
deleteSelf() {
113+
this.lists.delete(this.list.name, null).subscribe((success) => {
114+
console.log('DELETED LIST', success);
115+
this.deleted.emit();
116+
this.deleteDialog.set(false);
117+
});
118+
}
109119
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
<app-container>
1+
<app-container [showHeader]="true" [showSearchBar]="true" [listSideView]='false'>
22
<div *ngIf='init && list'>
3-
<app-list-view [list]='list'></app-list-view>
3+
<app-list-view [list]='list' (deleted)='onDeleted()'></app-list-view>
44
</div>
55
</app-container>
66

0 commit comments

Comments
 (0)