Many new functionalities
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { Component, effect, inject } from '@angular/core';
|
||||
import { Component, effect, inject, signal } from '@angular/core';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { Router, RouterLink } from '@angular/router';
|
||||
|
||||
import { ChatSessionService } from './chat-session.service';
|
||||
import type { AdminUserSummary } from './models';
|
||||
import { ThemeService } from './theme.service';
|
||||
|
||||
@Component({
|
||||
@@ -23,6 +24,10 @@ export class HomePageComponent {
|
||||
username = '';
|
||||
password = '';
|
||||
accessKeyLabel = '';
|
||||
readonly adminUsers = signal<AdminUserSummary[]>([]);
|
||||
readonly loadingAdminUsers = signal(false);
|
||||
readonly deletingUserId = signal<string | null>(null);
|
||||
readonly adminUsersError = signal<string | null>(null);
|
||||
|
||||
constructor(readonly session: ChatSessionService) {
|
||||
this.serverUrl = session.serverUrl();
|
||||
@@ -39,6 +44,19 @@ export class HomePageComponent {
|
||||
void this.router.navigate(['/chat', activePeerId], { replaceUrl: true });
|
||||
});
|
||||
}
|
||||
|
||||
effect(() => {
|
||||
const currentUser = this.session.currentUser();
|
||||
|
||||
if (!currentUser || !this.session.isApprovalAdmin()) {
|
||||
this.adminUsers.set([]);
|
||||
this.adminUsersError.set(null);
|
||||
this.loadingAdminUsers.set(false);
|
||||
return;
|
||||
}
|
||||
|
||||
void this.reloadAdminUsers();
|
||||
});
|
||||
}
|
||||
|
||||
async submitAuth(): Promise<void> {
|
||||
@@ -80,6 +98,44 @@ export class HomePageComponent {
|
||||
this.accessKeyLabel = '';
|
||||
}
|
||||
|
||||
async reloadAdminUsers(): Promise<void> {
|
||||
this.loadingAdminUsers.set(true);
|
||||
this.adminUsersError.set(null);
|
||||
|
||||
try {
|
||||
this.adminUsers.set(await this.session.loadAdminUsers());
|
||||
} catch (error) {
|
||||
this.adminUsersError.set(
|
||||
error instanceof Error ? error.message : 'Could not load users.',
|
||||
);
|
||||
} finally {
|
||||
this.loadingAdminUsers.set(false);
|
||||
}
|
||||
}
|
||||
|
||||
async deleteUser(user: AdminUserSummary): Promise<void> {
|
||||
if (
|
||||
typeof window !== 'undefined' &&
|
||||
!window.confirm(`Delete user ${user.username}? This removes the account from SQLite.`)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.deletingUserId.set(user.id);
|
||||
this.adminUsersError.set(null);
|
||||
|
||||
try {
|
||||
await this.session.deleteUserAccount(user.id);
|
||||
this.adminUsers.update((users) => users.filter((candidate) => candidate.id !== user.id));
|
||||
} catch (error) {
|
||||
this.adminUsersError.set(
|
||||
error instanceof Error ? error.message : 'Could not delete that user.',
|
||||
);
|
||||
} finally {
|
||||
this.deletingUserId.set(null);
|
||||
}
|
||||
}
|
||||
|
||||
async openChatUi(): Promise<void> {
|
||||
const peerId = this.session.activePeerId() ?? this.session.peers()[0]?.id;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user