2019-09-08 10:19:16 +02:00
|
|
|
import {SortedArray} from "../observable/index.js";
|
2019-07-29 22:39:56 +02:00
|
|
|
|
|
|
|
export default class SessionPickerViewModel {
|
|
|
|
constructor({sessionStore, sessionCallback}) {
|
2019-09-08 10:19:16 +02:00
|
|
|
this._sessionStore = sessionStore;
|
2019-07-29 22:39:56 +02:00
|
|
|
this._sessionCallback = sessionCallback;
|
|
|
|
this._sessions = new SortedArray((s1, s2) => (s1.lastUsed || 0) - (s2.lastUsed || 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
async load() {
|
2019-09-08 10:19:16 +02:00
|
|
|
const sessions = await this._sessionStore.getAll();
|
2019-07-29 22:39:56 +02:00
|
|
|
this._sessions.setManyUnsorted(sessions);
|
|
|
|
}
|
|
|
|
|
|
|
|
pick(id) {
|
|
|
|
const session = this._sessions.array.find(s => s.id === id);
|
|
|
|
if (session) {
|
|
|
|
this._sessionCallback(session);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
get sessions() {
|
|
|
|
return this._sessions;
|
|
|
|
}
|
|
|
|
|
|
|
|
cancel() {
|
|
|
|
this._sessionCallback();
|
|
|
|
}
|
|
|
|
}
|