Skip to content

Commit a0e21b5

Browse files
committed
Add form to configure custom web instance
1 parent 06237b1 commit a0e21b5

File tree

2 files changed

+46
-13
lines changed

2 files changed

+46
-13
lines changed

src/open/ClientView.js

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ function renderInstructions(parts) {
3939
export class ClientView extends TemplateView {
4040

4141
render(t, vm) {
42+
return t.mapView(vm => vm.customWebInstanceFormOpen, open => {
43+
switch (open) {
44+
case true: return new SetCustomWebInstanceView(vm);
45+
case false: return new TemplateView(vm, t => this.renderContent(t, vm));
46+
}
47+
});
48+
}
49+
renderContent(t, vm) {
4250
return t.div({className: {"ClientView": true, "isPreferred": vm => vm.hasPreferredWebInstance}}, [
4351
... vm.hasPreferredWebInstance ? [t.div({className: "hostedBanner"}, vm.hostedByBannerLabel)] : [],
4452
t.div({className: "header"}, [
@@ -119,32 +127,40 @@ export class SetCustomWebInstanceView extends TemplateView {
119127
"Use a custom web instance for the ", t.strong(vm.name), " client:",
120128
]),
121129
t.form({action: "#", id: "setCustomWebInstanceForm", onSubmit: evt => this._onSubmit(evt)}, [
122-
t.label([
123-
"Host name:",
124-
t.input({
125-
type: "text",
126-
className: "line",
127-
placeholder: "chat.example.org",
128-
name: "instanceHostname",
129-
})
130-
])
130+
t.input({
131+
type: "text",
132+
className: "fullwidth large",
133+
placeholder: "chat.example.org",
134+
name: "instanceHostname",
135+
value: vm.preferredWebInstance || "",
136+
}),
137+
t.input({type: "submit", value: "Save", className: "primary fullwidth"}),
138+
t.input({type: "button", value: "Use Default Instance", className: "secondary fullwidth", onClick: evt => this._onReset(evt)}),
131139
])
132140
]);
133141
}
134142

135143
_onSubmit(evt) {
136144
evt.preventDefault();
137-
this.value.continueWithSelection(this._askEveryTimeChecked);
145+
const form = evt.target;
146+
const {instanceHostname} = form.elements;
147+
this.value.setCustomWebInstance(instanceHostname.value || undefined);
148+
this.value.closeCustomWebInstanceForm();
149+
}
150+
151+
_onReset(evt) {
152+
this.value.setCustomWebInstance(undefined);
153+
this.value.closeCustomWebInstanceForm();
138154
}
139155
}
140156

141157
function showBack(t, vm) {
142158
return t.p({className: {caption: true, "back": true, hidden: vm => !vm.showBack}}, [
143159
`Continue with ${vm.name} · `,
144160
t.button({className: "text", onClick: () => vm.back()}, "Change"),
145-
t.span({hidden: vm => !vm.showSetWebInstance}, [
161+
t.span({hidden: vm => !vm.supportsCustomWebInstances}, [
146162
' · ',
147-
t.button({className: "text", onClick: () => vm.setCustomWebInstance()}, "Use Custom Web Instance"),
163+
t.button({className: "text", onClick: () => vm.configureCustomWebInstance()}, "Use Custom Web Instance"),
148164
])
149165

150166
]);

src/open/ClientViewModel.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export class ClientViewModel extends ViewModel {
3535
this._pickClient = pickClient;
3636
// to provide "choose other client" button after calling pick()
3737
this._clientListViewModel = null;
38+
this.customWebInstanceFormOpen = false;
3839
this._update();
3940
}
4041

@@ -231,7 +232,7 @@ export class ClientViewModel extends ViewModel {
231232
return !!this._clientListViewModel;
232233
}
233234

234-
get showSetWebInstance() {
235+
get supportsCustomWebInstances() {
235236
return !!this._client.supportsCustomInstances;
236237
}
237238

@@ -249,4 +250,20 @@ export class ClientViewModel extends ViewModel {
249250
vm.showAll();
250251
}
251252
}
253+
254+
configureCustomWebInstance() {
255+
this.customWebInstanceFormOpen = true;
256+
this.emitChange();
257+
}
258+
259+
closeCustomWebInstanceForm() {
260+
this.customWebInstanceFormOpen = false;
261+
this.emitChange();
262+
}
263+
264+
setCustomWebInstance(hostname) {
265+
this.preferences.setClient(this._client.id, hostname ? this._webPlatform : this._proposedPlatform);
266+
this.preferences.setPreferredWebInstance(this._client.id, hostname);
267+
this._update();
268+
}
252269
}

0 commit comments

Comments
 (0)