Skip the Sockethub server step in calendar setup when already configured
Track whether a Sockethub URL has been stored and start the ICS and CalDAV add flows past the server step for returning users, while keeping it for first-timers. Back navigation stops before the removed step, and the step's helper text now links Sockethub to its website.
This commit is contained in:
1 parent
13e02168c9
commit
4c9d6093c0
6 files changed
+220
-33
No files matched your search
@@ -18,7 +18,7 @@ export default class SettingsIntegrationsCalendarCaldavForm extends Component {
|
||||
@service calendar;
|
||||
@service sockethub;
|
||||
|
||||
@tracked step = 1;
|
||||
@tracked step = null;
|
||||
@tracked serverUrlDraft = null;
|
||||
@tracked caldavUrlDraft = null;
|
||||
@tracked usernameDraft = null;
|
||||
@@ -28,6 +28,8 @@ export default class SettingsIntegrationsCalendarCaldavForm extends Component {
|
||||
@tracked error = null;
|
||||
@tracked submitting = false;
|
||||
@tracked refreshing = false;
|
||||
@tracked sockethubReady = false;
|
||||
@tracked hasStoredSockethub = false;
|
||||
|
||||
constructor(owner, args) {
|
||||
super(owner, args);
|
||||
@@ -40,6 +42,28 @@ export default class SettingsIntegrationsCalendarCaldavForm extends Component {
|
||||
this.step = 3;
|
||||
this.refreshCalendars();
|
||||
}
|
||||
|
||||
this.loadSockethubState();
|
||||
}
|
||||
|
||||
async loadSockethubState() {
|
||||
let hasStored = false;
|
||||
|
||||
try {
|
||||
await this.sockethub.loadUrl();
|
||||
hasStored = Boolean(this.sockethub.hasStoredUrl);
|
||||
} catch (err) {
|
||||
console.error('Error loading the Sockethub URL:', err);
|
||||
}
|
||||
|
||||
this.hasStoredSockethub = hasStored;
|
||||
this.sockethubReady = true;
|
||||
|
||||
// Add mode starts with no step; edit mode (with an integration) already
|
||||
// chose one. Anything still undecided falls back to the normal first step.
|
||||
if (this.step === null) {
|
||||
this.step = hasStored ? 2 : 1;
|
||||
}
|
||||
}
|
||||
|
||||
get integration() {
|
||||
@@ -83,6 +107,20 @@ export default class SettingsIntegrationsCalendarCaldavForm extends Component {
|
||||
return this.step === 2;
|
||||
}
|
||||
|
||||
get isSelectionStep() {
|
||||
return this.step === 3;
|
||||
}
|
||||
|
||||
// Returning users already chose a Sockethub server, so the server step is
|
||||
// skipped and Back must not walk into it.
|
||||
get firstStep() {
|
||||
return this.hasStoredSockethub ? 2 : 1;
|
||||
}
|
||||
|
||||
get canGoBack() {
|
||||
return this.sockethubReady && this.step > this.firstStep;
|
||||
}
|
||||
|
||||
@action
|
||||
isSelected(id) {
|
||||
return this.selectedIds.includes(id);
|
||||
@@ -123,7 +161,7 @@ export default class SettingsIntegrationsCalendarCaldavForm extends Component {
|
||||
@action
|
||||
back() {
|
||||
this.error = null;
|
||||
this.step -= 1;
|
||||
this.step = Math.max(this.step - 1, this.firstStep);
|
||||
}
|
||||
|
||||
@action
|
||||
@@ -289,8 +327,14 @@ export default class SettingsIntegrationsCalendarCaldavForm extends Component {
|
||||
/>
|
||||
</div>
|
||||
<p class="mt-2 text-sm text-gray-500">
|
||||
The Sockethub instance Dashtab talks to. Leave as-is unless you
|
||||
self-host it.
|
||||
The
|
||||
<a
|
||||
href="https://sockethub.org"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
class="text-indigo-600 hover:text-indigo-500"
|
||||
>Sockethub</a>
|
||||
instance Dashtab talks to. Leave as-is unless you self-host it.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -400,13 +444,16 @@ export default class SettingsIntegrationsCalendarCaldavForm extends Component {
|
||||
>
|
||||
Continue
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
{{on "click" this.back}}
|
||||
class="inline-flex w-full justify-center rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50"
|
||||
>
|
||||
Back
|
||||
</button>
|
||||
{{#if this.canGoBack}}
|
||||
<button
|
||||
type="button"
|
||||
data-test-back
|
||||
{{on "click" this.back}}
|
||||
class="inline-flex w-full justify-center rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50"
|
||||
>
|
||||
Back
|
||||
</button>
|
||||
{{/if}}
|
||||
<button
|
||||
type="button"
|
||||
{{on "click" @close}}
|
||||
@@ -416,7 +463,7 @@ export default class SettingsIntegrationsCalendarCaldavForm extends Component {
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
{{else}}
|
||||
{{else if this.isSelectionStep}}
|
||||
<form {{on "submit" this.finish}} class="mt-5">
|
||||
{{#if this.eventCalendars.length}}
|
||||
<fieldset>
|
||||
@@ -495,13 +542,16 @@ export default class SettingsIntegrationsCalendarCaldavForm extends Component {
|
||||
>
|
||||
{{if this.isEdit "Save" "Connect"}}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
{{on "click" this.back}}
|
||||
class="inline-flex w-full justify-center rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50"
|
||||
>
|
||||
Back
|
||||
</button>
|
||||
{{#if this.canGoBack}}
|
||||
<button
|
||||
type="button"
|
||||
data-test-back
|
||||
{{on "click" this.back}}
|
||||
class="inline-flex w-full justify-center rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50"
|
||||
>
|
||||
Back
|
||||
</button>
|
||||
{{/if}}
|
||||
<button
|
||||
type="button"
|
||||
{{on "click" @close}}
|
||||
|
||||
@@ -16,11 +16,13 @@ export default class SettingsIntegrationsCalendarIcsForm extends Component {
|
||||
@service calendar;
|
||||
@service sockethub;
|
||||
|
||||
@tracked step = 1;
|
||||
@tracked step = null;
|
||||
@tracked serverUrlDraft = null;
|
||||
@tracked feedUrlDraft = null;
|
||||
@tracked error = null;
|
||||
@tracked submitting = false;
|
||||
@tracked sockethubReady = false;
|
||||
@tracked hasStoredSockethub = false;
|
||||
|
||||
constructor(owner, args) {
|
||||
super(owner, args);
|
||||
@@ -28,6 +30,28 @@ export default class SettingsIntegrationsCalendarIcsForm extends Component {
|
||||
if (args.props?.mode === 'edit' && args.props?.integration) {
|
||||
this.step = 2;
|
||||
}
|
||||
|
||||
this.loadSockethubState();
|
||||
}
|
||||
|
||||
async loadSockethubState() {
|
||||
let hasStored = false;
|
||||
|
||||
try {
|
||||
await this.sockethub.loadUrl();
|
||||
hasStored = Boolean(this.sockethub.hasStoredUrl);
|
||||
} catch (err) {
|
||||
console.error('Error loading the Sockethub URL:', err);
|
||||
}
|
||||
|
||||
this.hasStoredSockethub = hasStored;
|
||||
this.sockethubReady = true;
|
||||
|
||||
// Add mode starts with no step; edit mode (with an integration) already
|
||||
// chose one. Anything still undecided falls back to the normal first step.
|
||||
if (this.step === null) {
|
||||
this.step = hasStored ? 2 : 1;
|
||||
}
|
||||
}
|
||||
|
||||
get integration() {
|
||||
@@ -56,6 +80,20 @@ export default class SettingsIntegrationsCalendarIcsForm extends Component {
|
||||
return this.step === 1;
|
||||
}
|
||||
|
||||
get isFeedStep() {
|
||||
return this.step === 2;
|
||||
}
|
||||
|
||||
// Returning users already chose a Sockethub server, so the server step is
|
||||
// skipped and Back must not walk into it.
|
||||
get firstStep() {
|
||||
return this.hasStoredSockethub ? 2 : 1;
|
||||
}
|
||||
|
||||
get canGoBack() {
|
||||
return this.sockethubReady && this.step > this.firstStep;
|
||||
}
|
||||
|
||||
@action
|
||||
updateServerUrl(event) {
|
||||
this.serverUrlDraft = event.target.value;
|
||||
@@ -71,7 +109,7 @@ export default class SettingsIntegrationsCalendarIcsForm extends Component {
|
||||
@action
|
||||
back() {
|
||||
this.error = null;
|
||||
this.step = 1;
|
||||
this.step = Math.max(this.step - 1, this.firstStep);
|
||||
}
|
||||
|
||||
@action
|
||||
@@ -160,8 +198,14 @@ export default class SettingsIntegrationsCalendarIcsForm extends Component {
|
||||
/>
|
||||
</div>
|
||||
<p class="mt-2 text-sm text-gray-500">
|
||||
The Sockethub instance Dashtab talks to. Leave as-is unless you
|
||||
self-host it.
|
||||
The
|
||||
<a
|
||||
href="https://sockethub.org"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
class="text-indigo-600 hover:text-indigo-500"
|
||||
>Sockethub</a>
|
||||
instance Dashtab talks to. Leave as-is unless you self-host it.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -186,7 +230,7 @@ export default class SettingsIntegrationsCalendarIcsForm extends Component {
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
{{else}}
|
||||
{{else if this.isFeedStep}}
|
||||
<form {{on "submit" this.submitFeed}} class="mt-5">
|
||||
<div>
|
||||
<label
|
||||
@@ -225,13 +269,16 @@ export default class SettingsIntegrationsCalendarIcsForm extends Component {
|
||||
>
|
||||
{{if this.isEdit "Save" "Connect"}}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
{{on "click" this.back}}
|
||||
class="inline-flex w-full justify-center rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50"
|
||||
>
|
||||
Back
|
||||
</button>
|
||||
{{#if this.canGoBack}}
|
||||
<button
|
||||
type="button"
|
||||
data-test-back
|
||||
{{on "click" this.back}}
|
||||
class="inline-flex w-full justify-center rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50"
|
||||
>
|
||||
Back
|
||||
</button>
|
||||
{{/if}}
|
||||
<button
|
||||
type="button"
|
||||
{{on "click" @close}}
|
||||
|
||||
@@ -49,6 +49,10 @@ export default class SockethubService extends Service {
|
||||
@tracked error = null;
|
||||
@tracked url = null;
|
||||
@tracked descriptor = null;
|
||||
// Whether the user (or an earlier setup step) has saved a server URL, as
|
||||
// opposed to still using the built-in default. Lets the calendar forms skip
|
||||
// the server step for returning users while keeping it for first-timers.
|
||||
@tracked hasStoredUrl = false;
|
||||
|
||||
client = null;
|
||||
consumers = new Set();
|
||||
@@ -76,6 +80,7 @@ export default class SockethubService extends Service {
|
||||
SOCKETHUB_URL_KEY
|
||||
);
|
||||
|
||||
this.hasStoredUrl = Boolean(stored);
|
||||
this.url = stored ?? DEFAULT_SOCKETHUB_URL;
|
||||
return this.url;
|
||||
}
|
||||
@@ -87,6 +92,7 @@ export default class SockethubService extends Service {
|
||||
SOCKETHUB_URL_KEY,
|
||||
url
|
||||
);
|
||||
this.hasStoredUrl = true;
|
||||
|
||||
// Reconnect so a running integration picks up the new server.
|
||||
if (this.consumers.size > 0) {
|
||||
|
||||
@@ -10,7 +10,12 @@ function registerServices(owner, overrides = {}) {
|
||||
};
|
||||
const sockethub = overrides.sockethub ?? {
|
||||
url: 'https://sh.example.org',
|
||||
setUrl: async () => {},
|
||||
hasStoredUrl: false,
|
||||
loadUrl: async () => 'https://sh.example.org',
|
||||
async setUrl(url) {
|
||||
this.url = url;
|
||||
this.hasStoredUrl = true;
|
||||
},
|
||||
};
|
||||
|
||||
owner.register('service:calendar', calendar, { instantiate: false });
|
||||
@@ -51,9 +56,11 @@ module(
|
||||
|
||||
assert.dom().containsText('Add CalDAV Calendar');
|
||||
assert.dom('#caldav-server-url').hasValue('https://sh.example.org');
|
||||
assert.dom('a[href="https://sockethub.org"]').exists();
|
||||
|
||||
await triggerEvent('form', 'submit');
|
||||
assert.dom('#caldav-url').exists();
|
||||
assert.dom('[data-test-back]').exists();
|
||||
|
||||
await fillIn('#caldav-url', 'cal.example/dav/');
|
||||
await fillIn('#caldav-username', 'alice');
|
||||
@@ -122,6 +129,39 @@ module(
|
||||
assert.strictEqual(configured.length, 0);
|
||||
});
|
||||
|
||||
test('skips the server step when a Sockethub URL is stored', async function (assert) {
|
||||
registerServices(this.owner, {
|
||||
sockethub: {
|
||||
url: 'https://sh.example.org',
|
||||
hasStoredUrl: true,
|
||||
loadUrl: async () => 'https://sh.example.org',
|
||||
setUrl: async () => {},
|
||||
},
|
||||
calendar: {
|
||||
fetchCalendars: async () => [
|
||||
{ id: 'c1', name: 'Work', components: ['event'] },
|
||||
],
|
||||
configureCaldav: async () => {},
|
||||
},
|
||||
});
|
||||
|
||||
const noop = () => {};
|
||||
|
||||
await render(<template><CalendarCaldavForm @close={{noop}} /></template>);
|
||||
|
||||
assert.dom('#caldav-server-url').doesNotExist();
|
||||
assert.dom('#caldav-url').exists();
|
||||
assert.dom('[data-test-back]').doesNotExist();
|
||||
|
||||
await fillIn('#caldav-url', 'https://cal.example/dav/');
|
||||
await fillIn('#caldav-username', 'alice');
|
||||
await fillIn('#caldav-password', 'secret');
|
||||
await triggerEvent('form', 'submit');
|
||||
|
||||
assert.dom('#caldav-calendar-0').exists();
|
||||
assert.dom('[data-test-back]').exists();
|
||||
});
|
||||
|
||||
test('edit opens on the selection step with the stored calendars', async function (assert) {
|
||||
const fetched = [];
|
||||
|
||||
|
||||
@@ -10,7 +10,12 @@ function registerServices(owner, overrides = {}) {
|
||||
};
|
||||
const sockethub = overrides.sockethub ?? {
|
||||
url: 'https://sh.example.org',
|
||||
setUrl: async () => {},
|
||||
hasStoredUrl: false,
|
||||
loadUrl: async () => 'https://sh.example.org',
|
||||
async setUrl(url) {
|
||||
this.url = url;
|
||||
this.hasStoredUrl = true;
|
||||
},
|
||||
};
|
||||
|
||||
owner.register('service:calendar', calendar, { instantiate: false });
|
||||
@@ -47,9 +52,11 @@ module(
|
||||
|
||||
assert.dom().containsText('Add ICS / WebCal Calendar');
|
||||
assert.dom('#ics-server-url').hasValue('https://sh.example.org');
|
||||
assert.dom('a[href="https://sockethub.org"]').exists();
|
||||
|
||||
await triggerEvent('form', 'submit');
|
||||
assert.dom('#ics-feed-url').exists();
|
||||
assert.dom('[data-test-back]').exists();
|
||||
|
||||
await fillIn('#ics-feed-url', 'https://example.org/h.ics');
|
||||
await triggerEvent('form', 'submit');
|
||||
@@ -81,6 +88,25 @@ module(
|
||||
assert.strictEqual(verified.length, 0);
|
||||
});
|
||||
|
||||
test('skips the server step when a Sockethub URL is stored', async function (assert) {
|
||||
registerServices(this.owner, {
|
||||
sockethub: {
|
||||
url: 'https://sh.example.org',
|
||||
hasStoredUrl: true,
|
||||
loadUrl: async () => 'https://sh.example.org',
|
||||
setUrl: async () => {},
|
||||
},
|
||||
});
|
||||
|
||||
const noop = () => {};
|
||||
|
||||
await render(<template><CalendarIcsForm @close={{noop}} /></template>);
|
||||
|
||||
assert.dom('#ics-server-url').doesNotExist();
|
||||
assert.dom('#ics-feed-url').exists();
|
||||
assert.dom('[data-test-back]').doesNotExist();
|
||||
});
|
||||
|
||||
test('edit opens on the feed step prefilled', async function (assert) {
|
||||
registerServices(this.owner);
|
||||
|
||||
|
||||
@@ -65,6 +65,11 @@ class FakeClient {
|
||||
module('Unit | Service | sockethub', function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
hooks.beforeEach(async function () {
|
||||
const storage = this.owner.lookup('service:storage');
|
||||
await storage.remove('settings', 'sockethub-url');
|
||||
});
|
||||
|
||||
function setup(overrides = {}) {
|
||||
const service = this.owner.lookup('service:sockethub');
|
||||
const clients = [];
|
||||
@@ -93,6 +98,18 @@ module('Unit | Service | sockethub', function (hooks) {
|
||||
|
||||
assert.strictEqual(await service.loadUrl(), DEFAULT_SOCKETHUB_URL);
|
||||
assert.strictEqual(service.url, DEFAULT_SOCKETHUB_URL);
|
||||
assert.false(service.hasStoredUrl);
|
||||
});
|
||||
|
||||
test('loadUrl reports a stored server', async function (assert) {
|
||||
const storage = this.owner.lookup('service:storage');
|
||||
await storage.set('settings', 'sockethub-url', 'https://self.example.org');
|
||||
|
||||
const { service } = setup.call(this);
|
||||
|
||||
assert.strictEqual(await service.loadUrl(), 'https://self.example.org');
|
||||
assert.strictEqual(service.url, 'https://self.example.org');
|
||||
assert.true(service.hasStoredUrl);
|
||||
});
|
||||
|
||||
test('acquire connects once and shares the client between consumers', async function (assert) {
|
||||
@@ -218,6 +235,7 @@ module('Unit | Service | sockethub', function (hooks) {
|
||||
|
||||
assert.strictEqual(stored, 'https://other.example.org');
|
||||
assert.strictEqual(service.url, 'https://other.example.org');
|
||||
assert.true(service.hasStoredUrl);
|
||||
assert.true(clients[0].socket.disconnected);
|
||||
assert.strictEqual(service.client, clients[1]);
|
||||
assert.strictEqual(service.status, 'ready');
|
||||
|
||||
Reference in new issue
Block a user