Skip to content

Commit 11e1de9

Browse files
authored
fix: ux changes for sync settings/overrides (#7347)
* fix: ux changes for sync settings/overrides * fix: screenshots page lag + better virtualization pass * fix: gallery issues * feat: further ux changes
1 parent cf60f28 commit 11e1de9

40 files changed

Lines changed: 1748 additions & 1108 deletions

File tree

‎apps/app-frontend/src/App.vue‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ import {
125125
get as getInstance,
126126
get_global_synced_options,
127127
run,
128+
set_global_synced_option,
128129
} from '@/helpers/instance'
129130
import {
130131
get as getCreds,
@@ -151,7 +152,7 @@ import {
151152
} from '@/helpers/utils.js'
152153
import { start_join_server, start_join_singleplayer_world } from '@/helpers/worlds.ts'
153154
import i18n from '@/i18n.config'
154-
import { instanceKeys } from '@/pages/instance/query-options'
155+
import { instanceKeys, screenshotKeys } from '@/pages/instance/query-options'
155156
import {
156157
appUpdateState,
157158
downloadAvailableAppUpdate,
@@ -1116,6 +1117,25 @@ watch(
11161117
settings.hide_nametag_skins_page = behavior.hide_nametag
11171118
settingsChanged = true
11181119
}
1120+
1121+
const showAllScreenshots = behavior.show_all_screenshots
1122+
if (typeof showAllScreenshots === 'boolean') {
1123+
const globalSyncedOptions =
1124+
globalSyncedOptionsQuery.data.value ??
1125+
(await queryClient.fetchQuery({
1126+
queryKey: ['global-synced-options'],
1127+
queryFn: get_global_synced_options,
1128+
}))
1129+
if (globalSyncedOptions.screenshots !== showAllScreenshots) {
1130+
const updatedGlobalSyncedOptions = await set_global_synced_option(
1131+
'screenshots',
1132+
showAllScreenshots,
1133+
)
1134+
queryClient.setQueryData(['global-synced-options'], updatedGlobalSyncedOptions)
1135+
await queryClient.invalidateQueries({ queryKey: screenshotKeys.all })
1136+
}
1137+
}
1138+
11191139
for (const [flag, value] of Object.entries(behaviorFeatureFlags)) {
11201140
if (settings.feature_flags[flag] !== value) {
11211141
settings.feature_flags[flag] = value

‎apps/app-frontend/src/components/ui/screenshots-page/card.vue‎

Lines changed: 103 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@
33
<script setup lang="ts">
44
import { KeyboardSensor, PointerSensor, useDraggable } from '@dnd-kit/vue'
55
import { CheckIcon, ClipboardCopyIcon, EditIcon, MoreHorizontalIcon } from '@modrinth/assets'
6-
import { defineMessages, IconButton, useFormatDateTime, useVIntl } from '@modrinth/ui'
7-
import { computed, onMounted, ref, watch } from 'vue'
6+
import {
7+
defineMessages,
8+
IconButton,
9+
useDebugLogger,
10+
useFormatDateTime,
11+
useVIntl,
12+
} from '@modrinth/ui'
13+
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
814
915
import type { InstanceScreenshot } from '@/helpers/instance'
10-
const loadedScreenshotUrls = new Set<string>()
1116
1217
const props = defineProps<{
1318
screenshot: InstanceScreenshot
@@ -29,9 +34,12 @@ const emit = defineEmits<{
2934
3035
const card = ref<HTMLElement>()
3136
const image = ref<HTMLImageElement>()
32-
const loaded = ref(loadedScreenshotUrls.has(props.screenshot.url))
37+
const imageReady = ref(false)
3338
const { formatMessage } = useVIntl()
39+
const debugImage = useDebugLogger('Screenshots:Card')
3440
const formatTime = useFormatDateTime({ dateStyle: 'medium', timeStyle: 'short' })
41+
let loadStartedAt = performance.now()
42+
let loadGeneration = 0
3543
const messages = defineMessages({
3644
select: { id: 'app.screenshots.select', defaultMessage: 'Select {name}' },
3745
deselect: { id: 'app.screenshots.deselect', defaultMessage: 'Deselect {name}' },
@@ -69,19 +77,86 @@ function activate(event: MouseEvent | KeyboardEvent) {
6977
emit('activate', event)
7078
}
7179
72-
function markImageLoaded() {
73-
loadedScreenshotUrls.add(props.screenshot.url)
74-
loaded.value = true
80+
async function markImageLoaded() {
81+
const loadedImage = image.value
82+
const loadedUrl = props.screenshot.url
83+
const generation = loadGeneration
84+
if (!loadedImage) return
85+
86+
try {
87+
await loadedImage.decode()
88+
} catch {
89+
if (!loadedImage.complete || loadedImage.naturalWidth === 0) return
90+
}
91+
92+
await new Promise<void>((resolve) => {
93+
window.requestAnimationFrame(() => window.requestAnimationFrame(() => resolve()))
94+
})
95+
96+
if (
97+
generation !== loadGeneration ||
98+
image.value !== loadedImage ||
99+
props.screenshot.url !== loadedUrl
100+
) {
101+
return
102+
}
103+
104+
const wasReady = imageReady.value
105+
imageReady.value = true
106+
if (!wasReady) {
107+
debugImage('image loaded', {
108+
id: props.screenshot.id,
109+
fileName: props.screenshot.file_name,
110+
url: props.screenshot.url,
111+
loadDurationMs: performance.now() - loadStartedAt,
112+
naturalWidth: image.value?.naturalWidth,
113+
naturalHeight: image.value?.naturalHeight,
114+
})
115+
}
116+
}
117+
118+
function markImageFailed(event: Event) {
119+
debugImage('image failed', {
120+
id: props.screenshot.id,
121+
fileName: props.screenshot.file_name,
122+
url: props.screenshot.url,
123+
loadDurationMs: performance.now() - loadStartedAt,
124+
event,
125+
})
75126
}
76127
77128
onMounted(() => {
129+
debugImage('mounted', {
130+
id: props.screenshot.id,
131+
fileName: props.screenshot.file_name,
132+
url: props.screenshot.url,
133+
complete: image.value?.complete,
134+
})
78135
if (image.value?.complete && image.value.naturalWidth > 0) markImageLoaded()
79136
})
80137
138+
onBeforeUnmount(() => {
139+
loadGeneration += 1
140+
debugImage('unmounted', {
141+
id: props.screenshot.id,
142+
fileName: props.screenshot.file_name,
143+
url: props.screenshot.url,
144+
loaded: imageReady.value,
145+
})
146+
})
147+
81148
watch(
82149
() => props.screenshot.url,
83-
(url) => {
84-
loaded.value = loadedScreenshotUrls.has(url)
150+
(url, previousUrl) => {
151+
loadGeneration += 1
152+
loadStartedAt = performance.now()
153+
imageReady.value = false
154+
debugImage('source changed', {
155+
id: props.screenshot.id,
156+
fileName: props.screenshot.file_name,
157+
previousUrl,
158+
url,
159+
})
85160
},
86161
)
87162
</script>
@@ -91,7 +166,7 @@ watch(
91166
ref="card"
92167
role="button"
93168
tabindex="0"
94-
class="group relative aspect-video min-w-0 cursor-pointer overflow-hidden rounded-xl border border-solid border-surface-5 bg-surface-2 p-0 text-left shadow-sm transition-[filter] hover:brightness-110 focus-visible:outline focus-visible:outline-2 focus-visible:outline-brand"
169+
class="group relative isolate aspect-video min-w-0 cursor-pointer overflow-hidden rounded-xl border border-solid border-surface-5 bg-surface-2 p-0 text-left shadow-sm transition-[filter] hover:brightness-110 focus-visible:outline focus-visible:outline-2 focus-visible:outline-brand"
95170
:class="{
96171
'!border-contrast brightness-110': selected,
97172
'!border-brand ring-2 ring-brand animate-pulse': highlighted,
@@ -115,7 +190,7 @@ watch(
115190
>
116191
<button
117192
type="button"
118-
class="selection-button group/selection absolute right-0.5 top-0 z-[2] flex size-[50px] cursor-pointer items-start justify-center border-0 bg-transparent p-0 pt-4"
193+
class="selection-button group/selection absolute right-0.5 top-0 z-[3] flex size-[50px] cursor-pointer items-start justify-center border-0 bg-transparent p-0 pt-4"
119194
:aria-label="
120195
formatMessage(selected ? messages.deselect : messages.select, {
121196
name: screenshot.file_name,
@@ -134,19 +209,25 @@ watch(
134209
<CheckIcon v-if="selected" class="relative size-4 invert [stroke-width:3]" />
135210
</span>
136211
</button>
137-
<div v-if="!loaded" class="absolute inset-0 animate-pulse bg-surface-3" />
138212
<img
139213
ref="image"
140214
:src="screenshot.url"
141215
:alt="screenshot.file_name"
142-
loading="lazy"
216+
loading="eager"
217+
decoding="async"
143218
draggable="false"
144-
class="h-full w-full object-cover transition duration-200"
145-
:class="loaded ? 'opacity-100' : 'opacity-0'"
219+
class="screenshot-card-fade absolute inset-0 z-[1] h-full w-full object-cover"
220+
:class="imageReady ? 'opacity-100' : 'opacity-0'"
146221
@load="markImageLoaded"
222+
@error="markImageFailed"
147223
/>
148224
<div
149-
class="absolute inset-x-0 bottom-0 flex items-end justify-between gap-2 bg-gradient-to-t from-surface-1 to-transparent p-3 pt-[120px] text-contrast opacity-0 transition-opacity duration-200 group-hover:opacity-100 group-focus-within:opacity-100"
225+
aria-hidden="true"
226+
class="pointer-events-none absolute inset-0 bg-button-bg"
227+
:class="{ 'animate-pulse': !imageReady }"
228+
/>
229+
<div
230+
class="absolute inset-x-0 bottom-0 z-[2] flex items-end justify-between gap-2 bg-gradient-to-t from-surface-1 to-transparent p-3 pt-[120px] text-contrast opacity-0 transition-opacity duration-200 group-hover:opacity-100 group-focus-within:opacity-100"
150231
>
151232
<div class="min-w-0">
152233
<div v-tooltip="screenshot.file_name" class="truncate text-sm font-semibold">
@@ -193,3 +274,9 @@ watch(
193274
</div>
194275
</article>
195276
</template>
277+
278+
<style scoped>
279+
.screenshot-card-fade {
280+
transition: opacity 350ms ease-in-out;
281+
}
282+
</style>

‎apps/app-frontend/src/components/ui/screenshots-page/group.vue‎

Lines changed: 62 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script setup lang="ts">
22
import { useDroppable } from '@dnd-kit/vue'
3-
import { defineMessages, useVIntl } from '@modrinth/ui'
4-
import { computed, onBeforeUnmount, ref, watch } from 'vue'
3+
import { defineMessages, useDebugLogger, useVIntl } from '@modrinth/ui'
4+
import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue'
55
66
import type { InstanceScreenshot } from '@/helpers/instance'
77
@@ -27,7 +27,6 @@ const props = defineProps<{
2727
highlightedScreenshotId?: string
2828
copiedScreenshotIds: ReadonlySet<string>
2929
forceOpen: boolean
30-
animateEntry: boolean
3130
hideHeader?: boolean
3231
editableTitle?: boolean
3332
startEditingTitle?: boolean
@@ -39,6 +38,7 @@ const props = defineProps<{
3938
const collapsed = defineModel<boolean>('collapsed', { required: true })
4039
const dropTarget = ref<HTMLElement>()
4140
const { formatMessage } = useVIntl()
41+
const debugLayout = useDebugLogger('Screenshots:Group')
4242
const messages = defineMessages({
4343
emptyGroup: {
4444
id: 'app.screenshots.group.empty',
@@ -60,21 +60,50 @@ const visibleGridStyle = computed(() =>
6060
: { transform: `translateY(${props.virtualGridTop}px)` },
6161
)
6262
let unmountGridTimeout: ReturnType<typeof setTimeout> | undefined
63+
let resizeObserver: ResizeObserver | undefined
64+
65+
async function logGeometry(reason: string) {
66+
await nextTick()
67+
const rect = dropTarget.value?.getBoundingClientRect()
68+
debugLayout(reason, {
69+
id: props.id,
70+
title: props.title,
71+
collapsed: collapsed.value,
72+
shouldShowGrid: shouldShowGrid.value,
73+
renderGrid: renderGrid.value,
74+
screenshotCount: props.screenshots.length,
75+
renderedCount: visibleScreenshots.value.length,
76+
firstScreenshotId: visibleScreenshots.value.at(0)?.id,
77+
lastScreenshotId: visibleScreenshots.value.at(-1)?.id,
78+
virtualGridHeight: props.virtualGridHeight,
79+
virtualGridTop: props.virtualGridTop,
80+
actual: rect
81+
? { top: rect.top, left: rect.left, width: rect.width, height: rect.height }
82+
: undefined,
83+
})
84+
}
6385
6486
watch(
6587
() => props.renderedScreenshots ?? props.screenshots,
6688
(screenshots) => {
6789
if (shouldShowGrid.value) visibleScreenshots.value = screenshots
90+
void logGeometry('rendered screenshots changed')
6891
},
6992
)
7093
94+
watch(
95+
() => [props.virtualGridHeight, props.virtualGridTop] as const,
96+
() => void logGeometry('virtual grid geometry changed'),
97+
)
98+
7199
watch(
72100
shouldShowGrid,
73101
(showGrid, previouslyShown) => {
74102
if (unmountGridTimeout) clearTimeout(unmountGridTimeout)
75103
if (showGrid) {
76104
visibleScreenshots.value = props.renderedScreenshots ?? props.screenshots
77105
renderGrid.value = true
106+
void logGeometry('grid shown')
78107
return
79108
}
80109
if (!previouslyShown) {
@@ -83,13 +112,41 @@ watch(
83112
}
84113
unmountGridTimeout = setTimeout(() => {
85114
renderGrid.value = false
115+
void logGeometry('grid unmounted after collapse')
86116
unmountGridTimeout = undefined
87117
}, 300)
88118
},
89119
{ flush: 'post' },
90120
)
91121
122+
onMounted(() => {
123+
debugLayout('mounted', { id: props.id, title: props.title })
124+
void logGeometry('mounted geometry')
125+
if (dropTarget.value) {
126+
resizeObserver = new ResizeObserver(([entry]) => {
127+
const rect = entry?.target.getBoundingClientRect()
128+
debugLayout('actual size changed', {
129+
id: props.id,
130+
title: props.title,
131+
width: rect?.width,
132+
height: rect?.height,
133+
expectedHeight:
134+
(props.hideHeader ? 0 : 40) +
135+
(shouldShowGrid.value ? 10 + (props.virtualGridHeight ?? 0) : 0) +
136+
12,
137+
})
138+
})
139+
resizeObserver.observe(dropTarget.value)
140+
}
141+
})
142+
92143
onBeforeUnmount(() => {
144+
debugLayout('unmounted', {
145+
id: props.id,
146+
title: props.title,
147+
renderedCount: visibleScreenshots.value.length,
148+
})
149+
resizeObserver?.disconnect()
93150
if (unmountGridTimeout) clearTimeout(unmountGridTimeout)
94151
})
95152
@@ -149,19 +206,10 @@ function getSelectionKey(screenshot: InstanceScreenshot) {
149206
<slot name="actions" :start-editing="startEditing" />
150207
</template>
151208
<div v-if="renderGrid" class="relative min-h-[45px] w-full" :style="virtualGridStyle">
152-
<TransitionGroup
153-
tag="div"
209+
<div
154210
class="grid min-h-[45px] w-full grid-cols-1 gap-3 sm:grid-cols-2 2xl:grid-cols-4"
155211
:class="{ 'absolute inset-x-0 top-0': virtualGridHeight !== undefined }"
156212
:style="visibleGridStyle"
157-
move-class="transition-transform duration-200 ease-out motion-reduce:transition-none"
158-
:enter-active-class="
159-
animateEntry
160-
? 'transition-[opacity,transform] duration-[150ms] ease-out motion-reduce:transition-none'
161-
: ''
162-
"
163-
:enter-from-class="animateEntry ? 'opacity-0' : ''"
164-
enter-to-class="opacity-100 scale-100"
165213
>
166214
<ScreenshotCard
167215
v-for="screenshot in visibleScreenshots"
@@ -188,7 +236,7 @@ function getSelectionKey(screenshot: InstanceScreenshot) {
188236
>
189237
{{ formatMessage(messages.emptyGroup) }}
190238
</p>
191-
</TransitionGroup>
239+
</div>
192240
</div>
193241
</ScreenshotSection>
194242
</div>

0 commit comments

Comments
 (0)