Skip to content

Commit

Permalink
Finish the requests management
Browse files Browse the repository at this point in the history
  • Loading branch information
sondreb committed Aug 30, 2024
1 parent e18f395 commit 77eccc2
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 28 deletions.
6 changes: 6 additions & 0 deletions app/src/app/connection.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ export class ConnectionService {
const { records } = await this.identity.web5.dwn.records.query({
message: {
filter: {
// recipient: inbound ? this.identity.did : undefined,
protocol: connectionDefinition.protocol,
protocolPath: 'request',
schema: connectionDefinition.types.request.schema,
Expand All @@ -172,6 +173,11 @@ export class ConnectionService {
for (let record of records!) {
const data = await record.data.json();
let notifiationEvent: ConnectionEntry = { record, data, id: record.id };

if (record.author == this.identity.did) {
notifiationEvent.direction = 'out';
}

list.push(notifiationEvent);
}

Expand Down
1 change: 1 addition & 0 deletions app/src/app/data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ export interface RecordEntry<T> {
id: string;
data: T;
loading?: boolean;
direction?: 'in' | 'out' | any;
}
35 changes: 20 additions & 15 deletions app/src/app/settings/connections/connections.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ <h1>Connections Management</h1>

<mat-card class="notifications-card">
<mat-card-header>
<mat-card-title>Inbound</mat-card-title>
<mat-card-title>Connections</mat-card-title>
</mat-card-header>
<mat-card-content>
@for(entry of service.connections(); track entry) {
Expand All @@ -20,35 +20,40 @@ <h1>Connections Management</h1>
<button mat-button (click)="deleteConnection(entry)" [disabled]="entry.loading">DELETE</button>
</mat-card-actions>
</mat-card>
} @empty { No inbound connections found. }
} @empty { No connections found. }
</mat-card-content>
</mat-card>

<br />

<mat-card class="notifications-card">
<mat-card-header>
<mat-card-title>Outbound</mat-card-title>
<mat-card-title>Requests</mat-card-title>
</mat-card-header>
<mat-card-content>
@for(entry of service.requests(); track entry) {
<mat-card class="card-notification" appearance="outlined">
<!-- <mat-card-header>
<mat-icon class="card-icon" inline="true" mat-card-avatar></mat-icon>
<mat-card-title>{{ entry.data }}</mat-card-title>
<mat-card-subtitle>{{ entry.record.dateCreated | ago }}</mat-card-subtitle>
</mat-card-header> -->
<mat-card-content>
<!-- {{ entry.data | json }}<br /><br />
{{ entry.record | json }} -->

{{ entry.record.recipient }}
@if (entry.direction == 'out') {
<app-profile-header [did]="entry.record.recipient"> </app-profile-header>
} @else {
<app-profile-header [did]="entry.record.author"> </app-profile-header>
}
</mat-card-content>
<mat-card-actions>
<button mat-flat-button [routerLink]="['/profile', entry.record.recipient]">VIEW PROFILE</button>
<button mat-button (click)="deleteRequest(entry)" [disabled]="entry.loading">DELETE</button>
@if (entry.direction == 'out') {
<button mat-flat-button [routerLink]="['/profile', entry.record.recipient]">VIEW PROFILE</button>&nbsp;
<button mat-flat-button [disabled]="true">PENDING</button>&nbsp;
<button mat-button (click)="reject(entry)" [disabled]="entry.loading">CANCEL</button>

} @else {
<button mat-flat-button [routerLink]="['/profile', entry.record.author]">VIEW PROFILE</button>&nbsp;
<button mat-flat-button (click)="accept(entry)" [disabled]="entry.loading">CONFIRM</button>&nbsp;
<button mat-button (click)="reject(entry)" [disabled]="entry.loading">DELETE</button>

}
</mat-card-actions>
</mat-card>
} @empty { No outbound connections found. }
} @empty { No requests found. }
</mat-card-content>
</mat-card>
19 changes: 6 additions & 13 deletions app/src/app/settings/connections/connections.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import { MatButtonModule } from '@angular/material/button';
import { MatIconModule } from '@angular/material/icon';
import { RouterModule } from '@angular/router';
import { AgoPipe } from '../../shared/pipes/ago.pipe';
import { ProfileHeaderComponent } from '../../shared/components/profile-header/profile-header.component';

@Component({
selector: 'app-connections',
standalone: true,
imports: [AgoPipe, CommonModule, MatCardModule, MatButtonModule, MatIconModule, RouterModule],
imports: [ProfileHeaderComponent, AgoPipe, CommonModule, MatCardModule, MatButtonModule, MatIconModule, RouterModule],
templateUrl: './connections.component.html',
styleUrl: './connections.component.scss',
})
Expand All @@ -20,25 +21,17 @@ export class ConnectionsComponent {

app = inject(AppService);

constructor() {
// effect(async () => {
// if (this.app.initialized()) {
// }
// });
}

// async load() {
// const blocks = await this.service.loadBlocks();
// this.blocks.set(blocks);
// }
constructor() {}

deleteConnection(entry: any) {
entry.loading = true;

this.service.deleteConnection(entry);
}

deleteRequest(entry: any) {
accept(entry: any) {}

reject(entry: any) {
entry.loading = true;

this.service.deleteRequest(entry);
Expand Down

0 comments on commit 77eccc2

Please sign in to comment.