Skip to content

Commit 3139279

Browse files
committed
Minor rendering improvements
Signed-off-by: Louis Chemineau <[email protected]>
1 parent 0f8a13b commit 3139279

File tree

7 files changed

+54
-42
lines changed

7 files changed

+54
-42
lines changed

src/components/File.vue

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151
@error="onError">
5252
</div>
5353

54-
<!-- image name -->
55-
<p :id="ariaDescription" class="file__hidden-description">{{ item.basename }}</p>
54+
<!-- image description -->
55+
<p :id="ariaDescription" class="file__hidden-description" :class="{show: error}">{{ item.basename }}</p>
5656
</a>
5757

5858
<CheckboxRadioSwitch v-if="allowSelection"
@@ -261,7 +261,9 @@ export default {
261261
// Make the checkbox background round on hover.
262262
::v-deep .checkbox-radio-switch__label {
263263
padding: 10px;
264+
box-sizing: border-box;
264265
266+
// Add a background to the checkbox so we do not see the image through it.
265267
&::after {
266268
content: '';
267269
background: var(--color-primary-light);
@@ -305,6 +307,7 @@ export default {
305307
height: 100%;
306308
object-fit: cover;
307309
position: absolute;
310+
color: transparent; /// Hide alt text when loading.
308311
}
309312
310313
.loading-overlay {
@@ -330,6 +333,12 @@ export default {
330333
width: 1px;
331334
height: 1px;
332335
overflow: hidden;
336+
337+
&.show {
338+
position: initial;
339+
width: fit-content;
340+
height: fit-content;
341+
}
333342
}
334343
}
335344
}

src/components/FilesListViewer.vue

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@
4242
:file="item"
4343
:visibility="row.visibility" />
4444
</TiledRows>
45+
<template v-if="loading" #loader>
46+
<Loader class="files-list-viewer__loader" />
47+
</template>
4548
</VirtualScrolling>
4649
</TiledLayout>
47-
48-
<Loader v-if="loading" />
4950
</div>
5051
</template>
5152
<script>
@@ -81,7 +82,7 @@ export default {
8182
type: Object,
8283
default: undefined,
8384
},
84-
// A list of ordered sections.
85+
// The list of sorted sections.
8586
sections: {
8687
type: Array,
8788
default: undefined,
@@ -202,6 +203,7 @@ export default {
202203
<style lang="scss" scoped>
203204
.files-list-viewer {
204205
height: 100%;
206+
position: relative;
205207
206208
::v-deep .empty-content__icon {
207209
width: 200px;
@@ -212,5 +214,9 @@ export default {
212214
height: 200px;
213215
}
214216
}
217+
218+
&__loader {
219+
margin: 50px 0;
220+
}
215221
}
216222
</style>

src/components/FilesPicker.vue

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,18 @@
2727
:key="month"
2828
class="file-picker__navigation__month"
2929
:class="{selected: targetMonth === month}"
30-
@click="scrollTo(month)">
30+
@click="targetMonth = month">
3131
{{ month | dateMonthAndYear }}
3232
</div>
3333
</div>
3434
<FilesListViewer class="file-picker__file-list"
35-
:file-ids-by-section="filesListByMonth"
35+
:file-ids-by-section="fileIdsByMonth"
3636
:sections="monthsList"
37-
:loading="loadingFiles && fetchedFileIds.length !== 0"
37+
:loading="loadingFiles"
3838
:base-height="100"
3939
:section-header-height="50"
4040
:scroll-to-section="targetMonth"
41-
@need-content="fetchedFileIds">
41+
@need-content="fetchFiles">
4242
<template slot-scope="{file, height, visibility}">
4343
<h3 v-if="file.sectionHeader"
4444
:id="`file-picker-section-header-${file.id}`"
@@ -84,6 +84,7 @@ import FetchFilesMixin from '../mixins/FetchFilesMixin.js'
8484
import FilesSelectionMixin from '../mixins/FilesSelectionMixin.js'
8585
import FilesListViewer from './FilesListViewer.vue'
8686
import File from './File.vue'
87+
import FilesByMonthMixin from '../mixins/FilesByMonthMixin.js'
8788
8889
export default {
8990
name: 'FilesPicker',
@@ -107,6 +108,7 @@ export default {
107108
108109
mixins: [
109110
FetchFilesMixin,
111+
FilesByMonthMixin,
110112
FilesSelectionMixin,
111113
],
112114
@@ -121,34 +123,6 @@ export default {
121123
}
122124
},
123125
124-
computed: {
125-
/**
126-
* @return {string[]}
127-
*/
128-
filesListByMonth() {
129-
const filesByMonth = {}
130-
for (const fileId of Object.keys(this.files)) {
131-
const file = this.files[fileId]
132-
filesByMonth[file.month] = filesByMonth[file.month] ?? []
133-
filesByMonth[file.month].push(file.fileid)
134-
}
135-
136-
// Sort files in sections.
137-
Object.keys(filesByMonth).forEach(month => filesByMonth[month].sort(this.sortFilesByTimestamp))
138-
139-
return filesByMonth
140-
},
141-
142-
/**
143-
* @return {string[]}
144-
*/
145-
monthsList() {
146-
return Object
147-
.keys(this.filesListByMonth)
148-
.sort((month1, month2) => month1 > month2 ? -1 : 1)
149-
},
150-
},
151-
152126
watch: {
153127
monthsList(value) {
154128
if (this.targetMonth === null) {
@@ -182,6 +156,7 @@ export default {
182156
183157
&__content {
184158
display: flex;
159+
align-items: flex-start;
185160
flex-grow: 1;
186161
height: 500px;
187162
}
@@ -191,6 +166,7 @@ export default {
191166
overflow: scroll;
192167
margin-right: 8px;
193168
padding-right: 8px;
169+
height: 100%;
194170
195171
&__month {
196172
font-weight: bold;
@@ -213,6 +189,7 @@ export default {
213189
&__file-list {
214190
flex-grow: 1;
215191
min-width: 0;
192+
height: 100%;
216193
217194
.section-header {
218195
font-weight: bold;

src/components/TiledLayout.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<div ref="tiledLayoutContainer"
2424
class="tiled-container">
2525
<!-- Slot to allow changing the rows before passing them to TiledRows -->
26-
<!-- Useful for partially rendering rows like in VirtualScrolling -->
26+
<!-- Useful for partially rendering rows like with VirtualScrolling -->
2727
<slot :rows="rows">
2828
<!-- Default rendering -->
2929
<TiledRows :rows="rows" />
@@ -32,6 +32,7 @@
3232
</template>
3333

3434
<script>
35+
import logger from '../services/logger.js'
3536
import { splitItemsInRows } from '../services/TiledLayout.js'
3637
import TiledRows from './TiledRows.vue'
3738
@@ -64,6 +65,8 @@ export default {
6465
computed: {
6566
/** @return {import('../services/TiledLayout.js').TiledRow[]} */
6667
rows() {
68+
logger.debug('[TiledLayout] Computing rows', this.items)
69+
6770
return splitItemsInRows(this.items, this.containerWidth, this.baseHeight)
6871
},
6972
},

src/components/VirtualScrolling.vue

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,22 @@
2525
class="vs-rows-container"
2626
:style="rowsContainerStyle">
2727
<slot :rendered-rows="visibleRows" />
28+
<slot name="loader" />
2829
</div>
2930
</div>
3031
<div v-else
3132
ref="rowsContainer"
3233
class="vs-rows-container"
3334
:style="rowsContainerStyle">
3435
<slot :rendered-rows="visibleRows" />
36+
<slot name="loader" />
3537
</div>
3638
</template>
3739

3840
<script>
41+
import { debounce } from 'debounce'
42+
43+
import logger from '../services/logger.js'
3944
/**
4045
* @typedef {object} Row
4146
* @property {number} height - The height of the row.
@@ -72,7 +77,7 @@ export default {
7277
},
7378
willBeVisibleWindowRatio: {
7479
type: Number,
75-
default: 4,
80+
default: 5,
7681
},
7782
visibleWindowRatio: {
7883
type: Number,
@@ -104,6 +109,8 @@ export default {
104109
* @return {VisibleRow[]}
105110
*/
106111
visibleRows() {
112+
logger.debug('[VirtualScrolling] Computing visible rows', this.rows)
113+
107114
// Optimisation: get those computed properties once to not go through vue's internal every time we need them.
108115
const scrollPosition = this.scrollPosition
109116
const containerHeight = this.containerHeight
@@ -205,6 +212,7 @@ export default {
205212
* @return {HTMLElement}
206213
*/
207214
container() {
215+
logger.debug('[VirtualScrolling] Computing container')
208216
if (this.containerElement !== null) {
209217
return this.containerElement
210218
} else if (this.useWindow) {
@@ -277,13 +285,14 @@ export default {
277285
},
278286
279287
methods: {
280-
updateScrollPosition() {
288+
updateScrollPosition: debounce(function() {
281289
if (this.useWindow) {
282290
this.scrollPosition = this.container.scrollY
283291
} else {
284292
this.scrollPosition = this.container.scrollTop
285293
}
286-
},
294+
}, 200),
295+
287296
updateContainerSize() {
288297
this.containerHeight = window.innerHeight
289298
},
@@ -296,4 +305,8 @@ export default {
296305
overflow-y: scroll;
297306
height: 100%;
298307
}
308+
309+
.vs-rows-container {
310+
box-sizing: border-box;
311+
}
299312
</style>

src/mixins/FetchAlbumsMixin.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import { mapGetters } from 'vuex'
2424

25+
import logger from '../services/logger.js'
2526
import getAlbums from '../services/Albums.js'
2627
import cancelableRequest from '../utils/CancelableRequest.js'
2728

@@ -65,6 +66,7 @@ export default {
6566

6667
const albums = await request()
6768
this.$store.dispatch('addAlbums', { albums })
69+
logger.debug(`Fetched ${albums.length} new files: `, albums)
6870
} catch (error) {
6971
if (error.response && error.response.status) {
7072
if (error.response.status === 404) {

src/mixins/FetchFilesMixin.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,13 @@ export default {
100100
this.doneFetchingFiles = true
101101
}
102102

103-
const fileIds = fetchedFiles.map(file => file.fileid).filter(fileId => !this.fetchedFileIds.includes(fileId)) // Filter to prevent duplicate fileId.
103+
const fileIds = fetchedFiles.map(file => file.fileid).filter(fileId => !this.fetchedFileIds.includes(fileId)) // Filter to prevent duplicate fileIds.
104104
this.fetchedFileIds.push(...fileIds)
105105

106106
this.$store.dispatch('appendFiles', fetchedFiles)
107107

108+
logger.debug(`Fetched ${fileIds.length} new files: `, fileIds)
109+
108110
return fileIds
109111
} catch (error) {
110112
if (error.response && error.response.status) {

0 commit comments

Comments
 (0)