Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
29a7f7f
feat(files_trashbin): migrate to vue
skjnldsv Jan 13, 2023
03c3277
feat(files): switch to pinia
skjnldsv Feb 4, 2023
638b3df
perf(files): update files store by chunks
skjnldsv Feb 4, 2023
2ff1c00
fix(files_trashbin): previews crop support
skjnldsv Feb 5, 2023
b761039
perf(files): fetch previews faster and cache properly
skjnldsv Mar 17, 2023
10010fc
feat(files): sorting
skjnldsv Mar 21, 2023
f330813
feat(files): custom columns
skjnldsv Mar 22, 2023
0db210a
chore(deps): cleanup unused deps and audit
skjnldsv Mar 22, 2023
0b4da61
feat(files): actions api
skjnldsv Mar 23, 2023
3c3050c
feat(files): implement sorting per view
skjnldsv Mar 24, 2023
0e764f7
fix(files): fix custom render components reactivity
skjnldsv Mar 24, 2023
0f717d4
feat(accessibility): add files table caption and summary
skjnldsv Mar 24, 2023
e85eb4c
fix(files): selection and render performance
skjnldsv Mar 24, 2023
f28944e
feat(files): propagate restore and delete events
skjnldsv Mar 25, 2023
bda286c
perf(files): less verbose
skjnldsv Mar 25, 2023
6358e97
fix(files): inline action styling
skjnldsv Mar 25, 2023
2b25199
fix(files): accessibility tab into recycled invisible files rows
skjnldsv Mar 25, 2023
7215a9a
fix(files): breadcrumbs accessibility title
skjnldsv Mar 28, 2023
4942747
fix(files): use inline NcActions
skjnldsv Mar 28, 2023
60b74e3
feat(files): batch actions
skjnldsv Mar 28, 2023
044e824
chore(deps): update lockfile
skjnldsv Mar 28, 2023
c7c9ee1
feat(files): move userconfig to dedicated store and fix crop previews
skjnldsv Mar 31, 2023
a66cae0
fix(deps): update webdav 5 usage
skjnldsv Mar 31, 2023
014a57e
fix: improved preview handling
skjnldsv Apr 4, 2023
bdbe477
feat(files): add FileAction service
skjnldsv Apr 4, 2023
904348b
chore(npm): build assets
skjnldsv Apr 4, 2023
1361182
chore(eslint): clean and fix
skjnldsv Apr 4, 2023
f060e5a
fix(tests): update jsunit tests after dep and files update
skjnldsv Apr 4, 2023
d432e0c
fix(cypress): component testing with pinia
skjnldsv Apr 5, 2023
8298bb4
fix:(files-checker): add cypress.d.ts and custom.d.ts
skjnldsv Apr 5, 2023
ea3e77d
fix(files): better wording and catch single action run
skjnldsv Apr 5, 2023
5b3900e
fix(tests): acceptance
skjnldsv Apr 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: improved preview handling
Signed-off-by: John Molakvoæ <[email protected]>
  • Loading branch information
