-
Notifications
You must be signed in to change notification settings - Fork 7
Rebuild Capture - Step D1 (Stateful Capture Items) #452
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a7530d5
Add mutex lock when updating table.
seanwu1105 b1767bb
Navigate up after deleting capture item.
seanwu1105 0aa6241
Remove notification when collecting and uploading proof.
seanwu1105 ba9547e
Implement stateful CaptureItem.
seanwu1105 2f6b975
Display an empty small image to avoid border of img without src.
seanwu1105 a96a353
Remove spinner in inbox and transactions page.
seanwu1105 069c344
Remove willCollectTruth as a key of trackCaptureItem.
seanwu1105 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.