import * as React from "bloatless-react"; import FileTransferModel, { TransferData, } from "../../Model/Global/fileTransferModel"; import StorageModel, { StorageModelSubPath, } from "../../Model/Global/storageModel"; import ChatListModel from "../../Model/Chat/chatListModel"; import ChatModel from "../../Model/Chat/chatModel"; import { translations } from "../../View/translations"; export default class FileTransferViewModel { fileTransferModel: FileTransferModel; chatListModel: ChatListModel; // state presentedModal: React.State = new React.State(undefined); generalFileOptions: React.ListState = new React.ListState(); chatFileOptions: React.ListState = new React.ListState(); selectedPaths: React.ListState = new React.ListState(); transferChannel: React.State = new React.State(""); transferKey: React.State = new React.State(""); // guards hasNoPathsSelected: React.State = React.createProxyState( [this.selectedPaths], () => this.selectedPaths.value.size == 0 ); // methods getOptions = (): void => { this.generalFileOptions.clear(); this.chatFileOptions.clear(); this.generalFileOptions.add( { label: translations.dataTransferModal.connectionData, path: StorageModel.getPath(StorageModelSubPath.ConnectionModel, []), }, { label: translations.dataTransferModal.settingsData, path: StorageModel.getPath(StorageModelSubPath.SettingsModel, []), } ); const chatModels: Set = this.chatListModel.chatModels; for (const chatModel of chatModels) { this.chatFileOptions.add({ label: chatModel.info.primaryChannel, path: chatModel.getBasePath(), }); } }; getTransferData = (): void => { const transferData: TransferData = this.fileTransferModel.generateTransferData(); this.transferChannel.value = transferData.channel; this.transferKey.value = transferData.key; }; // view showDirectionSelectionModal = (): void => { this.presentedModal.value = FileTransferModal.DirectionSelection; this.getOptions(); }; showFileSelectionModal = (): void => { this.presentedModal.value = FileTransferModal.FileSelection; }; showTransferDataModal = (): void => { this.presentedModal.value = FileTransferModal.TransferDataDisplay; this.getTransferData(); }; hideModal = (): void => { this.presentedModal.value = undefined; }; // init constructor( fileTransferModel: FileTransferModel, chatListModel: ChatListModel ) { this.fileTransferModel = fileTransferModel; this.chatListModel = chatListModel; } } export interface FileTransferOption { label: string; path: string[]; } export enum FileTransferModal { DirectionSelection, // sending FileSelection, TransferDataDisplay, TransferDisplay, // receiving TransferDataInput, ReceptionDisplay, }