Skip to content

feat(frontend): Store last selected game version and platform for download modal #3284

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

Closed
57 changes: 19 additions & 38 deletions apps/frontend/src/pages/[type]/[id].vue
Original file line number Diff line number Diff line change
Expand Up @@ -244,22 +244,7 @@
</div>

<div class="mx-auto flex w-fit flex-col gap-2">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this removed? "Error: no game versions found"

<ButtonStyled v-if="project.game_versions.length === 1">
<div class="disabled button-like">
<GameIcon aria-hidden="true" />
{{
currentGameVersion
? `Game version: ${currentGameVersion}`
: "Error: no game versions found"
}}
<InfoIcon
v-tooltip="`${project.title} is only available for ${currentGameVersion}`"
class="ml-auto size-5"
/>
</div>
</ButtonStyled>
<Accordion
v-else
ref="gameVersionAccordion"
class="accordion-with-bg"
@on-open="
Expand Down Expand Up @@ -313,7 +298,7 @@
}"
@click="
() => {
userSelectedGameVersion = gameVersion;
setSelectedGameVersion(gameVersion);
gameVersionAccordion.close();
if (!currentPlatform && platformAccordion) {
platformAccordion.open();
Expand Down Expand Up @@ -341,26 +326,8 @@
:disabled="!!versionFilter"
/>
</Accordion>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, why was this removed?

<ButtonStyled
v-if="project.loaders.length === 1 && project.project_type !== 'resourcepack'"
>
<div class="disabled button-like">
<WrenchIcon aria-hidden="true" />
{{
currentPlatform
? `Platform: ${formatCategory(currentPlatform)}`
: "Error: no platforms found"
}}
<InfoIcon
v-tooltip="
`${project.title} is only available for ${formatCategory(currentPlatform)}`
"
class="ml-auto size-5"
/>
</div>
</ButtonStyled>
<Accordion
v-else-if="project.project_type !== 'resourcepack'"
v-if="project.project_type !== 'resourcepack'"
ref="platformAccordion"
class="accordion-with-bg"
@on-open="
Expand Down Expand Up @@ -396,7 +363,7 @@
}"
@click="
() => {
userSelectedPlatform = platform;
setSelectedPlatform(platform);

platformAccordion.close();
if (!currentGameVersion && gameVersionAccordion) {
Expand Down Expand Up @@ -915,7 +882,6 @@ import {
ImageIcon as GalleryIcon,
GameIcon,
HeartIcon,
InfoIcon,
LinkIcon as LinksIcon,
MoreVerticalIcon,
PlusIcon,
Expand Down Expand Up @@ -992,6 +958,10 @@ const overTheTopDownloadAnimation = ref();
const userSelectedGameVersion = ref(null);
const userSelectedPlatform = ref(null);
const showAllVersions = ref(false);
if (import.meta.client) {
userSelectedGameVersion.value = localStorage.getItem("selected_game_version");
userSelectedPlatform.value = localStorage.getItem("selected_platform");
}

const gameVersionFilterInput = ref();

Expand Down Expand Up @@ -1090,7 +1060,18 @@ const licenseIdDisplay = computed(() => {
return id;
}
});

function setSelectedGameVersion(version) {
userSelectedGameVersion.value = version;
if (import.meta.client) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than actually calling localStorage, it might be best to use useLocalStorage composable provided by vueuse, which handles the import.meta.client stuff for you automatically.

Also, make sure that it correctly falls back to undefined/not set if the local storage game version isn't actually supported by the project.

localStorage.setItem("selected_game_version", version);
}
}
function setSelectedPlatform(platform) {
userSelectedPlatform.value = platform;
if (import.meta.client) {
localStorage.setItem("selected_platform", platform);
}
}
async function getLicenseData(event) {
modalLicense.value.show(event);

Expand Down