|
15 | 15 | /> |
16 | 16 | </div> |
17 | 17 | <div class="card changelog-wrapper"> |
18 | | - <template v-if="paginatedVersions"> |
| 18 | + <template v-if="paginatedVersions && !isLoadingVersions"> |
19 | 19 | <div v-for="version in paginatedVersions" :key="version.id" class="changelog-item"> |
20 | 20 | <div |
21 | 21 | :class="`changelog-bar ${version.version_type} ${version.duplicate ? 'duplicate' : ''}`" |
@@ -78,6 +78,7 @@ import { DownloadIcon, SpinnerIcon } from '@modrinth/assets' |
78 | 78 | import { injectModrinthClient, Pagination } from '@modrinth/ui' |
79 | 79 | import VersionFilterControl from '@modrinth/ui/src/components/version/VersionFilterControl.vue' |
80 | 80 | import { renderHighlightedString } from '@modrinth/utils' |
| 81 | +import { useQuery } from '@tanstack/vue-query' |
81 | 82 |
|
82 | 83 | const props = defineProps({ |
83 | 84 | project: { |
@@ -135,32 +136,44 @@ const filteredVersions = computed(() => { |
135 | 136 |
|
136 | 137 | const { labrinth } = injectModrinthClient() |
137 | 138 |
|
138 | | -const paginatedVersions = ref(null) |
139 | | -
|
140 | | -watch( |
141 | | - [filteredVersions, currentPage], |
142 | | - async ([filtered, page]) => { |
143 | | - const paginated = filtered.slice((page - 1) * 20, page * 20) |
| 139 | +const paginatedVersionIds = computed(() => { |
| 140 | + const page = currentPage.value |
| 141 | + const paginated = filteredVersions.value.slice((page - 1) * 20, page * 20) |
| 142 | + return paginated.map((v) => v.id) |
| 143 | +}) |
144 | 144 |
|
145 | | - const ids = paginated.map((v) => v.id) |
| 145 | +const { data: fetchedVersions, isLoading: isLoadingVersions } = useQuery({ |
| 146 | + queryKey: computed(() => ['versions', { ids: paginatedVersionIds.value.toSorted() }]), |
| 147 | + queryFn: async () => { |
| 148 | + const ids = paginatedVersionIds.value |
| 149 | + if (ids.length === 0) return [] |
146 | 150 | const versions = await labrinth.versions_v3.getVersions(toRaw(ids)) |
147 | 151 | versions.sort((a, b) => ids.indexOf(a.id) - ids.indexOf(b.id)) |
148 | | -
|
149 | | - paginatedVersions.value = paginated.map((version, index) => { |
150 | | - const fullVersion = versions.find((v) => v.id === version.id) |
151 | | - if (fullVersion) |
152 | | - return { |
153 | | - ...version, |
154 | | - duplicate: |
155 | | - !!fullVersion.changelog && |
156 | | - versions.slice(index + 1).some((v) => v.changelog === fullVersion.changelog), |
157 | | - changelog: fullVersion.changelog, |
158 | | - } |
159 | | - else return version |
160 | | - }) |
| 152 | + return versions |
161 | 153 | }, |
162 | | - { immediate: true }, |
163 | | -) |
| 154 | + enabled: computed(() => paginatedVersionIds.value.length > 0), |
| 155 | +}) |
| 156 | +
|
| 157 | +const paginatedVersions = computed(() => { |
| 158 | + if (!fetchedVersions.value) return null |
| 159 | +
|
| 160 | + const page = currentPage.value |
| 161 | + const paginated = filteredVersions.value.slice((page - 1) * 20, page * 20) |
| 162 | + const versions = fetchedVersions.value |
| 163 | +
|
| 164 | + return paginated.map((version, index) => { |
| 165 | + const fullVersion = versions.find((v) => v.id === version.id) |
| 166 | + if (fullVersion) |
| 167 | + return { |
| 168 | + ...version, |
| 169 | + duplicate: |
| 170 | + !!fullVersion.changelog && |
| 171 | + versions.slice(index + 1).some((v) => v.changelog === fullVersion.changelog), |
| 172 | + changelog: fullVersion.changelog, |
| 173 | + } |
| 174 | + else return version |
| 175 | + }) |
| 176 | +}) |
164 | 177 |
|
165 | 178 | function switchPage(page) { |
166 | 179 | currentPage.value = page |
|
0 commit comments