forked from mystiq/hydrogen-web
add clear cache button for session
This commit is contained in:
parent
ad7a150aaa
commit
e2b9e9dfdc
2 changed files with 40 additions and 3 deletions
|
@ -7,6 +7,7 @@ class SessionItemViewModel extends EventEmitter {
|
|||
this._pickerVM = pickerVM;
|
||||
this._sessionInfo = sessionInfo;
|
||||
this._isDeleting = false;
|
||||
this._isClearing = false;
|
||||
this._error = null;
|
||||
}
|
||||
|
||||
|
@ -29,10 +30,29 @@ class SessionItemViewModel extends EventEmitter {
|
|||
}
|
||||
}
|
||||
|
||||
async clear() {
|
||||
this._isClearing = true;
|
||||
this.emit("change", "isClearing");
|
||||
try {
|
||||
await this._pickerVM.clear(this.id);
|
||||
} catch(err) {
|
||||
this._error = err;
|
||||
console.error(err);
|
||||
this.emit("change", "error");
|
||||
} finally {
|
||||
this._isClearing = false;
|
||||
this.emit("change", "isClearing");
|
||||
}
|
||||
}
|
||||
|
||||
get isDeleting() {
|
||||
return this._isDeleting;
|
||||
}
|
||||
|
||||
get isClearing() {
|
||||
return this._isClearing;
|
||||
}
|
||||
|
||||
get id() {
|
||||
return this._sessionInfo.id;
|
||||
}
|
||||
|
@ -73,6 +93,10 @@ export default class SessionPickerViewModel {
|
|||
this._sessions.remove(idx);
|
||||
}
|
||||
|
||||
async clear(id) {
|
||||
await this._storageFactory.delete(id);
|
||||
}
|
||||
|
||||
get sessions() {
|
||||
return this._sessions;
|
||||
}
|
||||
|
|
|
@ -5,22 +5,35 @@ class SessionPickerItem extends TemplateView {
|
|||
constructor(vm) {
|
||||
super(vm, true);
|
||||
this._onDeleteClick = this._onDeleteClick.bind(this);
|
||||
this._onClearClick = this._onClearClick.bind(this);
|
||||
}
|
||||
|
||||
_onDeleteClick(event) {
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
this.viewModel.delete();
|
||||
if (confirm("Are you sure?")) {
|
||||
this.viewModel.delete();
|
||||
}
|
||||
}
|
||||
|
||||
_onClearClick(event) {
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
this.viewModel.clear();
|
||||
}
|
||||
|
||||
render(t) {
|
||||
const deleteButton = t.button({
|
||||
disabled: vm => vm.isDeleting,
|
||||
onClick: event => this._onDeleteClick(event)
|
||||
onClick: this._onDeleteClick,
|
||||
}, "Delete");
|
||||
const clearButton = t.button({
|
||||
disabled: vm => vm.isClearing,
|
||||
onClick: this._onClearClick,
|
||||
}, "Clear");
|
||||
const userName = t.span({className: "userId"}, vm => vm.userId);
|
||||
const errorMessage = t.if(vm => vm.error, t => t.span({className: "error"}, vm => vm.error));
|
||||
return t.li([userName, errorMessage, deleteButton]);
|
||||
return t.li([userName, errorMessage, clearButton, deleteButton]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue