mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 11:35:04 +01:00
add export/import of session data
This commit is contained in:
parent
e2b9e9dfdc
commit
6f73d3983f
@ -32,6 +32,7 @@ class SessionItemViewModel extends EventEmitter {
|
|||||||
|
|
||||||
async clear() {
|
async clear() {
|
||||||
this._isClearing = true;
|
this._isClearing = true;
|
||||||
|
alert(JSON.stringify(this._sessionInfo, undefined, 2));
|
||||||
this.emit("change", "isClearing");
|
this.emit("change", "isClearing");
|
||||||
try {
|
try {
|
||||||
await this._pickerVM.clear(this.id);
|
await this._pickerVM.clear(this.id);
|
||||||
@ -71,7 +72,7 @@ export default class SessionPickerViewModel {
|
|||||||
this._storageFactory = storageFactory;
|
this._storageFactory = storageFactory;
|
||||||
this._sessionStore = sessionStore;
|
this._sessionStore = sessionStore;
|
||||||
this._sessionCallback = sessionCallback;
|
this._sessionCallback = sessionCallback;
|
||||||
this._sessions = new SortedArray((s1, s2) => (s1.sessionInfo.lastUsed || 0) - (s2.sessionInfo.lastUsed || 0));
|
this._sessions = new SortedArray((s1, s2) => s1.id.localeCompare(s2.id));
|
||||||
}
|
}
|
||||||
|
|
||||||
async load() {
|
async load() {
|
||||||
@ -86,6 +87,15 @@ export default class SessionPickerViewModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async import(json) {
|
||||||
|
const sessionInfo = JSON.parse(json);
|
||||||
|
const sessionId = (Math.floor(Math.random() * Number.MAX_SAFE_INTEGER)).toString();
|
||||||
|
sessionInfo.id = sessionId;
|
||||||
|
sessionInfo.lastUsed = sessionId;
|
||||||
|
await this._sessionStore.add(sessionInfo);
|
||||||
|
this._sessions.set(new SessionItemViewModel(sessionInfo, this));
|
||||||
|
}
|
||||||
|
|
||||||
async delete(id) {
|
async delete(id) {
|
||||||
const idx = this._sessions.array.findIndex(s => s.id === id);
|
const idx = this._sessions.array.findIndex(s => s.id === id);
|
||||||
await this._sessionStore.delete(id);
|
await this._sessionStore.delete(id);
|
||||||
|
@ -54,7 +54,8 @@ export default class SessionPickerView extends TemplateView {
|
|||||||
return t.div({className: "SessionPickerView"}, [
|
return t.div({className: "SessionPickerView"}, [
|
||||||
t.h1(["Pick a session"]),
|
t.h1(["Pick a session"]),
|
||||||
this._sessionList.mount(),
|
this._sessionList.mount(),
|
||||||
t.button({onClick: () => this.viewModel.cancel()}, ["Log in to a new session instead"])
|
t.p(t.button({onClick: () => this.viewModel.cancel()}, ["Log in to a new session instead"])),
|
||||||
|
t.p(t.button({onClick: () => this.viewModel.import(prompt("JSON"))}, ["Import Session JSON"]))
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user