-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rebuild Capture - Step D1 (Stateful Capture Items) #452
* Add mutex lock when updating table. * Navigate up after deleting capture item. * Remove notification when collecting and uploading proof. * Implement stateful CaptureItem. * Display an empty small image to avoid border of img without src. * Remove spinner in inbox and transactions page.
- Loading branch information
1 parent
fe67d6e
commit abfeb60
Showing
20 changed files
with
194 additions
and
268 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/app/features/home/capture-tab/capture-item/capture-item.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<div *ngIf="willCollectTruth$ | async" class="spinner-container"> | ||
<ion-spinner></ion-spinner> | ||
</div> | ||
<ion-icon *ngIf="willCollectTruth$ | async" name="hourglass-outline"></ion-icon> | ||
<!-- Display an empty small image to avoid border of img without src. --> | ||
<img | ||
[src]=" | ||
(thumbnailUrl$ | async) || | ||
'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==' | ||
" | ||
/> |
46 changes: 46 additions & 0 deletions
46
src/app/features/home/capture-tab/capture-item/capture-item.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
:host { | ||
display: block; | ||
position: relative; | ||
width: 100%; | ||
height: 100%; | ||
overflow: hidden; | ||
border-radius: 4px; | ||
background-color: whitesmoke; | ||
} | ||
|
||
ion-icon { | ||
position: absolute; | ||
top: 50%; | ||
left: 50%; | ||
margin-right: -50%; | ||
transform: translate(-50%, -50%); | ||
z-index: 10; | ||
opacity: 50%; | ||
font-size: 24px; | ||
color: white; | ||
} | ||
|
||
.spinner-container { | ||
position: absolute; | ||
top: 50%; | ||
left: 50%; | ||
margin-right: -50%; | ||
transform: translate(-50%, -50%); | ||
z-index: 9; | ||
|
||
ion-spinner { | ||
width: 48px; | ||
height: 48px; | ||
opacity: 50%; | ||
|
||
--color: white; | ||
} | ||
} | ||
|
||
img { | ||
width: 100%; | ||
height: 100%; | ||
object-fit: cover; | ||
object-position: center; | ||
background-color: whitesmoke; | ||
} |
23 changes: 23 additions & 0 deletions
23
src/app/features/home/capture-tab/capture-item/capture-item.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { SharedTestingModule } from '../../../../shared/shared-testing.module'; | ||
import { CaptureItemComponent } from './capture-item.component'; | ||
|
||
describe('CaptureItemComponent', () => { | ||
let component: CaptureItemComponent; | ||
let fixture: ComponentFixture<CaptureItemComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [CaptureItemComponent], | ||
imports: [SharedTestingModule], | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(CaptureItemComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
})); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
63 changes: 63 additions & 0 deletions
63
src/app/features/home/capture-tab/capture-item/capture-item.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { Component, Input } from '@angular/core'; | ||
import { UntilDestroy } from '@ngneat/until-destroy'; | ||
import { BehaviorSubject } from 'rxjs'; | ||
import { map, switchMap } from 'rxjs/operators'; | ||
import { getOldProof } from '../../../../shared/services/repositories/proof/old-proof-adapter'; | ||
import { Proof } from '../../../../shared/services/repositories/proof/proof'; | ||
import { isNonNullable } from '../../../../utils/rx-operators/rx-operators'; | ||
|
||
@UntilDestroy({ checkProperties: true }) | ||
@Component({ | ||
selector: 'app-capture-item', | ||
templateUrl: './capture-item.component.html', | ||
styleUrls: ['./capture-item.component.scss'], | ||
}) | ||
export class CaptureItemComponent { | ||
// Use setter to make sure the item is updated even if the component is | ||
// recycled and redrawed (e.g. virtual scroll). | ||
@Input() | ||
set item(value: CaptureItem) { | ||
this._item$.next(value); | ||
} | ||
|
||
// tslint:disable-next-line: rxjs-no-explicit-generics | ||
private readonly _item$ = new BehaviorSubject<CaptureItem | undefined>( | ||
undefined | ||
); | ||
readonly item$ = this._item$.asObservable().pipe(isNonNullable()); | ||
readonly thumbnailUrl$ = this.item$.pipe( | ||
switchMap(item => item.getThumbnailUrl()) | ||
); | ||
readonly willCollectTruth$ = this.item$.pipe( | ||
map(item => item.proof?.willCollectTruth === true) | ||
); | ||
} | ||
|
||
export class CaptureItem { | ||
proof?: Proof; | ||
private readonly createdTimestamp: number; | ||
|
||
get oldProofHash() { | ||
if (this.proof) { | ||
return getOldProof(this.proof).hash; | ||
} | ||
} | ||
|
||
get timestamp() { | ||
if (this.proof) { | ||
return this.proof.timestamp; | ||
} | ||
return this.createdTimestamp; | ||
} | ||
|
||
constructor({ proof }: { proof?: Proof }) { | ||
this.proof = proof; | ||
this.createdTimestamp = Date.now(); | ||
} | ||
|
||
async getThumbnailUrl() { | ||
if (this.proof) { | ||
return this.proof.getThumbnailUrl(); | ||
} | ||
} | ||
} |
21 changes: 8 additions & 13 deletions
21
src/app/features/home/capture-tab/capture-tab.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,20 @@ | ||
<ng-container | ||
*ngFor="let group of capturesByDate$ | async | keyvalue: keyDescendingOrder" | ||
*ngFor=" | ||
let group of capturesByDate$ | async | keyvalue: keyDescendingOrder; | ||
trackBy: trackCaptureGroupByDate | ||
" | ||
> | ||
<div class="mat-title">{{ group.key }}</div> | ||
<mat-grid-list cols="3" gutterSize="8px"> | ||
<mat-grid-tile | ||
*ngFor="let capture of group.value" | ||
*ngFor="let captureItem of group.value; trackBy: trackCaptureItem" | ||
[routerLink]=" | ||
capture.proof.willCollectTruth | ||
captureItem.proof.willCollectTruth | ||
? undefined | ||
: ['capture-details', { oldProofHash: capture.oldProofHash }] | ||
: ['capture-details', { oldProofHash: captureItem.oldProofHash }] | ||
" | ||
class="capture-item" | ||
> | ||
<div *ngIf="capture.proof.willCollectTruth" class="spinner-container"> | ||
<ion-spinner></ion-spinner> | ||
</div> | ||
<ion-icon | ||
*ngIf="capture.proof.willCollectTruth" | ||
name="hourglass-outline" | ||
></ion-icon> | ||
<img [src]="capture.thumbnailUrl" /> | ||
<app-capture-item [item]="captureItem"></app-capture-item> | ||
</mat-grid-tile> | ||
</mat-grid-list> | ||
</ng-container> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { PostCaptureCardModule } from '../../shared/core/post-capture-card/post-capture-card.module'; | ||
import { SharedModule } from '../../shared/shared.module'; | ||
import { CaptureItemComponent } from './capture-tab/capture-item/capture-item.component'; | ||
import { CaptureTabComponent } from './capture-tab/capture-tab.component'; | ||
import { HomePageRoutingModule } from './home-routing.module'; | ||
import { HomePage } from './home.page'; | ||
|
||
@NgModule({ | ||
imports: [SharedModule, HomePageRoutingModule, PostCaptureCardModule], | ||
declarations: [HomePage, CaptureTabComponent], | ||
declarations: [HomePage, CaptureTabComponent, CaptureItemComponent], | ||
}) | ||
export class HomePageModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.