Skip to content

Commit 42d85c1

Browse files
committed
feat(ui): fade in the files added to a loaded listing
A file that appears in a directory listing after it has loaded now fades in over the short3 motion token. The rows of the initial load, a new directory, a sort and a removal stay as they were. The fade is an animation on the row itself, so a removed row leaves at once, and the single reduced motion rule of the stylesheet turns it into an instant swap. Signed-off-by: TheMeinerLP <github@themeinerlp.dev>
1 parent b3c6175 commit 42d85c1

6 files changed

Lines changed: 228 additions & 0 deletions

File tree

‎reposilite-frontend/src/components/browser/FileList.test.ts‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,3 +380,42 @@ describe('FileList action slot', () => {
380380
expect(rows.map(row => row.props('actionSlots') as number), 'the xml row offers one action, so each row reserves one').toEqual([1, 1])
381381
})
382382
})
383+
384+
describe('FileList row fade', () => {
385+
const second = { name: 'example-2.0.jar', type: 'FILE' as const, contentLength: 4096 }
386+
const first = { ...jar, type: 'FILE' as const }
387+
const rowOf = (wrapper: VueWrapper<InstanceType<typeof FileList>>, name: string) =>
388+
wrapper.findAllComponents({ name: 'DetailedListEntry' }).find(row => row.text().includes(name))!
389+
390+
it('does not fade the rows of the initial load', () => {
391+
const wrapper = mountList({ files: { list: [jar, second], error: false } })
392+
393+
expect(wrapper.findAll('.motion-row-enter').length, 'no row of the initial load carries the fade').toBe(0)
394+
})
395+
396+
it('fades a row that is added after the load', async () => {
397+
const wrapper = mountList({ files: { list: [jar], error: false } })
398+
399+
await wrapper.setProps({ files: { list: [first, second], error: false } })
400+
401+
expect(rowOf(wrapper, 'example-2.0.jar').classes(), 'the added row carries the fade').toContain('motion-row-enter')
402+
expect(rowOf(wrapper, 'example-1.0.jar').classes(), 'the row that was there stays plain').not.toContain('motion-row-enter')
403+
})
404+
405+
it('does not fade the rows that arrive after a skeleton', async () => {
406+
const wrapper = mountList({ loading: true, files: { list: [], error: false } })
407+
408+
await wrapper.setProps({ loading: false, files: { list: [first, second], error: false } })
409+
410+
expect(wrapper.findAll('.motion-row-enter').length, 'a loaded listing does not fade').toBe(0)
411+
})
412+
413+
it('leaves the other rows plain when a row is removed', async () => {
414+
const wrapper = mountList({ files: { list: [first, second], error: false } })
415+
416+
await wrapper.setProps({ files: { list: [second], error: false } })
417+
418+
expect(wrapper.findAll('.motion-row-enter').length, 'a removal animates nothing').toBe(0)
419+
expect(wrapper.text(), 'the removed row is gone at once').not.toContain('example-1.0.jar')
420+
})
421+
})

