mirror of
https://github.com/block-core/blockcore-notes.git
synced 2024-09-29 22:40:44 +00:00
WIP: New state management for abstracting services and UI
This commit is contained in:
parent
b3a118149a
commit
2d964e9786
@ -107,10 +107,10 @@
|
||||
<mat-icon>bookmarks</mat-icon>
|
||||
<span *ngIf="displayLabels">{{ 'App.Bookmarks' | translate }}</span>
|
||||
</a>
|
||||
<!-- <a [routerLink]="['/development']" mat-menu-item (click)="toggleMenu()" [routerLinkActiveOptions]="{ exact: true }" routerLinkActive="active">
|
||||
<a [routerLink]="['/development']" mat-menu-item (click)="toggleMenu()" [routerLinkActiveOptions]="{ exact: true }" routerLinkActive="active">
|
||||
<mat-icon>construction</mat-icon>
|
||||
<span *ngIf="displayLabels">Development</span>
|
||||
</a> -->
|
||||
</a>
|
||||
<a [routerLink]="['/relays']" mat-menu-item (click)="toggleMenu()" [routerLinkActiveOptions]="{ exact: true }" routerLinkActive="active">
|
||||
<mat-icon>dns</mat-icon>
|
||||
<span *ngIf="displayLabels">{{ 'App.Relays' | translate }}</span>
|
||||
|
@ -1,4 +1,21 @@
|
||||
<div class="page">
|
||||
<h1>State Service Management</h1>
|
||||
|
||||
<mat-list >
|
||||
<div mat-subheader>Metadata</div>
|
||||
<mat-list-item *ngFor="let state of state.events.metadata | keyvalue">
|
||||
<mat-icon matListItemIcon>folder</mat-icon>
|
||||
<div matListItemTitle>{{state.key}}</div>
|
||||
<div matListItemLine>{{state.value.content}}</div>
|
||||
</mat-list-item>
|
||||
<mat-divider></mat-divider>
|
||||
</mat-list>
|
||||
|
||||
State as JSON:<br>
|
||||
{{ state | json }}
|
||||
|
||||
<br /><br />
|
||||
|
||||
<p>This page act as examples for more specialized implementation details of the app.</p>
|
||||
|
||||
<button mat-stroked-button (click)="downloadProfile()">Enque Profile Download</button>
|
||||
@ -21,4 +38,4 @@
|
||||
<app-relays [relays]="relayService.items"></app-relays>
|
||||
|
||||
<!-- <mat-spinner></mat-spinner> -->
|
||||
</div>
|
||||
</div>
|
||||
|
@ -5,6 +5,7 @@ import { NostrService } from '../services/nostr';
|
||||
import { RelayService } from '../services/relay';
|
||||
import { RelayType } from '../types/relay';
|
||||
import { Storage } from '../types/storage';
|
||||
import { State, StateService } from '../services/state';
|
||||
|
||||
@Component({
|
||||
selector: 'app-development',
|
||||
@ -15,10 +16,13 @@ export class DevelopmentComponent {
|
||||
worker?: Worker;
|
||||
storage?: Storage;
|
||||
|
||||
constructor(private nostr: NostrService, private dataService: DataService, private appState: ApplicationState, public relayService: RelayService) {}
|
||||
constructor(
|
||||
public state: State,
|
||||
private nostr: NostrService, private dataService: DataService, private appState: ApplicationState, public relayService: RelayService) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.appState.updateTitle('Development & Debug');
|
||||
|
||||
}
|
||||
|
||||
async database() {
|
||||
|
@ -10,14 +10,14 @@ export class StateService {
|
||||
|
||||
addEvent(event: NostrEvent) {
|
||||
// TODO: Temporarily removed to avoid building massive in-memory state.
|
||||
// switch (event.kind) {
|
||||
// case Kind.Metadata:
|
||||
// this.addIfNewer(event, this.state.events.shortTextNote);
|
||||
// break;
|
||||
// case Kind.Text:
|
||||
// this.addIfMissing(event, this.state.events.shortTextNote);
|
||||
// break;
|
||||
// }
|
||||
switch (event.kind) {
|
||||
case Kind.Metadata:
|
||||
this.addIfNewer(event, event.pubkey, this.state.events.metadata);
|
||||
break;
|
||||
case Kind.Text:
|
||||
this.addIfMissing(event, this.state.events.shortTextNote);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
addIfMissing(event: NostrEvent, map: Map<string, NostrEvent>) {
|
||||
@ -28,17 +28,17 @@ export class StateService {
|
||||
map.set(event.id, event);
|
||||
}
|
||||
|
||||
addIfNewer(event: NostrEvent, map: Map<string, NostrEvent>) {
|
||||
if (!map.has(event.id)) {
|
||||
map.set(event.id, event);
|
||||
addIfNewer(event: NostrEvent, identifier: string, map: Map<string, NostrEvent>) {
|
||||
if (!map.has(identifier)) {
|
||||
map.set(identifier, event);
|
||||
} else {
|
||||
const existing = map.get(event.id);
|
||||
const existing = map.get(identifier);
|
||||
|
||||
if (existing!.created_at > event.created_at) {
|
||||
if (existing!.created_at >= event.created_at) {
|
||||
return;
|
||||
}
|
||||
|
||||
map.set(event.id, event);
|
||||
map.set(identifier, event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user