Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Profile import auto refresh when some or all packages are not found #1655

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 47 additions & 28 deletions src/components/profiles-modals/ImportProfileModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ import { valueToReadableDate } from "../../utils/DateUtils";
import * as ProfileUtils from "../../utils/ProfileUtils";
import { ModalCard } from "../all";
import ProfilesMixin from "../mixins/ProfilesMixin.vue";
import Progress from "../Progress.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}
components: {Progress, OnlineModList, ModalCard}
})
export default class ImportProfileModal extends mixins(ProfilesMixin) {
valueToReadableDate = valueToReadableDate;
Expand All @@ -36,6 +37,7 @@ export default class ImportProfileModal extends mixins(ProfilesMixin) {
'FILE_CODE_SELECTION'
| 'IMPORT_FILE'
| 'IMPORT_CODE'
| 'REFRESH_MOD_LIST'
| 'REVIEW_IMPORT'
| 'IMPORT_UPDATE_SELECTION'
| 'ADDING_PROFILE'
Expand Down Expand Up @@ -123,7 +125,7 @@ export default class ImportProfileModal extends mixins(ProfilesMixin) {
}

// Check that selected profile zip is valid and proceed.
async validateProfileFile(files: string[] | null) {
async validateProfileFile(files: string[] | null, isRetry: boolean = false) {
if (files === null || files.length === 0) {
this.closeModal();
return;
Expand All @@ -144,6 +146,25 @@ export default class ImportProfileModal extends mixins(ProfilesMixin) {
}

this.profileImportFilePath = files[0];

if (this.profileMods.known.length === 0 || this.profileMods.unknown.length > 0) {
// Sometimes the reason some packages are unknown is that the mod is out of date,
// so let's try refreshing it
try {
this.activeStep = 'REFRESH_MOD_LIST';
await this.$store.dispatch('tsMods/syncPackageList');
this.profileMods = await ProfileUtils.exportModsToCombos(
this.profileImportContent.getMods(),
this.$store.state.activeGame
);
} catch (e: unknown) {
const err = R2Error.fromThrownValue(e);
this.$store.commit('error/handleError', err);
this.closeModal();
return;
}
}

this.activeStep = 'REVIEW_IMPORT';
}

Expand Down Expand Up @@ -297,18 +318,39 @@ export default class ImportProfileModal extends mixins(ProfilesMixin) {
</template>
</ModalCard>

<ModalCard v-else-if="activeStep === 'REFRESH_MOD_LIST'" key="REFRESH_MOD_LIST" :is-active="isOpen" :can-close="false">
<template v-slot:header>
<h2 class="modal-title">Refreshing mod list</h2>
</template>
<template v-slot:footer>
<div>
<p>
At least some of the packages were not found. We're trying to fix this by refreshing the online mod list:</br>
{{$store.state.tsMods.thunderstoreModListUpdateStatus}}
</p>
</div>
</template>
</ModalCard>

<ModalCard v-else-if="activeStep === 'REVIEW_IMPORT'" key="REVIEW_IMPORT" :is-active="isOpen" @close-modal="closeModal">
<template v-slot:header>
<h2 class="modal-title">Packages to be installed</h2>
</template>
<template v-slot:body>
<OnlineModList :paged-mod-list="knownProfileMods" :read-only="true" />
<OnlineModList
v-if="profileMods.known.length > 0"
:paged-mod-list="knownProfileMods"
:read-only="true"
/>
<p v-else>
None of the packages in the profile were found on Thunderstore.
</p>
<div v-if="profileMods.known.length === 0 || profileMods.unknown.length > 0" class="notification is-warning margin-top">
<p v-if="profileMods.known.length === 0">
None of the packages in the profile were found on Thunderstore:
These packages were not found:
</p>
<p v-else>
Some of the packages in the profile were not found on Thunderstore:
These packages in the profile were found on Thunderstore:
</p>

<p class="margin-top">{{ unknownProfileModNames }}</p>
Expand All @@ -319,29 +361,6 @@ export default class ImportProfileModal extends mixins(ProfilesMixin) {
<p v-else class="margin-top">
Ensure the profile is intended for the currently selected game.
</p>

<p class="margin-top">
Updating the mod list from Thunderstore might solve this issue.

<span v-if="$store.state.tsMods.modsLastUpdated">
The mod list was last updated on {{ valueToReadableDate($store.state.tsMods.modsLastUpdated) }}.
</span>

<br />

<span v-if="$store.state.tsMods.isThunderstoreModListUpdateInProgress">
{{ $store.state.tsMods.thunderstoreModListUpdateStatus }}
</span>
<span v-else-if="$store.state.tsMods.thunderstoreModListUpdateError">
Error updating the mod list:
{{ $store.state.tsMods.thunderstoreModListUpdateError.message }}.
<a @click="$store.dispatch('tsMods/syncPackageList')">Retry</a>?
</span>
<span v-else>
Would you like to
<a @click="$store.dispatch('tsMods/syncPackageList')">update now</a>?
</span>
</p>
</div>
</template>
<template v-slot:footer>
Expand Down
Loading