‎reposilite-frontend/src/components/browser/FileList.vue‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import MdList from '../md/MdList.vue'
3232
import MdListItem from '../md/MdListItem.vue'
3333
import BrowserIcon from './BrowserIcon.vue'
3434
import { computed, reactive, ref } from 'vue'
35+
import { useRowFade } from '../../composables/useRowFade'
3536
import { useRouter } from 'vue-router'
3637
import type { BrowserFile, BrowserPath, DeleteTarget, Listing, ListingFailure } from './listing'
3738
import type { GlyphName } from './glyphs'
@@ -123,6 +124,12 @@ const displayedEntries = computed<Array<BrowserFile | SkeletonRow>>(() =>
123124
: (props.files.list ?? [])
124125
)
125126
127+
// Only a file that is added after the listing has loaded fades in; a new listing, a removal or a sort does not.
128+
const { isAdded } = useRowFade(
129+
() => (props.files.list ?? []).map(file => file.name),
130+
() => !props.loading
131+
)
132+
126133
const { client, token, hasPermissionTo } = useSession()
127134
const { javadocSuffixes } = usePlaceholders()
128135
@@ -213,6 +220,7 @@ const entryUrl = (file: BrowserFile) =>
213220
:action-slots="widestActions"
214221
:signed-in="signedIn"
215222
:busy="isDownloading(entry)"
223+
:class="{ 'motion-row-enter': isAdded(entry.name) }"
216224
@download="downloadHandler"
217225
/>
218226
</template>
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
* Copyright (c) 2026 OneLiteFeather
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { describe, it, expect } from 'vitest'
18+
import { nextTick, ref } from 'vue'
19+
import { useRowFade } from './useRowFade'
20+
21+
// Every test builds its own keys and its own composable, so no test depends on another.
22+
const setup = (initial: string[], ready = true) => {
23+
const keys = ref(initial)
24+
const isReady = ref(ready)
25+
const { isAdded } = useRowFade(() => keys.value, () => isReady.value)
26+
return { keys, isReady, isAdded }
27+
}
28+
29+
describe('useRowFade', () => {
30+
it('does not mark the rows of the initial load', () => {
31+
const { isAdded } = setup(['a', 'b'])
32+
33+
expect(isAdded('a'), 'a row of the initial load does not fade').toBe(false)
34+
expect(isAdded('b'), 'a row of the initial load does not fade').toBe(false)
35+
})
36+
37+
it('marks a row that is added after the initial load', async () => {
38+
const { keys, isAdded } = setup(['a'])
39+
40+
keys.value = ['a', 'b']
41+
await nextTick()
42+
43+
expect(isAdded('b'), 'the new row fades in').toBe(true)
44+
expect(isAdded('a'), 'the row that was there stays plain').toBe(false)
45+
})
46+
47+
it('does not mark the rows below a removed row', async () => {
48+
const { keys, isAdded } = setup(['a', 'b', 'c'])
49+
50+
keys.value = ['a', 'c']
51+
await nextTick()
52+
53+
expect(isAdded('a'), 'a removal marks nothing').toBe(false)
54+
expect(isAdded('c'), 'a removal marks nothing').toBe(false)
55+
})
56+
57+
it('does not mark rows that only change their order', async () => {
58+
const { keys, isAdded } = setup(['a', 'b'])
59+
60+
keys.value = ['b', 'a']
61+
await nextTick()
62+
63+
expect(isAdded('a'), 'a sort is not an addition').toBe(false)
64+
expect(isAdded('b'), 'a sort is not an addition').toBe(false)
65+
})
66+
67+
it('waits for the load and treats the rows that arrive with it as the initial load', async () => {
68+
const { keys, isReady, isAdded } = setup([], false)
69+
70+
keys.value = ['a', 'b']
71+
isReady.value = true
72+
await nextTick()
73+
74+
expect(isAdded('a'), 'the first loaded rows do not fade').toBe(false)
75+
expect(isAdded('b'), 'the first loaded rows do not fade').toBe(false)
76+
})
77+
78+
it('treats the next load as an initial load again', async () => {
79+
const { keys, isReady, isAdded } = setup(['a'])
80+
81+
isReady.value = false
82+
await nextTick()
83+
keys.value = ['x', 'y']
84+
isReady.value = true
85+
await nextTick()
86+
87+
expect(isAdded('x'), 'the rows of another directory do not fade').toBe(false)
88+
expect(isAdded('y'), 'the rows of another directory do not fade').toBe(false)
89+
})
90+
91+
it('marks a row again when it is removed and added back', async () => {
92+
const { keys, isAdded } = setup(['a', 'b'])
93+
94+
keys.value = ['a']
95+
await nextTick()
96+
keys.value = ['a', 'b']
97+
await nextTick()
98+
99+
expect(isAdded('b'), 'a row that returns is an added row').toBe(true)
100+
})
101+
})
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright (c) 2026 OneLiteFeather
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { watch } from 'vue'
18+
19+
/*
20+
* Tells a list which of its rows were added after the list had loaded, so that only those fade in (the motion-row-enter
21+
* class of src/styles/md3/motion-transitions.css). The rows of the initial load, the rows that only change their order
22+
* and the rows below a removed row are never marked, and a removed row is simply gone. Reduced motion is left to the
23+
* single rule of src/style.css, which makes the fade an instant swap.
24+
*
25+
* keys the keys of the rows as they are shown now
26+
* ready false while the list loads; the rows present when it turns true are the initial load, and a list that goes
27+
* back to false starts over, so the rows of another directory do not fade either
28+
*/
29+
export const useRowFade = (keys: () => readonly string[], ready: () => boolean = () => true) => {
30+
// The rows the list has shown since its load, and the ones among them that were added later. Plain sets on purpose:
31+
// the watcher runs before the render of the same change, so a row reads its mark in the render that draws it.
32+
let known: Set<string> | null = null
33+
let added = new Set<string>()
34+
35+
watch(
36+
() => [ready(), keys()] as const,
37+
([isReady, current]) => {
38+
if (!isReady) {
39+
known = null
40+
added = new Set()
41+
return
42+
}
43+
if (known === null) {
44+
known = new Set(current)
45+
return
46+
}
47+
const present = new Set(current)
48+
for (const key of current) {
49+
if (!known.has(key)) added.add(key)
50+
}
51+
for (const key of added) {
52+
if (!present.has(key)) added.delete(key)
53+
}
54+
known = present
55+
},
56+
{ immediate: true }
57+
)
58+
59+
return { isAdded: (key: string): boolean => added.has(key) }
60+
}

‎reposilite-frontend/src/styles/md3/motion-transitions.css‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,3 +233,17 @@
233233
.motion-fade-leave-to {
234234
opacity: 0;
235235
}
236+
237+
/*
238+
* Row fade: a row that is added to a loaded list fades in over the short3 token. It is an animation on the row itself,
239+
* not a transition group, so a removed row leaves at once and the rows below it move without a transition.
240+
*/
241+
@keyframes motion-row-enter {
242+
from {
243+
opacity: 0;
244+
}
245+
}
246+
247+
.motion-row-enter {
248+
animation: motion-row-enter var(--md-sys-motion-duration-short3) var(--md-sys-motion-easing-standard-decelerate);
249+
}

‎reposilite-frontend/src/styles/md3/motion-transitions.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ describe('named transition classes', () => {
5555
expect(css, 'the scrim starts and ends transparent').toMatch(/\.motion-dialog-scrim-enter-from,\s*\.motion-dialog-scrim-leave-to\s*\{\s*opacity: 0;/)
5656
})
5757

58+
it('fades an added row over the short3 token, with no leave class for a removed row', () => {
59+
expect(css, 'a .motion-row-enter class').toMatch(/\.motion-row-enter\s*\{\s*animation: motion-row-enter var\(--md-sys-motion-duration-short3\)/)
60+
expect(css, 'the animation starts transparent').toMatch(/@keyframes motion-row-enter\s*\{\s*from\s*\{\s*opacity: 0;/)
61+
expect(css, 'a removed row is not animated').not.toContain('motion-row-leave')
62+
})
63+
5864
it('finds a timing declaration in the file', () => {
5965
expect(timingOf(css).length, 'the transition declarations of the patterns').toBeGreaterThan(0)
6066
})

0 commit comments

Comments
 (0)