add new route "/vault-import" in the popup

This commit is contained in:
DEV Sam Hayes
2025-02-07 17:14:29 +01:00
parent 7f0829af09
commit 27e8d52d23
16 changed files with 230 additions and 60 deletions

View File

@@ -6,7 +6,7 @@
<div class="sam-flex-column center">
<div class="sam-flex-column gap" style="align-items: center">
<div class="logo-frame">
<img src="gooti.svg" height="120" width="120" alt=""/>
<img src="gooti.svg" height="120" width="120" alt="" />
</div>
<button
@@ -25,18 +25,10 @@
<button
type="button"
class="btn btn-secondary"
(click)="fileInput.click()"
(click)="router.navigateByUrl('/vault-import')"
>
<span>Import a vault</span>
</button>
</div>
</div>
</div>
<input
#fileInput
class="file-input"
type="file"
(change)="onImportFileChange($event)"
accept=".json"
/>

View File

@@ -1,7 +1,6 @@
import { Component, inject } from '@angular/core';
import { Router } from '@angular/router';
import { BrowserSyncData, StartupService, StorageService } from '@common';
import { getNewStorageServiceConfig } from '../../../common/data/get-new-storage-service-config';
import { NavComponent } from '@common';
@Component({
selector: 'app-home',
@@ -9,28 +8,6 @@ import { getNewStorageServiceConfig } from '../../../common/data/get-new-storage
templateUrl: './home.component.html',
styleUrl: './home.component.scss',
})
export class HomeComponent {
export class HomeComponent extends NavComponent {
readonly router = inject(Router);
readonly #storage = inject(StorageService);
readonly #startup = inject(StartupService);
async onImportFileChange(event: Event) {
try {
const element = event.currentTarget as HTMLInputElement;
const file = element.files !== null ? element.files[0] : undefined;
if (!file) {
return;
}
const text = await file.text();
const vault = JSON.parse(text) as BrowserSyncData;
console.log(vault);
await this.#storage.importVault(vault);
this.#startup.startOver(getNewStorageServiceConfig());
} catch (error) {
console.log(error);
// TODO
}
}
}