more tweaking to server consent flow and changing servers on preview
This commit is contained in:
@@ -39,7 +39,11 @@ class ShowLinkView extends TemplateView {
|
||||
onClick: () => vm.showClients()
|
||||
}, vm => vm.showClientsLabel)),
|
||||
t.mapView(vm => vm.clientsViewModel, childVM => childVM ? new ClientListView(childVM) : null),
|
||||
t.p({className: {hidden: vm => !vm.previewDomain}}, ["Preview provided by ", vm => vm.previewDomain]),
|
||||
t.p({className: {previewSource: true, hidden: vm => !vm.previewDomain}}, [
|
||||
vm => vm.previewFailed ? `${vm.previewDomain} did not return a preview.` : `Preview provided by ${vm.previewDomain}.`,
|
||||
" ",
|
||||
t.button({className: "text", onClick: () => vm.changeServer()}, "Change"),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,18 +32,22 @@ export class OpenLinkViewModel extends ViewModel {
|
||||
this.clientsViewModel = null;
|
||||
this.previewLoading = false;
|
||||
if (this.preferences.homeservers === null) {
|
||||
this.serverConsentViewModel = new ServerConsentViewModel(this.childOptions({
|
||||
servers: this._link.servers,
|
||||
done: () => {
|
||||
this.serverConsentViewModel = null;
|
||||
this._showLink();
|
||||
}
|
||||
}));
|
||||
this._showServerConsent();
|
||||
} else {
|
||||
this._showLink();
|
||||
}
|
||||
}
|
||||
|
||||
_showServerConsent() {
|
||||
this.serverConsentViewModel = new ServerConsentViewModel(this.childOptions({
|
||||
servers: this._link.servers,
|
||||
done: () => {
|
||||
this.serverConsentViewModel = null;
|
||||
this._showLink();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
async _showLink() {
|
||||
const preferredClient = this.preferences.clientId ? this._clients.find(c => c.id === this.preferences.clientId) : null;
|
||||
this.clientsViewModel = preferredClient ? new ClientListViewModel(this.childOptions({
|
||||
@@ -63,13 +67,24 @@ export class OpenLinkViewModel extends ViewModel {
|
||||
}
|
||||
|
||||
get previewDomain() {
|
||||
return this.previewViewModel.previewDomain;
|
||||
return this.previewViewModel?.domain;
|
||||
}
|
||||
|
||||
get previewFailed() {
|
||||
return this.previewViewModel?.failed;
|
||||
}
|
||||
|
||||
get showClientsLabel() {
|
||||
return getLabelForLinkKind(this._link.kind);
|
||||
}
|
||||
|
||||
changeServer() {
|
||||
this.previewViewModel = null;
|
||||
this.clientsViewModel = null;
|
||||
this._showServerConsent();
|
||||
this.emitChange();
|
||||
}
|
||||
|
||||
showClients() {
|
||||
if (!this.clientsViewModel) {
|
||||
this.clientsViewModel = new ClientListViewModel(this.childOptions({
|
||||
|
||||
@@ -50,7 +50,7 @@ export class ServerConsentView extends TemplateView {
|
||||
t.form({action: "#", onSubmit: evt => this._onSubmit(evt)}, [
|
||||
t.mapView(vm => vm.showSelectServer, show => show ? new ServerOptions(vm) : null),
|
||||
t.div({className: "actions"}, [
|
||||
t.label([t.input({type: "checkbox", name: "persist"}), "Ask every time"]),
|
||||
t.label([t.input({type: "checkbox", name: "askEveryTime"}), "Ask every time"]),
|
||||
t.input({type: "submit", value: "Continue", className: "primary fullwidth"})
|
||||
])
|
||||
])
|
||||
@@ -59,7 +59,8 @@ export class ServerConsentView extends TemplateView {
|
||||
|
||||
_onSubmit(evt) {
|
||||
evt.preventDefault();
|
||||
this.value.continueWithSelection();
|
||||
const {askEveryTime} = evt.target.elements;
|
||||
this.value.continueWithSelection(askEveryTime.checked);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ import {ClientListViewModel} from "./ClientListViewModel.js";
|
||||
import {ClientViewModel} from "./ClientViewModel.js";
|
||||
import {PreviewViewModel} from "../preview/PreviewViewModel.js";
|
||||
import {getLabelForLinkKind} from "../Link.js";
|
||||
import {orderedUnique} from "../utils/unique.js";
|
||||
|
||||
export class ServerConsentViewModel extends ViewModel {
|
||||
constructor(options) {
|
||||
@@ -47,7 +48,7 @@ export class ServerConsentViewModel extends ViewModel {
|
||||
try {
|
||||
const domain = new URL(urlStr).hostname;
|
||||
if (/((?:[0-9a-zA-Z][0-9a-zA-Z-]{1,61}\.)+)(xn--[a-z0-9]+|[a-z]+)/.test(domain) || domain === "localhost") {
|
||||
this.selectServer(urlStr);
|
||||
this.selectServer(domainOrUrl);
|
||||
return true;
|
||||
}
|
||||
} catch (err) {}
|
||||
@@ -55,11 +56,11 @@ export class ServerConsentViewModel extends ViewModel {
|
||||
return false;
|
||||
}
|
||||
|
||||
continueWithSelection() {
|
||||
continueWithSelection(askEveryTime) {
|
||||
// keep previously consented servers
|
||||
const homeservers = this.preferences.homeservers || [];
|
||||
homeservers.unshift(this.selectedServer);
|
||||
this.preferences.setHomeservers(homeservers);
|
||||
this.preferences.setHomeservers(orderedUnique(homeservers), !askEveryTime);
|
||||
this.done();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user