Skip to content

Commit

Permalink
refractor: use vote endpoints intead of favorites
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex P. Scigalszky authored and Alex P. Scigalszky committed Mar 8, 2023
1 parent fd18866 commit 49b27c7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"budgets": [
{
"type": "initial",
"maximumWarning": "500kb",
"maximumWarning": "1mb",
"maximumError": "1mb"
},
{
Expand Down
25 changes: 21 additions & 4 deletions src/app/components/item-actions/item-actions.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,33 @@ import { Item } from 'src/app/models/item';
template: `
<div>
<button
[class.disabled]="!(item.dones[order] === false || item.dones[order] === null)"
[class.disabled]="done"
(click)="markAsDone()"
type="button"
class="btn btn-sm btn-outline-success mr-2"
class="btn btn-sm mr-2"
[class.btn-success]="done"
[class.btn-outline-success]="!done"
>
Done
</button>
<button
[class.disabled]="!(item.dones[order] === true || item.dones[order] === null)"
[class.disabled]="todo"
(click)="markAsTodo()"
type="button"
class="btn btn-sm btn-outline-secondary mr-2"
[class.btn-success]="todo"
[class.btn-outline-secondary]="!todo"
>
To do
</button>
<button
[class.disabled]="!(item.dones[order] !== null)"
[class.disabled]="reset"
(click)="clear()"
type="button"
class="btn btn-sm btn-link-danger"
[class.btn-success]="reset"
[class.btn-outline-secondary]="!reset"
>
Reset
</button>
Expand All @@ -43,6 +49,17 @@ export class ItemActionsComponent {
@Output() onTodo = new EventEmitter<boolean>();
@Output() onClear = new EventEmitter<boolean>();

get done() {
return !(this.item.dones[this.order] === false || this.item.dones[this.order] === null);
}

get todo() {
return !(this.item.dones[this.order] === true || this.item.dones[this.order] === null);
}

get reset() {
return !(this.item.dones[this.order] !== null)
}
markAsDone(): void {
this.onDone.emit(true);
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/services/items.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class ItemsService {

vote(identifier: string, userIdentifier: string): Observable<void> {
return this.http.post<void>(
'https://threethingstodoinlife-functions.netlify.app/.netlify/functions/favorites-add',
'https://threethingstodoinlife-functions.netlify.app/.netlify/functions/vote-up',
{ identifier, userIdentifier },
{
headers: this.headers,
Expand All @@ -39,7 +39,7 @@ export class ItemsService {

unvote(identifier: string, userIdentifier: string): Observable<void> {
return this.http.post<void>(
'https://threethingstodoinlife-functions.netlify.app/.netlify/functions/favorites-remove',
'https://threethingstodoinlife-functions.netlify.app/.netlify/functions/vote-down',
{ identifier, userIdentifier },
{
headers: this.headers,
Expand Down

0 comments on commit 49b27c7

Please sign in to comment.