fix removing items
This commit is contained in:
@@ -24,6 +24,7 @@ export default class StorageModel {
|
||||
remove = (pathComponents: string[]): void => {
|
||||
const key: string = StorageModel.pathComponentsToKey(...pathComponents);
|
||||
localStorage.removeItem(key);
|
||||
this.initializeTree();
|
||||
};
|
||||
|
||||
list = (pathComponents: string[]): string[] => {
|
||||
@@ -52,14 +53,19 @@ export default class StorageModel {
|
||||
|
||||
// init
|
||||
constructor() {
|
||||
this.initializeTree();
|
||||
}
|
||||
|
||||
// utility
|
||||
initializeTree = (): void => {
|
||||
this.storageEntryTree = {};
|
||||
for (const key of Object.keys(localStorage)) {
|
||||
const components: string[] = StorageModel.keyToPathComponents(key);
|
||||
this.updateTree(...components);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// utility
|
||||
updateTree = (...pathComponents: string[]) => {
|
||||
updateTree = (...pathComponents: string[]): void => {
|
||||
let currentParent: StorageEntry = this.storageEntryTree;
|
||||
for (const pathPart of pathComponents) {
|
||||
if (!currentParent[pathPart]) {
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import * as React from "bloatless-react";
|
||||
|
||||
import { translations } from "../translations";
|
||||
|
||||
export function DeletableListItem(text: string, ondelete: () => void) {
|
||||
return (
|
||||
<div class="tile flex-row justify-apart align-center padding-0">
|
||||
<span class="padding-h">{text}</span>
|
||||
|
||||
<button
|
||||
class="danger"
|
||||
aria-label={translations.general.deleteItemButtonAudioLabel}
|
||||
on:click={ondelete}
|
||||
>
|
||||
<span class="icon">delete</span>
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,9 +1,18 @@
|
||||
import * as React from "bloatless-react";
|
||||
|
||||
import ConnectionViewModel from "../../ViewModel/connectionViewModel";
|
||||
import { DeletableListItem } from "../Components/deletableListItem";
|
||||
import { translations } from "../translations";
|
||||
|
||||
export function ConnectionModal(connectionViewModel: ConnectionViewModel) {
|
||||
const previousAddressConverter: React.StateItemConverter<string> = (
|
||||
address: string
|
||||
) => {
|
||||
return DeletableListItem(address, () => {
|
||||
connectionViewModel.removePreviousAddress(address);
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
class="modal"
|
||||
@@ -13,10 +22,16 @@ export function ConnectionModal(connectionViewModel: ConnectionViewModel) {
|
||||
<main>
|
||||
<h2>{translations.connectionModal.connectionModalHeadline}</h2>
|
||||
|
||||
|
||||
<div
|
||||
class="flex-column gap"
|
||||
children:append={[
|
||||
connectionViewModel.previousAddresses,
|
||||
previousAddressConverter,
|
||||
]}
|
||||
></div>
|
||||
</main>
|
||||
<button on:click={connectionViewModel.hideConnectionModal}>
|
||||
{translations.general.closeButton}
|
||||
{translations.general.closeButtonAudioLabel}
|
||||
<span class="icon">close</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@@ -52,7 +52,7 @@ export function HomePage(
|
||||
aria-label={translations.homePage.manageConnectionsAudioLabel}
|
||||
on:click={connectionViewModel.showConnectionModal}
|
||||
>
|
||||
<span class="icon">build</span>
|
||||
<span class="icon">edit</span>
|
||||
</button>
|
||||
<button
|
||||
class="primary flex justify-center"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
const englishTranslations = {
|
||||
general: {
|
||||
closeButton: "close",
|
||||
closeButtonAudioLabel: "close",
|
||||
deleteItemButtonAudioLabel: "delete item",
|
||||
},
|
||||
|
||||
regional: {
|
||||
|
||||
@@ -50,6 +50,11 @@ export default class ConnectionViewModel {
|
||||
this.connectionModel.disconnect();
|
||||
};
|
||||
|
||||
removePreviousAddress = (address: string): void => {
|
||||
this.connectionModel.removeAddress(address);
|
||||
this.updatePreviousAddresses();
|
||||
}
|
||||
|
||||
// view methods
|
||||
showConnectionModal = (): void => {
|
||||
this.isShowingConnectionModal.value = true;
|
||||
|
||||
Reference in New Issue
Block a user