skjnldsv committed Apr 6, 2023
commit 014a57e54174ce9a8f2c55beafad2dd8d1c6a9d0
1 change: 1 addition & 0 deletions apps/files/src/components/BreadCrumbs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export default Vue.extend({
computed: {
dirs() {
const cumulativePath = (acc) => (value) => (acc += `${value}/`)
// Generate a cumulative path for each path segment: ['/', '/foo', '/foo/bar', ...] etc
const paths = this.path.split('/').filter(Boolean).map(cumulativePath('/'))
// Strip away trailing slash
return ['/', ...paths.map(path => path.replace(/^(.+)\/$/, '$1'))]
Expand Down
102 changes: 52 additions & 50 deletions apps/files/src/components/FileEntry.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

<!-- Link to file -->
<td class="files-list__row-name">
<a v-bind="linkTo">
<a ref="name" v-bind="linkTo">
<!-- Icon or preview -->
<span class="files-list__row-icon">
<FolderIcon v-if="source.type === 'folder'" />
Expand Down Expand Up @@ -61,7 +61,8 @@
<!-- TODO: implement CustomElementRender -->

<!-- Menu actions -->
<NcActions ref="actionsMenu"
<NcActions v-if="active"
ref="actionsMenu"
:force-title="true"
:inline="enabledInlineActions.length">
<NcActionButton v-for="action in enabledMenuActions"
Expand Down Expand Up @@ -99,10 +100,9 @@

<script lang='ts'>
import { debounce } from 'debounce'
import { Folder, File, getFileActions, formatFileSize } from '@nextcloud/files'
import { Folder, File, formatFileSize } from '@nextcloud/files'
import { Fragment } from 'vue-fragment'
import { join } from 'path'
import { mapState } from 'pinia'
import { showError } from '@nextcloud/dialogs'
import { translate } from '@nextcloud/l10n'
import FileIcon from 'vue-material-design-icons/File.vue'
Expand All @@ -113,17 +113,15 @@ import NcCheckboxRadioSwitch from '@nextcloud/vue/dist/Components/NcCheckboxRadi
import NcLoadingIcon from '@nextcloud/vue/dist/Components/NcLoadingIcon.js'
import Vue from 'vue'

import { isCachedPreview } from '../services/PreviewService'
import { getFileActions } from '../services/FileAction'
import { useFilesStore } from '../store/files'
import { UserConfig } from '../types'
import { useSelectionStore } from '../store/selection'
import { useUserConfigStore } from '../store/userconfig'
import CustomElementRender from './CustomElementRender.vue'
import CustomSvgIconRender from './CustomSvgIconRender.vue'
import logger from '../logger.js'
import { UserConfig } from '../types'


// The preview service worker cache name (see webpack config)
const SWCacheName = 'previews'

// The registered actions list
const actions = getFileActions()
Expand Down Expand Up @@ -156,6 +154,10 @@ export default Vue.extend({
type: Object,
required: true,
},
index: {
type: Number,
required: true,
},
},

setup() {
Expand Down Expand Up @@ -314,6 +316,7 @@ export default Vue.extend({
// Restore default tabindex
this.$el.parentNode.style.display = ''
},

/**
* When the source changes, reset the preview
* and fetch the new one.
Expand All @@ -335,11 +338,7 @@ export default Vue.extend({
this.fetchAndApplyPreview()
}, 150, false)

// ⚠ Init img on mount and
// not when the module is imported to
// avoid sharing between recycled components
this.img = null

// Fetch the preview on init
this.debounceIfNotCached()
},

Expand All @@ -354,7 +353,7 @@ export default Vue.extend({
}

// Check if we already have this preview cached
const isCached = await this.isCachedPreview(this.previewUrl)
const isCached = await isCachedPreview(this.previewUrl)
if (isCached) {
this.backgroundImage = `url(${this.previewUrl})`
this.backgroundFailed = false
Expand All @@ -372,19 +371,37 @@ export default Vue.extend({
}

// If any image is being processed, reset it
if (this.img) {
if (this.previewPromise) {
this.clearImg()
}

this.img = new Image()
this.img.fetchpriority = this.active ? 'high' : 'auto'
this.img.onload = () => {
this.backgroundImage = `url(${this.previewUrl})`
}
this.img.onerror = () => {
this.backgroundFailed = true
}
this.img.src = this.previewUrl
// Ensure max 5 previews are being fetched at the same time
const controller = new AbortController()

// Store the promise to be able to cancel it
this.previewPromise = new CancelablePromise((resolve, reject, onCancel) => {
const img = new Image()
// If active, load the preview with higher priority
img.fetchpriority = this.active ? 'high' : 'auto'
img.onload = () => {
this.backgroundImage = `url(${this.previewUrl})`
this.backgroundFailed = false
resolve(img)
}
img.onerror = () => {
this.backgroundFailed = true
reject(img)
}
img.src = this.previewUrl

// Image loading has been canceled
onCancel(() => {
img.onerror = null
img.onload = null
img.src = ''
controller.abort()
})
})
},

resetState() {
Expand All @@ -402,23 +419,10 @@ export default Vue.extend({
this.backgroundImage = ''
this.backgroundFailed = false

if (this.img) {
// Do not fail on cancel
this.img.onerror = null
this.img.src = ''
if (this.previewPromise) {
this.previewPromise.cancel()
this.previewPromise = null
}

this.img = null
},

isCachedPreview(previewUrl) {
return caches.open(SWCacheName)
.then(function(cache) {
return cache.match(previewUrl)
.then(function(response) {
return !!response // or `return response ? true : false`, or similar.
})
})
},

hashCode(str) {
Expand Down Expand Up @@ -464,23 +468,21 @@ tr {

/* Preview not loaded animation effect */
.files-list__row-icon-preview:not([style*='background']) {
background: linear-gradient(110deg, var(--color-loading-dark) 0%, var(--color-loading-dark) 25%, var(--color-loading-light) 50%, var(--color-loading-dark) 75%, var(--color-loading-dark) 100%);
background-size: 400%;
animation: preview-gradient-slide 1.2s ease-in-out infinite;
background: var(--color-loading-dark);
// animation: preview-gradient-fade 1.2s ease-in-out infinite;
}
</style>

<style>
@keyframes preview-gradient-slide {
/* @keyframes preview-gradient-fade {
0% {
background-position: 100% 0%;
opacity: 1;
}
50% {
background-position: 0% 0%;
opacity: 0.5;
}
/* adds a small delay to the animation */
100% {
background-position: 0% 0%;
opacity: 1;
}
}
} */
</style>
16 changes: 16 additions & 0 deletions apps/files/src/components/FilesListHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ export default Vue.extend({
FilesListHeaderActions,
},

provide() {
return {
toggleSortBy: this.toggleSortBy,
}
},

props: {
isSizeAvailable: {
type: Boolean,
Expand Down Expand Up @@ -186,6 +192,16 @@ export default Vue.extend({
}
},

toggleSortBy(key) {
// If we're already sorting by this key, flip the direction
if (this.sortingMode === key) {
this.sortingStore.toggleSortingDirection(this.currentView.id)
return
}
// else sort ASC by this new key
this.sortingStore.setSortingBy(key, this.currentView.id)
},

t: translate,
},
})
Expand Down
12 changes: 2 additions & 10 deletions apps/files/src/components/FilesListHeaderButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export default Vue.extend({
NcButton,
},

inject: ['toggleSortBy'],

props: {
name: {
type: String,
Expand Down Expand Up @@ -97,16 +99,6 @@ export default Vue.extend({
})
},

toggleSortBy(key) {
// If we're already sorting by this key, flip the direction
if (this.sortingMode === key) {
this.sortingStore.toggleSortingDirection(this.currentView.id)
return
}
// else sort ASC by this new key
this.sortingStore.setSortingBy(key, this.currentView.id)
},

t: translate,
},
})
Expand Down
Loading