Files
CT/src/ViewModel/Global/fileTransferViewModel.ts
T

85 lines
2.1 KiB
TypeScript
Raw Normal View History

2024-07-27 19:13:59 +02:00
import * as React from "bloatless-react";
import StorageModel, {
StorageModelSubPath,
} from "../../Model/Global/storageModel";
import ChatListModel from "../../Model/Chat/chatListModel";
import ChatModel from "../../Model/Chat/chatModel";
import FileTransferModel from "../../Model/Global/fileTransferModel";
import { translations } from "../../View/translations";
export default class FileTransferViewModel {
fileTransferModel: FileTransferModel;
chatListModel: ChatListModel;
// state
isShowingTransferModal: React.State<boolean> = new React.State(false);
generalFileOptions: React.ListState<FileTransferOption> =
new React.ListState();
chatFileOptions: React.ListState<FileTransferOption> = new React.ListState();
2024-07-27 19:40:16 +02:00
selectedPaths: React.ListState<string[]> = new React.ListState();
2024-07-27 19:13:59 +02:00
// methods
getOptions = (): void => {
this.generalFileOptions.clear();
this.chatFileOptions.clear();
this.generalFileOptions.add(
{
2024-07-27 23:45:36 +02:00
label: translations.dataTransferModal.connectionData,
2024-07-27 19:13:59 +02:00
path: StorageModel.getPath(StorageModelSubPath.ConnectionModel, []),
},
{
2024-07-27 23:45:36 +02:00
label: translations.dataTransferModal.settingsData,
2024-07-27 19:13:59 +02:00
path: StorageModel.getPath(StorageModelSubPath.SettingsModel, []),
}
);
const chatModels: Set<ChatModel> = this.chatListModel.chatModels;
for (const chatModel of chatModels) {
this.chatFileOptions.add({
label: chatModel.info.primaryChannel,
path: chatModel.getBasePath(),
});
}
};
// view
showTransferModal = (): void => {
this.isShowingTransferModal.value = true;
this.getOptions();
};
hideTransferModal = (): void => {
this.isShowingTransferModal.value = false;
};
// init
constructor(
fileTransferModel: FileTransferModel,
chatListModel: ChatListModel
) {
this.fileTransferModel = fileTransferModel;
this.chatListModel = chatListModel;
}
}
export interface FileTransferOption {
label: string;
path: string[];
}
2024-07-27 23:45:36 +02:00
export enum FileTransferModals {
DirectionSelection,
// sending
FileSelection,
TransferDataDisplay,
TransferDisplay,
// receiving
TransferDataInput,
ReceptionDisplay
}