import {
formatBytes,
- formatCategory, formatNumber,
+ formatCategory,
+ formatNumber,
formatVersionsForDisplay,
- type GameVersionTag, type PlatformTag, type Version
+ type GameVersionTag,
+ type PlatformTag,
+ type Version,
} from '@modrinth/utils'
import { commonMessages } from '../../utils/common-messages'
-import {
- CalendarIcon,
- DownloadIcon,
- StarIcon,
-} from '@modrinth/assets'
+import { CalendarIcon, DownloadIcon, StarIcon } from '@modrinth/assets'
import { Pagination, VersionChannelIndicator, VersionFilterControl } from '../index'
import { useVIntl } from '@vintl/vintl'
import { type Ref, ref, computed } from 'vue'
@@ -190,24 +191,24 @@ import TagItem from '../base/TagItem.vue'
const { formatMessage } = useVIntl()
-type VersionWithDisplayUrlEnding = Version & {
+type VersionWithDisplayUrlEnding = Version & {
displayUrlEnding: string
}
const props = withDefaults(
defineProps<{
- baseId?: string,
+ baseId?: string
project: {
project_type: string
slug?: string
id: string
- },
- versions: VersionWithDisplayUrlEnding[],
- showFiles?: boolean,
- currentMember?: boolean,
- loaders: PlatformTag[],
- gameVersions: GameVersionTag[],
- versionLink?: (version: Version) => string,
+ }
+ versions: VersionWithDisplayUrlEnding[]
+ showFiles?: boolean
+ currentMember?: boolean
+ loaders: PlatformTag[]
+ gameVersions: GameVersionTag[]
+ versionLink?: (version: Version) => string
}>(),
{
baseId: undefined,
@@ -217,23 +218,26 @@ const props = withDefaults(
},
)
-const currentPage: Ref = ref(1);
-const pageSize: Ref = ref(20);
+const currentPage: Ref = ref(1)
+const pageSize: Ref = ref(20)
const versionFilters: Ref | null> = ref(null)
-const selectedGameVersions: Ref = computed(() => versionFilters.value?.selectedGameVersions ?? []);
-const selectedPlatforms: Ref = computed(() => versionFilters.value?.selectedPlatforms ?? []);
-const selectedChannels: Ref = computed(() => versionFilters.value?.selectedChannels ?? []);
+const selectedGameVersions: Ref = computed(
+ () => versionFilters.value?.selectedGameVersions ?? [],
+)
+const selectedPlatforms: Ref = computed(
+ () => versionFilters.value?.selectedPlatforms ?? [],
+)
+const selectedChannels: Ref = computed(() => versionFilters.value?.selectedChannels ?? [])
const filteredVersions = computed(() => {
return props.versions.filter(
(version) =>
hasAnySelected(version.game_versions, selectedGameVersions.value) &&
hasAnySelected(version.loaders, selectedPlatforms.value) &&
- isAnySelected(version.version_type, selectedChannels.value)
- );
-});
-
+ isAnySelected(version.version_type, selectedChannels.value),
+ )
+})
function hasAnySelected(values: string[], selected: string[]) {
return selected.length === 0 || selected.some((value) => values.includes(value))
@@ -244,33 +248,37 @@ function isAnySelected(value: string, selected: string[]) {
}
const currentVersions = computed(() =>
- filteredVersions.value.slice((currentPage.value - 1) * pageSize.value, currentPage.value * pageSize.value));
+ filteredVersions.value.slice(
+ (currentPage.value - 1) * pageSize.value,
+ currentPage.value * pageSize.value,
+ ),
+)
-const route = useRoute();
-const router = useRouter();
+const route = useRoute()
+const router = useRouter()
if (route.query.page) {
- currentPage.value = Number(route.query.page) || 1;
+ currentPage.value = Number(route.query.page) || 1
}
function switchPage(page: number) {
- currentPage.value = page;
+ currentPage.value = page
router.replace({
query: {
...route.query,
page: currentPage.value !== 1 ? currentPage.value : undefined,
},
- });
+ })
- window.scrollTo({ top: 0, behavior: 'smooth' });
+ window.scrollTo({ top: 0, behavior: 'smooth' })
}
function updateQuery(newQueries: Record) {
if (newQueries.page) {
- currentPage.value = Number(newQueries.page);
+ currentPage.value = Number(newQueries.page)
} else if (newQueries.page === undefined) {
- currentPage.value = 1;
+ currentPage.value = 1
}
router.replace({
@@ -278,9 +286,8 @@ function updateQuery(newQueries: Record