Skip to content

Commit

Permalink
Improve "enter profile code" phase of profile import modal
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
anttimaki committed Jan 27, 2025
1 parent 6f1cfc6 commit cbbf040
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 26 deletions.
6 changes: 0 additions & 6 deletions src/components/mixins/ProfilesMixin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import Component from 'vue-class-component';
import sanitize from "sanitize-filename";
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;
@Component
export default class ProfilesMixin extends Vue {
Expand Down Expand Up @@ -35,9 +33,5 @@ export default class ProfilesMixin extends Vue {
return sanitize(nameToSanitize);
}
isProfileCodeValid(profileImportCode: string): boolean {
return VALID_PROFILE_CODE_REGEX.test(profileImportCode);
}
}
</script>
33 changes: 13 additions & 20 deletions src/components/profiles-modals/ImportProfileModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { ModalCard } from "../all";
import ProfilesMixin from "../mixins/ProfilesMixin.vue";
import OnlineModList from "../views/OnlineModList.vue";
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;
@Component({
components: { OnlineModList, ModalCard}
Expand Down Expand Up @@ -80,6 +81,10 @@ export default class ImportProfileModal extends mixins(ProfilesMixin) {
return this.profileMods.unknown.join(', ');
}
get isProfileCodeValid(): boolean {
return VALID_PROFILE_CODE_REGEX.test(this.profileImportCode);
}
// Fired when user selects to import either from file or code.
async onFileOrCodeSelect(mode: 'FILE' | 'CODE') {
if (mode === 'FILE') {
Expand Down Expand Up @@ -270,39 +275,27 @@ export default class ImportProfileModal extends mixins(ProfilesMixin) {
<template v-slot:body>
<input
v-model="profileImportCode"
@keyup.enter="isProfileCodeValid(profileImportCode) && onProfileCodeEntered()"
@keyup.enter="isProfileCodeValid && !importViaCodeInProgress && onProfileCodeEntered()"
id="import-profile-modal-profile-code"
class="input"
type="text"
ref="profileCodeInput"
placeholder="Enter the profile code"
autocomplete="off"
/>
<br />
<br />
<span class="tag is-dark" v-if="profileImportCode === ''">You haven't entered a code</span>
<span class="tag is-danger" v-else-if="!isProfileCodeValid(profileImportCode)">Invalid code, check for typos</span>
<span class="tag is-success" v-else>You may import the profile</span>
<span class="tag is-danger" v-if="profileImportCode !== '' && !isProfileCodeValid">
Invalid code, check for typos
</span>
</template>
<template v-slot:footer>
<button
id="modal-import-profile-from-code-invalid"
class="button is-danger"
v-if="!isProfileCodeValid(profileImportCode)">
Fix issues before importing
</button>
<button
disabled
id="modal-import-profile-from-code-loading"
class="button is-disabled"
v-else-if="importViaCodeInProgress">
Loading...
</button>
<button
:disabled="!isProfileCodeValid || importViaCodeInProgress"
id="modal-import-profile-from-code"
class="button is-info"
@click="onProfileCodeEntered();"
v-else>
Continue
@click="onProfileCodeEntered();">
{{importViaCodeInProgress ? 'Loading...' : 'Continue'}}
</button>
</template>
</ModalCard>
Expand Down

0 comments on commit cbbf040

Please sign in to comment.