using existing store state and component

This commit is contained in:
Weidi Deng 2020-12-23 15:04:44 +08:00
parent 57e11a5162
commit 5087c6c579
13 changed files with 104 additions and 245 deletions

View File

@ -58,8 +58,7 @@ export async function put (url, content = '') {
} }
export function download (format, ...files) { export function download (format, ...files) {
const isSharing = store.getters['isSharing'] let url = store.getters['isSharing'] ? `${baseURL}/api/public/dl/${store.state.hash}` : `${baseURL}/api/raw`
let url = isSharing ? `${baseURL}/api/public/dl/${store.state.shared.hash}` : `${baseURL}/api/raw`
if (files.length === 1) { if (files.length === 1) {
url += removePrefix(files[0]) + '?' url += removePrefix(files[0]) + '?'
@ -79,9 +78,7 @@ export function download (format, ...files) {
url += `algo=${format}&` url += `algo=${format}&`
} }
if (!isSharing) { url += `auth=${store.state.jwt}`
url += `auth=${store.state.jwt}`
}
window.open(url) window.open(url)
} }

View File

@ -37,7 +37,7 @@ export function removePrefix (url) {
if (url.startsWith('/files')) { if (url.startsWith('/files')) {
url = url.slice(6) url = url.slice(6)
} else if (store.getters['isSharing']) { } else if (store.getters['isSharing']) {
url = url.slice(7 + store.state.shared.hash.length) url = url.slice(7 + store.state.hash.length)
} }
if (url === '') url = '/' if (url === '') url = '/'

View File

@ -8,8 +8,8 @@
<search v-if="isLogged"></search> <search v-if="isLogged"></search>
</div> </div>
<div> <div>
<template v-if="isLogged"> <template v-if="isLogged || isSharing">
<button @click="openSearch" :aria-label="$t('buttons.search')" :title="$t('buttons.search')" class="search-button action"> <button v-show="!isSharing" @click="openSearch" :aria-label="$t('buttons.search')" :title="$t('buttons.search')" class="search-button action">
<i class="material-icons">search</i> <i class="material-icons">search</i>
</button> </button>
@ -18,7 +18,7 @@
</button> </button>
<!-- Menu that shows on listing AND mobile when there are files selected --> <!-- Menu that shows on listing AND mobile when there are files selected -->
<div id="file-selection" v-if="isMobile && isListing"> <div id="file-selection" v-if="isMobile && isListing && !isSharing">
<span v-if="selectedCount > 0">{{ selectedCount }} selected</span> <span v-if="selectedCount > 0">{{ selectedCount }} selected</span>
<share-button v-show="showShareButton"></share-button> <share-button v-show="showShareButton"></share-button>
<rename-button v-show="showRenameButton"></rename-button> <rename-button v-show="showRenameButton"></rename-button>
@ -28,7 +28,7 @@
</div> </div>
<!-- This buttons are shown on a dropdown on mobile phones --> <!-- This buttons are shown on a dropdown on mobile phones -->
<div class="dropdown" :class="{ active: showMore }"> <div id="dropdown" :class="{ active: showMore }">
<div v-if="!isListing || !isMobile"> <div v-if="!isListing || !isMobile">
<share-button v-show="showShareButton"></share-button> <share-button v-show="showShareButton"></share-button>
<rename-button v-show="showRenameButton"></rename-button> <rename-button v-show="showRenameButton"></rename-button>
@ -43,18 +43,7 @@
<upload-button v-show="showUpload"></upload-button> <upload-button v-show="showUpload"></upload-button>
<info-button v-show="isFiles"></info-button> <info-button v-show="isFiles"></info-button>
<button v-show="isListing" @click="toggleMultipleSelection" :aria-label="$t('buttons.selectMultiple')" :title="$t('buttons.selectMultiple')" class="action" > <button v-show="isListing || (isSharing && req.isDir)" @click="toggleMultipleSelection" :aria-label="$t('buttons.selectMultiple')" :title="$t('buttons.selectMultiple')" class="action" >
<i class="material-icons">check_circle</i>
<span>{{ $t('buttons.select') }}</span>
</button>
</div>
</template>
<template v-if="isSharing">
<!-- This buttons are shown on a dropdown on mobile phones -->
<div class="dropdown" :class="{ active: showMore }">
<download-button v-if="sharedSelectedCount > 0"></download-button>
<button @click="toggleSharedMultipleSelection" :aria-label="$t('buttons.selectMultiple')" :title="$t('buttons.selectMultiple')" class="action" >
<i class="material-icons">check_circle</i> <i class="material-icons">check_circle</i>
<span>{{ $t('buttons.select') }}</span> <span>{{ $t('buttons.select') }}</span>
</button> </button>
@ -122,16 +111,14 @@ export default {
'isPreview', 'isPreview',
'isListing', 'isListing',
'isLogged', 'isLogged',
'isSharing', 'isSharing'
'sharedSelectedCount'
]), ]),
...mapState([ ...mapState([
'req', 'req',
'user', 'user',
'loading', 'loading',
'reload', 'reload',
'multiple', 'multiple'
'shared'
]), ]),
logoURL: () => logoURL, logoURL: () => logoURL,
isExecEnabled: () => enableExec, isExecEnabled: () => enableExec,
@ -142,7 +129,7 @@ export default {
return this.isListing && this.user.perm.create return this.isListing && this.user.perm.create
}, },
showDownloadButton () { showDownloadButton () {
return this.isFiles && this.user.perm.download return (this.isFiles && this.user.perm.download) || (this.isSharing && this.selectedCount > 0)
}, },
showDeleteButton () { showDeleteButton () {
return this.isFiles && (this.isListing return this.isFiles && (this.isListing
@ -190,10 +177,6 @@ export default {
this.$store.commit('multiple', !this.multiple) this.$store.commit('multiple', !this.multiple)
this.resetPrompts() this.resetPrompts()
}, },
toggleSharedMultipleSelection () {
this.$store.commit('sharedMultiple', !this.shared.multiple)
this.resetPrompts()
},
resetPrompts () { resetPrompts () {
this.$store.commit('closeHovers') this.$store.commit('closeHovers')
} }

View File

@ -3,7 +3,6 @@
<i class="material-icons">file_download</i> <i class="material-icons">file_download</i>
<span>{{ $t('buttons.download') }}</span> <span>{{ $t('buttons.download') }}</span>
<span v-if="selectedCount > 0" class="counter">{{ selectedCount }}</span> <span v-if="selectedCount > 0" class="counter">{{ selectedCount }}</span>
<span v-else-if="isSharing && sharedSelectedCount > 0" class="counter">{{ sharedSelectedCount }}</span>
</button> </button>
</template> </template>
@ -14,8 +13,8 @@ import { files as api } from '@/api'
export default { export default {
name: 'download-button', name: 'download-button',
computed: { computed: {
...mapState(['req', 'selected', 'shared']), ...mapState(['req', 'selected']),
...mapGetters(['isListing', 'selectedCount', 'isSharing', 'sharedSelectedCount']) ...mapGetters(['isListing', 'selectedCount', 'isSharing'])
}, },
methods: { methods: {
download: function () { download: function () {
@ -29,11 +28,6 @@ export default {
return return
} }
if (this.sharedSelectedCount === 1 && !this.shared.req.items[this.shared.selected[0]].isDir) {
api.download(null, this.shared.req.items[this.shared.selected[0]].url)
return
}
this.$store.commit('showHover', 'download') this.$store.commit('showHover', 'download')
} }
} }

View File

@ -48,7 +48,7 @@ export default {
props: ['name', 'isDir', 'url', 'type', 'size', 'modified', 'index'], props: ['name', 'isDir', 'url', 'type', 'size', 'modified', 'index'],
computed: { computed: {
...mapState(['user', 'selected', 'req', 'user', 'jwt']), ...mapState(['user', 'selected', 'req', 'user', 'jwt']),
...mapGetters(['selectedCount']), ...mapGetters(['selectedCount', 'isSharing']),
isSelected () { isSelected () {
return (this.selected.indexOf(this.index) !== -1) return (this.selected.indexOf(this.index) !== -1)
}, },
@ -63,7 +63,7 @@ export default {
return this.user.perm.rename return this.user.perm.rename
}, },
canDrop () { canDrop () {
if (!this.isDir) return false if (!this.isDir || this.isSharing) return false
for (let i of this.selected) { for (let i of this.selected) {
if (this.req.items[i].url === this.url) { if (this.req.items[i].url === this.url) {

View File

@ -1,112 +0,0 @@
<template>
<div class="item"
role="button"
tabindex="0"
@click="click"
@dblclick="dblclick"
@touchstart="touchstart"
:data-dir="isDir"
:aria-label="name"
:aria-selected="isSelected">
<div>
<i class="material-icons">{{ icon }}</i>
</div>
<div>
<p class="name">{{ name }}</p>
<p v-if="isDir" class="size" data-order="-1">&mdash;</p>
<p v-else class="size" :data-order="humanSize()">{{ humanSize() }}</p>
<p class="modified">
<time :datetime="modified">{{ humanTime() }}</time>
</p>
</div>
</div>
</template>
<script>
import { mapMutations, mapGetters, mapState } from 'vuex'
import filesize from 'filesize'
import moment from 'moment'
export default {
name: 'sharedItem',
data: function () {
return {
touches: 0
}
},
props: ['name', 'isDir', 'url', 'type', 'size', 'modified', 'index'],
computed: {
...mapState(['shared']),
...mapGetters(['sharedSelectedCount']),
isSelected () {
return (this.shared.selected.indexOf(this.index) !== -1)
},
icon () {
if (this.isDir) return 'folder'
if (this.type === 'image') return 'insert_photo'
if (this.type === 'audio') return 'volume_up'
if (this.type === 'video') return 'movie'
return 'insert_drive_file'
}
},
methods: {
...mapMutations(['addSharedSelected', 'removeSharedSelected', 'resetSharedSelected']),
humanSize: function () {
return filesize(this.size)
},
humanTime: function () {
return moment(this.modified).fromNow()
},
click: function (event) {
if (this.sharedSelectedCount !== 0) event.preventDefault()
if (this.$store.state.shared.selected.indexOf(this.index) !== -1) {
this.removeSharedSelected(this.index)
return
}
if (event.shiftKey && this.shared.selected.length > 0) {
let fi = 0
let la = 0
if (this.index > this.shared.selected[0]) {
fi = this.shared.selected[0] + 1
la = this.index
} else {
fi = this.index
la = this.shared.selected[0] - 1
}
for (; fi <= la; fi++) {
if (this.$store.state.shared.selected.indexOf(fi) == -1) {
this.addSharedSelected(fi)
}
}
return
}
if (!event.ctrlKey && !event.metaKey && !this.$store.state.shared.multiple) this.resetSharedSelected()
this.addSharedSelected(this.index)
},
dblclick: function () {
this.open()
},
touchstart () {
setTimeout(() => {
this.touches = 0
}, 300)
this.touches++
if (this.touches > 1) {
this.open()
}
},
open: function () {
this.$router.push({path: this.url})
}
}
}
</script>

View File

@ -25,20 +25,12 @@ import { files as api } from '@/api'
export default { export default {
name: 'download', name: 'download',
computed: { computed: {
...mapState(['selected', 'req', 'shared']), ...mapState(['selected', 'req']),
...mapGetters(['selectedCount', 'isSharing' ,'sharedSelectedCount']) ...mapGetters(['selectedCount'])
}, },
methods: { methods: {
download: function (format) { download: function (format) {
if (this.isSharing) { if (this.selectedCount === 0) {
let files = []
for (let i of this.shared.selected) {
files.push(this.shared.req.items[i].url)
}
api.download(format, ...files)
} else if (this.selectedCount === 0) {
api.download(format, this.$route.path) api.download(format, this.$route.path)
} else { } else {
let files = [] let files = []

View File

@ -54,12 +54,6 @@
border-right: 0; border-right: 0;
border-bottom: 0; border-bottom: 0;
border-top: 1px solid rgba(0, 0, 0, 0.1); border-top: 1px solid rgba(0, 0, 0, 0.1);
-webkit-user-select:none;
-khtml-user-select:none;
-moz-user-select:none;
-ms-user-select:none;
-o-user-select:none;
user-select:none;
} }
.share__box__items #listing.list .item .name { .share__box__items #listing.list .item .name {

View File

@ -28,7 +28,7 @@
height: 100%; height: 100%;
background-color: rgba(0, 0, 0, 0.1); background-color: rgba(0, 0, 0, 0.1);
} }
.dropdown { #dropdown {
position: fixed; position: fixed;
top: 1em; top: 1em;
right: 1em; right: 1em;
@ -40,23 +40,23 @@
transform-origin: top right; transform-origin: top right;
z-index: 99999; z-index: 99999;
} }
.dropdown > div { #dropdown > div {
display: block; display: block;
} }
.dropdown.active { #dropdown.active {
transform: scale(1); transform: scale(1);
} }
.dropdown .action { #dropdown .action {
display: flex; display: flex;
align-items: center; align-items: center;
border-radius: 0; border-radius: 0;
width: 100%; width: 100%;
} }
.dropdown .action span:not(.counter) { #dropdown .action span:not(.counter) {
display: inline-block; display: inline-block;
padding: .4em; padding: .4em;
} }
.dropdown .counter { #dropdown .counter {
left: 2.25em; left: 2.25em;
} }
#file-selection { #file-selection {

View File

@ -4,7 +4,7 @@ const getters = {
isListing: (state, getters) => getters.isFiles && state.req.isDir, isListing: (state, getters) => getters.isFiles && state.req.isDir,
isEditor: (state, getters) => getters.isFiles && (state.req.type === 'text' || state.req.type === 'textImmutable'), isEditor: (state, getters) => getters.isFiles && (state.req.type === 'text' || state.req.type === 'textImmutable'),
isPreview: state => state.previewMode, isPreview: state => state.previewMode,
isSharing: state => state.shared.loaded && state.route.name === 'Share', isSharing: state => !state.loading && state.route.name === 'Share',
selectedCount: state => state.selected.length, selectedCount: state => state.selected.length,
progress : state => { progress : state => {
if (state.upload.progress.length == 0) { if (state.upload.progress.length == 0) {
@ -13,8 +13,7 @@ const getters = {
let sum = state.upload.progress.reduce((acc, val) => acc + val) let sum = state.upload.progress.reduce((acc, val) => acc + val)
return Math.ceil(sum / state.upload.size * 100); return Math.ceil(sum / state.upload.size * 100);
}, }
sharedSelectedCount: state => state.shared.selected.length
} }
export default getters export default getters

View File

@ -7,7 +7,18 @@ import upload from './modules/upload'
Vue.use(Vuex) Vue.use(Vuex)
const state = { const state = {
user: null, user: {
perm: {
admin: false,
create: false,
delete: false,
download: false,
execute: false,
modify: false,
rename: false,
share: false
}
},
req: {}, req: {},
oldReq: {}, oldReq: {},
clipboard: { clipboard: {
@ -25,13 +36,7 @@ const state = {
showMessage: null, showMessage: null,
showConfirm: null, showConfirm: null,
previewMode: false, previewMode: false,
shared: { hash: ''
req: {},
hash: '',
loaded: false,
selected: [],
multiple: false
}
} }
export default new Vuex.Store({ export default new Vuex.Store({

View File

@ -27,12 +27,8 @@ const mutations = {
state.show = 'success' state.show = 'success'
state.showMessage = value state.showMessage = value
}, },
setLoading: (state, value) => { setLoading: (state, value) => { state.loading = value },
state.loading = value setReload: (state, value) => { state.reload = value },
},
setReload: (state, value) => {
state.reload = value
},
setUser: (state, value) => { setUser: (state, value) => {
if (value === null) { if (value === null) {
state.user = null state.user = null
@ -91,19 +87,7 @@ const mutations = {
setPreviewMode(state, value) { setPreviewMode(state, value) {
state.previewMode = value state.previewMode = value
}, },
addSharedSelected: (state, value) => (state.shared.selected.push(value)), setHash: (state, value) => (state.hash = value),
removeSharedSelected: (state, value) => {
let i = state.shared.selected.indexOf(value)
if (i === -1) return
state.shared.selected.splice(i, 1)
},
resetSharedSelected: (state) => {
state.shared.selected = []
},
sharedMultiple: (state, value) => (state.shared.multiple = value),
updateSharedRequest: (state, value) => (state.shared.req = value),
setSharedHash: (state, value) => (state.shared.hash = value),
toggleSharedLoaded: (state, value) => (state.shared.loaded = value)
} }
export default mutations export default mutations

View File

@ -1,7 +1,7 @@
<template> <template>
<div v-if="shared.loaded"> <div v-if="!loading">
<div id="breadcrumbs"> <div id="breadcrumbs">
<router-link :to="'/share/' + shared.hash" :aria-label="$t('files.home')" :title="$t('files.home')"> <router-link :to="'/share/' + hash" :aria-label="$t('files.home')" :title="$t('files.home')">
<i class="material-icons">home</i> <i class="material-icons">home</i>
</router-link> </router-link>
@ -13,13 +13,13 @@
<div class="share"> <div class="share">
<div class="share__box share__box__info"> <div class="share__box share__box__info">
<div class="share__box__header"> <div class="share__box__header">
{{ shared.req.isDir ? $t('download.downloadFolder') : $t('download.downloadFile') }} {{ req.isDir ? $t('download.downloadFolder') : $t('download.downloadFile') }}
</div> </div>
<div class="share__box__element share__box__center share__box__icon"> <div class="share__box__element share__box__center share__box__icon">
<i class="material-icons">{{ icon }}</i> <i class="material-icons">{{ icon }}</i>
</div> </div>
<div class="share__box__element"> <div class="share__box__element">
<strong>{{ $t('prompts.displayName') }}</strong> {{ shared.req.name }} <strong>{{ $t('prompts.displayName') }}</strong> {{ req.name }}
</div> </div>
<div class="share__box__element"> <div class="share__box__element">
<strong>{{ $t('prompts.lastModified') }}:</strong> {{ humanTime }} <strong>{{ $t('prompts.lastModified') }}:</strong> {{ humanTime }}
@ -34,12 +34,12 @@
<qrcode-vue :value="fullLink" size="200" level="M"></qrcode-vue> <qrcode-vue :value="fullLink" size="200" level="M"></qrcode-vue>
</div> </div>
</div> </div>
<div v-if="shared.req.isDir" class="share__box share__box__items"> <div v-if="req.isDir && req.items.length > 0" class="share__box share__box__items">
<div class="share__box__header" v-if="shared.req.isDir"> <div class="share__box__header" v-if="req.isDir">
{{ $t('files.files') }} {{ $t('files.files') }}
</div> </div>
<div id="listing" class="list"> <div id="listing" class="list">
<shared-item v-for="(item) in shared.req.items.slice(0, this.showLimit)" <item v-for="(item) in req.items.slice(0, this.showLimit)"
:key="base64(item.name)" :key="base64(item.name)"
v-bind:index="item.index" v-bind:index="item.index"
v-bind:name="item.name" v-bind:name="item.name"
@ -48,14 +48,14 @@
v-bind:modified="item.modified" v-bind:modified="item.modified"
v-bind:type="item.type" v-bind:type="item.type"
v-bind:size="item.size"> v-bind:size="item.size">
</shared-item> </item>
<div v-if="shared.req.items.length > showLimit" class="item"> <div v-if="req.items.length > showLimit" class="item">
<div> <div>
<p class="name"> + {{ shared.req.items.length - showLimit }} </p> <p class="name"> + {{ req.items.length - showLimit }} </p>
</div> </div>
</div> </div>
<div :class="{ active: $store.state.shared.multiple }" id="multiple-selection"> <div :class="{ active: $store.state.multiple }" id="multiple-selection">
<p>{{ $t('files.multipleSelectionEnabled') }}</p> <p>{{ $t('files.multipleSelectionEnabled') }}</p>
<div @click="$store.commit('sharedMultiple', false)" tabindex="0" role="button" :title="$t('files.clear')" :aria-label="$t('files.clear')" class="action"> <div @click="$store.commit('sharedMultiple', false)" tabindex="0" role="button" :title="$t('files.clear')" :aria-label="$t('files.clear')" class="action">
<i class="material-icons">clear</i> <i class="material-icons">clear</i>
@ -63,8 +63,19 @@
</div> </div>
</div> </div>
</div> </div>
<div v-else-if="req.isDir && req.items.length === 0" class="share__box share__box__items">
<h2 class="message">
<i class="material-icons">sentiment_dissatisfied</i>
<span>{{ $t('files.lonely') }}</span>
</h2>
</div>
</div> </div>
</div> </div>
<div v-else-if="error">
<not-found v-if="error.message === '404'"></not-found>
<forbidden v-else-if="error.message === '403'"></forbidden>
<internal-error v-else></internal-error>
</div>
</template> </template>
<script> <script>
@ -74,16 +85,22 @@ import { baseURL } from '@/utils/constants'
import filesize from 'filesize' import filesize from 'filesize'
import moment from 'moment' import moment from 'moment'
import QrcodeVue from 'qrcode.vue' import QrcodeVue from 'qrcode.vue'
import SharedItem from "@/components/files/SharedItem" import Item from "@/components/files/ListingItem"
import Forbidden from './errors/403'
import NotFound from './errors/404'
import InternalError from './errors/500'
export default { export default {
name: 'share', name: 'share',
components: { components: {
SharedItem, Item,
Forbidden,
NotFound,
InternalError,
QrcodeVue QrcodeVue
}, },
data: () => ({ data: () => ({
notFound: false, error: null,
filePath: '', filePath: '',
showLimit: 500 showLimit: 500
}), }),
@ -92,7 +109,7 @@ export default {
}, },
created: async function () { created: async function () {
const hash = this.$route.params.pathMatch.split('/')[0] const hash = this.$route.params.pathMatch.split('/')[0]
this.setSharedHash(hash) this.setHash(hash)
await this.fetchData() await this.fetchData()
}, },
mounted () { mounted () {
@ -102,13 +119,13 @@ export default {
window.removeEventListener('keydown', this.keyEvent) window.removeEventListener('keydown', this.keyEvent)
}, },
computed: { computed: {
...mapState(['shared']), ...mapState(['hash', 'req', 'loading', 'multiple']),
...mapGetters(['sharedSelectedCount']), ...mapGetters(['selectedCount']),
icon: function () { icon: function () {
if (this.shared.req.isDir) return 'folder' if (this.req.isDir) return 'folder'
if (this.shared.req.type === 'image') return 'insert_photo' if (this.req.type === 'image') return 'insert_photo'
if (this.shared.req.type === 'audio') return 'volume_up' if (this.req.type === 'audio') return 'volume_up'
if (this.shared.req.type === 'video') return 'movie' if (this.req.type === 'video') return 'movie'
return 'insert_drive_file' return 'insert_drive_file'
}, },
path: function () { path: function () {
@ -132,20 +149,20 @@ export default {
return absoluteParts.slice(absoluteParts.length - len).join('/') return absoluteParts.slice(absoluteParts.length - len).join('/')
}, },
link: function () { link: function () {
return `${baseURL}/api/public/dl/${this.shared.hash}/${this.path}` return `${baseURL}/api/public/dl/${this.hash}/${this.path}`
}, },
fullLink: function () { fullLink: function () {
return window.location.origin + this.link return window.location.origin + this.link
}, },
humanSize: function () { humanSize: function () {
if (this.shared.req.isDir) { if (this.req.isDir) {
return this.shared.req.items.length return this.req.items.length
} }
return filesize(this.shared.req.size) return filesize(this.req.size)
}, },
humanTime: function () { humanTime: function () {
return moment(this.shared.req.modified).fromNow() return moment(this.req.modified).fromNow()
}, },
breadcrumbs () { breadcrumbs () {
let parts = this.path.split('/') let parts = this.path.split('/')
@ -162,7 +179,7 @@ export default {
for (let i = 0; i < parts.length; i++) { for (let i = 0; i < parts.length; i++) {
if (i === 0) { if (i === 0) {
breadcrumbs.push({ name: decodeURIComponent(parts[i]), url: '/share/' + this.shared.hash + '/' + parts[i] + '/' }) breadcrumbs.push({ name: decodeURIComponent(parts[i]), url: '/share/' + this.hash + '/' + parts[i] + '/' })
} else { } else {
breadcrumbs.push({ name: decodeURIComponent(parts[i]), url: breadcrumbs[i - 1].url + parts[i] + '/' }) breadcrumbs.push({ name: decodeURIComponent(parts[i]), url: breadcrumbs[i - 1].url + parts[i] + '/' })
} }
@ -182,27 +199,33 @@ export default {
} }
}, },
methods: { methods: {
...mapMutations([ 'resetSharedSelected', 'setSharedHash', 'updateSharedRequest', 'toggleSharedLoaded' ]), ...mapMutations([ 'setHash', 'resetSelected', 'updateRequest', 'setLoading' ]),
base64: function (name) { base64: function (name) {
return window.btoa(unescape(encodeURIComponent(name))) return window.btoa(unescape(encodeURIComponent(name)))
}, },
fetchData: async function () { fetchData: async function () {
this.notFound = false // Reset view information.
this.$store.commit('toggleSharedLoaded', false) this.$store.commit('setReload', false)
this.$store.commit('resetSharedSelected') this.$store.commit('resetSelected')
this.$store.commit('sharedMultiple', false) this.$store.commit('multiple', false)
this.$store.commit('closeHovers')
// Set loading to true and reset the error.
this.setLoading(true)
this.error = null
try { try {
let file = await api.getHash(encodeURIComponent(this.$route.params.pathMatch)) let file = await api.getHash(encodeURIComponent(this.$route.params.pathMatch))
this.filePath = file.path this.filePath = file.path
if (file.isDir) file.items = file.items.map((item, index) => { if (file.isDir) file.items = file.items.map((item, index) => {
item.index = index item.index = index
item.url = `/share/${this.shared.hash}/${this.path}/${encodeURIComponent(item.name)}` item.url = `/share/${this.hash}/${this.path}/${encodeURIComponent(item.name)}`
return item return item
}) })
this.updateSharedRequest(file) this.updateRequest(file)
this.$store.commit('toggleSharedLoaded', true) this.setLoading(false)
} catch (e) { } catch (e) {
this.notFound = true this.error = e
} }
}, },
keyEvent (event) { keyEvent (event) {
@ -210,13 +233,13 @@ export default {
if (event.keyCode === 27) { if (event.keyCode === 27) {
// If we're on a listing, unselect all // If we're on a listing, unselect all
// files and folders. // files and folders.
if (this.sharedSelectedCount > 0) { if (this.selectedCount > 0) {
this.resetSharedSelected() this.resetSelected()
} }
} }
}, },
toggleMultipleSelection () { toggleMultipleSelection () {
this.$store.commit('sharedMultiple', !this.shared.multiple) this.$store.commit('multiple', !this.multiple)
} }
} }
} }