Skip to content

Commit b33feb0

Browse files
committed
Improve "enter profile code" phase of profile import modal
- Remove the somewhat unnecessary "You haven't entered a code" and "You may import the profile" badges that mostly just look awkward - Show "Invalid code" badge only if a profile code has been entered - Remove the big red button when a valid profile code hasn't been entered. This looked like an error state before user has entered the code. Just disabling the Continue button if the code is invalid seems sufficient - Combine the two remaining buttons into one - Prevent submitting the form when the download is already in progress, both via button and key press - Move isProfileCodeValid helper to modal components as that's the only place where it's used. Remove the unnecessary argument to make the method a computed value
1 parent 4c8f91c commit b33feb0

File tree

2 files changed

+13
-26
lines changed

2 files changed

+13
-26
lines changed

Diff for: src/components/mixins/ProfilesMixin.vue

-6
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import Component from 'vue-class-component';
44
55
import sanitize from "sanitize-filename";
66
7-
const VALID_PROFILE_CODE_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
8-
97
@Component
108
export default class ProfilesMixin extends Vue {
119
@@ -35,9 +33,5 @@ export default class ProfilesMixin extends Vue {
3533
return sanitize(nameToSanitize);
3634
}
3735
38-
isProfileCodeValid(profileImportCode: string): boolean {
39-
return VALID_PROFILE_CODE_REGEX.test(profileImportCode);
40-
}
41-
4236
}
4337
</script>

Diff for: src/components/profiles-modals/ImportProfileModal.vue

+13-20
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { ModalCard } from "../all";
1616
import ProfilesMixin from "../mixins/ProfilesMixin.vue";
1717
import OnlineModList from "../views/OnlineModList.vue";
1818
19+
const VALID_PROFILE_CODE_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
1920
2021
@Component({
2122
components: { OnlineModList, ModalCard}
@@ -76,6 +77,10 @@ export default class ImportProfileModal extends mixins(ProfilesMixin) {
7677
return {known, unknown};
7778
}
7879
80+
get isProfileCodeValid(): boolean {
81+
return VALID_PROFILE_CODE_REGEX.test(this.profileImportCode);
82+
}
83+
7984
// Fired when user selects to import either from file or code.
8085
async onFileOrCodeSelect(mode: 'FILE' | 'CODE') {
8186
if (mode === 'FILE') {
@@ -266,39 +271,27 @@ export default class ImportProfileModal extends mixins(ProfilesMixin) {
266271
<template v-slot:body>
267272
<input
268273
v-model="profileImportCode"
269-
@keyup.enter="isProfileCodeValid(profileImportCode) && onProfileCodeEntered()"
274+
@keyup.enter="isProfileCodeValid && !importViaCodeInProgress && onProfileCodeEntered()"
270275
id="import-profile-modal-profile-code"
271276
class="input"
272277
type="text"
273278
ref="profileCodeInput"
279+
placeholder="Enter the profile code"
274280
autocomplete="off"
275281
/>
276282
<br />
277283
<br />
278-
<span class="tag is-dark" v-if="profileImportCode === ''">You haven't entered a code</span>
279-
<span class="tag is-danger" v-else-if="!isProfileCodeValid(profileImportCode)">Invalid code, check for typos</span>
280-
<span class="tag is-success" v-else>You may import the profile</span>
284+
<span class="tag is-danger" v-if="profileImportCode !== '' && !isProfileCodeValid">
285+
Invalid code, check for typos
286+
</span>
281287
</template>
282288
<template v-slot:footer>
283289
<button
284-
id="modal-import-profile-from-code-invalid"
285-
class="button is-danger"
286-
v-if="!isProfileCodeValid(profileImportCode)">
287-
Fix issues before importing
288-
</button>
289-
<button
290-
disabled
291-
id="modal-import-profile-from-code-loading"
292-
class="button is-disabled"
293-
v-else-if="importViaCodeInProgress">
294-
Loading...
295-
</button>
296-
<button
290+
:disabled="!isProfileCodeValid || importViaCodeInProgress"
297291
id="modal-import-profile-from-code"
298292
class="button is-info"
299-
@click="onProfileCodeEntered();"
300-
v-else>
301-
Continue
293+
@click="onProfileCodeEntered();">
294+
{{importViaCodeInProgress ? 'Loading...' : 'Continue'}}
302295
</button>
303296
</template>
304297
</ModalCard>

0 commit comments

Comments
 (0)