Onboarding devices page: Neutral defaults
This commit is contained in:
1 parent
41ef3b88a0
commit
8591fb5039
3 files changed
+35
-12
No files matched your search
@@ -4,7 +4,7 @@
|
||||
<StackLayout>
|
||||
<Label text="Your Devices" class="h1 text-center m-t-24" textWrap="true" />
|
||||
<Label
|
||||
text="Which devices do you have? The rest of setup will be tailored to them."
|
||||
text="Which devices do you have?"
|
||||
class="body-text m-t-24" textWrap="true" />
|
||||
|
||||
<Label text="Glasses" class="h2 pairing-section m-t-24" />
|
||||
@@ -37,7 +37,7 @@
|
||||
|
||||
<GridLayout row="1" columns="*,*" class="m-t-20">
|
||||
<Button col="0" text="Back" tap="{{ onBackTap }}" />
|
||||
<Button col="1" text="Next" tap="{{ onNextTap }}" class="-primary" />
|
||||
<Button col="1" text="Next" tap="{{ onNextTap }}" class="-primary" isEnabled="{{ nextEnabled }}" />
|
||||
</GridLayout>
|
||||
</GridLayout>
|
||||
</Page>
|
||||
@@ -1,16 +1,16 @@
|
||||
import { EventData, Frame, Observable, View } from "@nativescript/core";
|
||||
|
||||
import { glassesTypeSetting, type GlassesType } from "../ui/dashboard-settings";
|
||||
import { isPreviewOnlyMode, ownsRing, ownsWatch, setOwnsRing, setOwnsWatch, setPreviewOnlyMode } from "./onboarding-state";
|
||||
import { ownsRing, ownsWatch, setOwnsRing, setOwnsWatch, setPreviewOnlyMode } from "./onboarding-state";
|
||||
|
||||
/** A row in the glasses list: a kind of glasses, or no glasses at all. */
|
||||
type GlassesChoice = GlassesType | "preview";
|
||||
|
||||
const GLASSES_OPTIONS: { choice: GlassesChoice; label: string; description?: string }[] = [
|
||||
{ choice: "preview", label: "Preview Only", description: "No glasses: explore Faceclaw on your phone's screen" },
|
||||
{ choice: "g1", label: "Even G1" },
|
||||
{ choice: "g2", label: "Even G2" },
|
||||
{ choice: "rayneo-io", label: "RayNeo iO" },
|
||||
{ choice: "preview", label: "Preview Only", description: "No glasses: explore Faceclaw on your phone's screen" },
|
||||
];
|
||||
|
||||
/** Why this choice can't be made on this phone, or "" when it can. */
|
||||
@@ -37,13 +37,17 @@ export type GlassesOptionItem = {
|
||||
* pages tailor themselves to. Pairing still has the last word on the glasses,
|
||||
* since it can tell what it heard.
|
||||
*
|
||||
* Preview Only is the persisted preview-only flag, and leaves the glasses type
|
||||
* alone; the Permissions page then finishes onboarding instead of moving on to
|
||||
* the firmware step.
|
||||
* Nothing starts out selected, whatever an earlier run stored, and Next waits
|
||||
* for a choice. A tap stores it straight away: Preview Only sets the persisted
|
||||
* preview-only flag and leaves the glasses type alone, so the Permissions page
|
||||
* finishes onboarding instead of moving on to the firmware step.
|
||||
*/
|
||||
export class OnboardingDevicesViewModel extends Observable {
|
||||
/** This visit's choice; the page keeps this model when you come Back to it. */
|
||||
private selected: GlassesChoice | null = null;
|
||||
|
||||
get glassesOptions(): GlassesOptionItem[] {
|
||||
const selected: GlassesChoice = isPreviewOnlyMode() ? "preview" : glassesTypeSetting.get();
|
||||
const selected = this.selected;
|
||||
return GLASSES_OPTIONS.map(({ choice, label, description }) => {
|
||||
const reason = unavailableReason(choice);
|
||||
const note = reason || description || "";
|
||||
@@ -66,11 +70,17 @@ export class OnboardingDevicesViewModel extends Observable {
|
||||
readonly onGlassesRowTap = (args: EventData): void => {
|
||||
const item = (args.object as View).bindingContext as GlassesOptionItem | undefined;
|
||||
if (!item?.selectable) return;
|
||||
this.selected = item.choice;
|
||||
setPreviewOnlyMode(item.choice === "preview");
|
||||
if (item.choice !== "preview") glassesTypeSetting.set(item.choice);
|
||||
this.notifyPropertyChange("glassesOptions", this.glassesOptions);
|
||||
this.notifyPropertyChange("nextEnabled", this.nextEnabled);
|
||||
};
|
||||
|
||||
get nextEnabled(): boolean {
|
||||
return this.selected !== null;
|
||||
}
|
||||
|
||||
get hasRing(): boolean {
|
||||
return ownsRing();
|
||||
}
|
||||
@@ -92,6 +102,7 @@ export class OnboardingDevicesViewModel extends Observable {
|
||||
}
|
||||
|
||||
onNextTap(): void {
|
||||
if (!this.nextEnabled) return;
|
||||
Frame.topmost()?.navigate({
|
||||
moduleName: "phone-ui/onboarding-page",
|
||||
context: { step: 2 },
|
||||
|
||||
@@ -67,7 +67,9 @@ test('the devices page sits between the splash and the disclaimer', () => {
|
||||
assert.equal(state.navigations.pop().moduleName, 'phone-ui/onboarding-devices-page');
|
||||
|
||||
const { OnboardingDevicesViewModel } = loadPage('onboarding-devices-view-model');
|
||||
new OnboardingDevicesViewModel().onNextTap();
|
||||
const devices = new OnboardingDevicesViewModel();
|
||||
tap(devices, 'g2');
|
||||
devices.onNextTap();
|
||||
const next = state.navigations.pop();
|
||||
assert.equal(next.moduleName, 'phone-ui/onboarding-page');
|
||||
assert.equal(next.context.step, 2);
|
||||
@@ -90,12 +92,18 @@ test('choosing glasses selects exactly one, and the accessories are stored', ()
|
||||
const { state, loadPage } = fixture();
|
||||
const { OnboardingDevicesViewModel } = loadPage('onboarding-devices-view-model');
|
||||
const model = new OnboardingDevicesViewModel();
|
||||
assert.equal(model.glassesOptions.map(option => option.choice).join(), 'g1,g2,rayneo-io,preview');
|
||||
assert.equal(selected(model), 'g2');
|
||||
assert.equal(model.glassesOptions.map(option => option.choice).join(), 'preview,g1,g2,rayneo-io');
|
||||
|
||||
// Nothing is chosen until you choose, even with a stored glasses type, and Next waits for it.
|
||||
assert.equal(selected(model), '');
|
||||
assert.equal(model.nextEnabled, false);
|
||||
model.onNextTap();
|
||||
assert.equal(state.navigations.length, 0);
|
||||
|
||||
tap(model, 'rayneo-io');
|
||||
assert.equal(state.glasses, 'rayneo-io');
|
||||
assert.equal(selected(model), 'rayneo-io');
|
||||
assert.equal(model.nextEnabled, true);
|
||||
|
||||
assert.equal(model.hasRing, false);
|
||||
model.hasRing = true;
|
||||
@@ -117,6 +125,8 @@ test('the watch follows the platform, and iOS can\'t choose a RayNeo iO', () =>
|
||||
assert.equal(rowFor(onIos, 'rayneo-io').noteVisibility, 'visible');
|
||||
tap(onIos, 'rayneo-io');
|
||||
assert.equal(ios.state.glasses, 'g2');
|
||||
assert.equal(selected(onIos), '');
|
||||
assert.equal(onIos.nextEnabled, false);
|
||||
});
|
||||
|
||||
test('the disclaimer and firmware steps name only the chosen glasses', () => {
|
||||
@@ -160,7 +170,9 @@ test('Preview Only is a glasses choice that skips the firmware step', () => {
|
||||
assert.equal(state.previewOnly, true);
|
||||
assert.equal(state.glasses, 'rayneo-io');
|
||||
assert.equal(selected(devices), 'preview');
|
||||
assert.equal(selected(new OnboardingDevicesViewModel()), 'preview');
|
||||
assert.equal(devices.nextEnabled, true);
|
||||
// A later visit (say, after restarting mid-setup) asks again.
|
||||
assert.equal(selected(new OnboardingDevicesViewModel()), '');
|
||||
|
||||
// The disclaimer can't name glasses nobody chose.
|
||||
const { OnboardingViewModel } = loadPage('onboarding-view-model');
|
||||
|
||||
Reference in new issue
Block a user