forked from mystiq/hydrogen-web
remove action buttons on session picker
and now that we're adding logout, none of them are something we want to support really
This commit is contained in:
parent
e3c5def536
commit
2b884e73db
2 changed files with 1 additions and 125 deletions
|
@ -33,44 +33,6 @@ class SessionItemViewModel extends ViewModel {
|
|||
return this._error && this._error.message;
|
||||
}
|
||||
|
||||
async delete() {
|
||||
this._isDeleting = true;
|
||||
this.emitChange("isDeleting");
|
||||
try {
|
||||
await this._pickerVM.delete(this.id);
|
||||
} catch(err) {
|
||||
this._error = err;
|
||||
console.error(err);
|
||||
this.emitChange("error");
|
||||
} finally {
|
||||
this._isDeleting = false;
|
||||
this.emitChange("isDeleting");
|
||||
}
|
||||
}
|
||||
|
||||
async clear() {
|
||||
this._isClearing = true;
|
||||
this.emitChange();
|
||||
try {
|
||||
await this._pickerVM.clear(this.id);
|
||||
} catch(err) {
|
||||
this._error = err;
|
||||
console.error(err);
|
||||
this.emitChange("error");
|
||||
} finally {
|
||||
this._isClearing = false;
|
||||
this.emitChange("isClearing");
|
||||
}
|
||||
}
|
||||
|
||||
get isDeleting() {
|
||||
return this._isDeleting;
|
||||
}
|
||||
|
||||
get isClearing() {
|
||||
return this._isClearing;
|
||||
}
|
||||
|
||||
get id() {
|
||||
return this._sessionInfo.id;
|
||||
}
|
||||
|
@ -96,27 +58,6 @@ class SessionItemViewModel extends ViewModel {
|
|||
return this._exportDataUrl;
|
||||
}
|
||||
|
||||
async export() {
|
||||
try {
|
||||
const data = await this._pickerVM._exportData(this._sessionInfo.id);
|
||||
const json = JSON.stringify(data, undefined, 2);
|
||||
const blob = new Blob([json], {type: "application/json"});
|
||||
this._exportDataUrl = URL.createObjectURL(blob);
|
||||
this.emitChange("exportDataUrl");
|
||||
} catch (err) {
|
||||
alert(err.message);
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
clearExport() {
|
||||
if (this._exportDataUrl) {
|
||||
URL.revokeObjectURL(this._exportDataUrl);
|
||||
this._exportDataUrl = null;
|
||||
this.emitChange("exportDataUrl");
|
||||
}
|
||||
}
|
||||
|
||||
get avatarColorNumber() {
|
||||
return getIdentifierColorNumber(this._sessionInfo.userId);
|
||||
}
|
||||
|
@ -148,43 +89,6 @@ export class SessionPickerViewModel extends ViewModel {
|
|||
return this._loadViewModel;
|
||||
}
|
||||
|
||||
async _exportData(id) {
|
||||
const sessionInfo = await this.platform.sessionInfoStorage.get(id);
|
||||
const stores = await this.logger.run("export", log => {
|
||||
return this.platform.storageFactory.export(id, log);
|
||||
});
|
||||
const data = {sessionInfo, stores};
|
||||
return data;
|
||||
}
|
||||
|
||||
async import(json) {
|
||||
try {
|
||||
const data = JSON.parse(json);
|
||||
const {sessionInfo} = data;
|
||||
sessionInfo.comment = `Imported on ${new Date().toLocaleString()} from id ${sessionInfo.id}.`;
|
||||
sessionInfo.id = this._createSessionContainer().createNewSessionId();
|
||||
await this.logger.run("import", log => {
|
||||
return this.platform.storageFactory.import(sessionInfo.id, data.stores, log);
|
||||
});
|
||||
await this.platform.sessionInfoStorage.add(sessionInfo);
|
||||
this._sessions.set(new SessionItemViewModel(sessionInfo, this));
|
||||
} catch (err) {
|
||||
alert(err.message);
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
async delete(id) {
|
||||
const idx = this._sessions.array.findIndex(s => s.id === id);
|
||||
await this.platform.sessionInfoStorage.delete(id);
|
||||
await this.platform.storageFactory.delete(id);
|
||||
this._sessions.remove(idx);
|
||||
}
|
||||
|
||||
async clear(id) {
|
||||
await this.platform.storageFactory.delete(id);
|
||||
}
|
||||
|
||||
get sessions() {
|
||||
return this._sessions;
|
||||
}
|
||||
|
|
|
@ -57,39 +57,11 @@ class SessionPickerItemView extends TemplateView {
|
|||
}
|
||||
|
||||
render(t, vm) {
|
||||
const deleteButton = t.button({
|
||||
className: "destructive",
|
||||
disabled: vm => vm.isDeleting,
|
||||
onClick: this._onDeleteClick.bind(this),
|
||||
}, "Sign Out");
|
||||
const clearButton = t.button({
|
||||
disabled: vm => vm.isClearing,
|
||||
onClick: this._onClearClick.bind(this),
|
||||
}, "Clear");
|
||||
const exportButton = t.button({
|
||||
disabled: vm => vm.isClearing,
|
||||
onClick: () => vm.export(),
|
||||
}, "Export");
|
||||
const downloadExport = t.if(vm => vm.exportDataUrl, (t, vm) => {
|
||||
return t.a({
|
||||
href: vm.exportDataUrl,
|
||||
download: `brawl-session-${vm.id}.json`,
|
||||
onClick: () => setTimeout(() => vm.clearExport(), 100),
|
||||
}, "Download");
|
||||
});
|
||||
const errorMessage = t.if(vm => vm.error, t => t.p({className: "error"}, vm => vm.error));
|
||||
return t.li([
|
||||
t.a({className: "session-info", href: vm.openUrl}, [
|
||||
t.div({className: `avatar usercolor${vm.avatarColorNumber}`}, vm => vm.avatarInitials),
|
||||
t.div({className: "user-id"}, vm => vm.label),
|
||||
]),
|
||||
t.div({className: "session-actions"}, [
|
||||
deleteButton,
|
||||
exportButton,
|
||||
downloadExport,
|
||||
clearButton,
|
||||
]),
|
||||
errorMessage
|
||||
])
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue