Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 10 additions & 7 deletions src/components/card/AttachmentList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,12 @@ import relativeDate from '../../mixins/relativeDate.js'
import { formatFileSize } from '@nextcloud/files'
import { getCurrentUser } from '@nextcloud/auth'
import { generateUrl, generateOcsUrl, generateRemoteUrl } from '@nextcloud/router'
import { mapState, mapActions } from 'vuex'
import { mapState as mapStateVuex } from 'vuex'
import { mapState, mapActions } from 'pinia'
import { loadState } from '@nextcloud/initial-state'
import attachmentUpload from '../../mixins/attachmentUpload.js'
import { getFilePickerBuilder } from '@nextcloud/dialogs'
import { useAttachmentStore } from '../../stores/attachment.js'
const maxUploadSizeState = loadState('deck', 'maxUploadSize', -1)

const picker = getFilePickerBuilder(t('deck', 'File to share'))
Expand Down Expand Up @@ -147,7 +149,7 @@ export default {
},
attachments() {
// FIXME sort propertly by last modified / deleted at
return [...this.$store.getters.attachmentsByCard(this.cardId)].filter(attachment => attachment.deletedAt >= 0).sort((a, b) => b.id - a.id)
return [...this.attachmentsByCard(this.cardId)].filter(attachment => attachment.deletedAt >= 0).sort((a, b) => b.id - a.id)
},
mimetypeForAttachment() {
return (attachment) => {
Expand Down Expand Up @@ -176,9 +178,12 @@ export default {
formattedFileSize() {
return (filesize) => formatFileSize(filesize)
},
...mapState({
...mapStateVuex({
currentBoard: state => state.currentBoard,
}),
...mapState(useAttachmentStore, [
'attachmentsByCard',
]),
isReadOnly() {
return !this.$store.getters.canEdit
},
Expand Down Expand Up @@ -210,8 +215,9 @@ export default {
},
},
methods: {
...mapActions([
...mapActions(useAttachmentStore, [
'fetchAttachments',
'unshareAttachment',
]),
handleUploadFile(event) {
const files = event.target.files ?? []
Expand Down Expand Up @@ -240,9 +246,6 @@ export default {
})
})
},
unshareAttachment(attachment) {
this.$store.dispatch('unshareAttachment', attachment)
},
clickAddNewAttachmment() {
this.$refs.localAttachments.click()
},
Expand Down
12 changes: 6 additions & 6 deletions src/components/card/CardSidebarTabAttachments.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
</template>

<script>
import { mapActions } from 'pinia'
import AttachmentList from './AttachmentList.vue'
import { useAttachmentStore } from '../../stores/attachment.js'
export default {
name: 'CardSidebarTabAttachments',
components: {
Expand All @@ -24,12 +26,10 @@ export default {
},
},
methods: {
deleteAttachment(attachment) {
this.$store.dispatch('deleteAttachment', attachment)
},
restoreAttachment(attachment) {
this.$store.dispatch('restoreAttachment', attachment)
},
...mapActions(useAttachmentStore, [
'deleteAttachment',
'restoreAttachment',
]),
},
}
</script>
5 changes: 3 additions & 2 deletions src/components/cards/CardCover.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
</div>
</template>
<script>
import { mapActions } from 'vuex'
import { mapActions } from 'pinia'
import { generateUrl } from '@nextcloud/router'
import { useAttachmentStore } from '../../stores/attachment.js'
export default {
name: 'CardCover',
props: {
Expand Down Expand Up @@ -61,7 +62,7 @@ export default {
},
},
methods: {
...mapActions([
...mapActions(useAttachmentStore, [
'fetchAttachments',
]),
},
Expand Down
10 changes: 8 additions & 2 deletions src/mixins/attachmentUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { showError } from '@nextcloud/dialogs'
import { formatFileSize } from '@nextcloud/files'
// eslint-disable-next-line import/no-unresolved
import PQueue from 'p-queue'
import { mapActions } from 'pinia'
import { useAttachmentStore } from '../stores/attachment.js'

const queue = new PQueue({ concurrency: 2 })

Expand Down Expand Up @@ -33,7 +35,7 @@ export default {
bodyFormData.append('file', file)
await queue.add(async () => {
try {
await this.$store.dispatch('createAttachment', {
await this.createAttachment({
cardId: this.cardId,
formData: bodyFormData,
onUploadProgress: (e) => {
Expand All @@ -54,13 +56,17 @@ export default {
})

},
...mapActions(useAttachmentStore, [
'createAttachment',
'updateAttachment',
]),

overrideAttachment() {
const bodyFormData = new FormData()
bodyFormData.append('cardId', this.cardId)
bodyFormData.append('type', 'deck_file')
bodyFormData.append('file', this.file)
this.$store.dispatch('updateAttachment', {
this.updateAttachment({
cardId: this.cardId,
attachment: this.overwriteAttachment,
formData: bodyFormData,
Expand Down
109 changes: 0 additions & 109 deletions src/store/attachment.js

This file was deleted.

2 changes: 0 additions & 2 deletions src/store/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { generateOcsUrl, generateUrl } from '@nextcloud/router'
import { BoardApi } from '../services/BoardApi.js'
import stackModuleFactory from './stack.js'
import cardModuleFactory from './card.js'
import attachment from './attachment.js'
Vue.use(Vuex)

const apiClient = new BoardApi()
Expand All @@ -33,7 +32,6 @@ export default function storeFactory() {
modules: {
stack: stackModuleFactory(),
card: cardModuleFactory(),
attachment,
},
strict: debug,
state: {
Expand Down
78 changes: 78 additions & 0 deletions src/stores/attachment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import { defineStore } from 'pinia'
import Vue from 'vue'
import { AttachmentApi } from '../services/AttachmentApi.js'

const apiClient = new AttachmentApi()

export const useAttachmentStore = defineStore('attachment', {
state: () => ({
attachments: {},
}),
getters: {
attachmentsByCard: (state) => (cardId) => {
if (typeof state.attachments[cardId] === 'undefined') {
return []
}
return state.attachments[cardId]
},
},
actions: {
async createAttachment({ cardId, formData, onUploadProgress }) {
const boardId = this.$vuex.state.currentBoard.id
const attachment = await apiClient.createAttachment({ cardId, formData, onUploadProgress, boardId })
if (typeof this.attachments[cardId] === 'undefined') {
Vue.set(this.attachments, cardId, [attachment])
} else {
this.attachments[cardId].push(attachment)
}
this.$vuex.commit('cardSetAttachmentCount', { cardId })
},
async fetchAttachments(cardId) {
const boardId = this.$vuex.state.currentBoard.id
const attachments = await apiClient.fetchAttachments(cardId, boardId)
Vue.set(this.attachments, cardId, attachments)
this.$vuex.commit('cardSetAttachmentCount', { cardId, count: attachments.length })
},
async updateAttachment({ cardId, attachment, formData }) {
const boardId = this.$vuex.state.currentBoard.id
const result = await apiClient.updateAttachment({ cardId, attachment, formData, boardId })
const existingIndex = this.attachments[attachment.cardId].findIndex(a => a.id === attachment.id && a.type === attachment.type)
if (existingIndex !== -1) {
Vue.set(this.attachments[cardId], existingIndex, result)
}
},
async deleteAttachment(attachment) {
const boardId = this.$vuex.state.currentBoard.id
await apiClient.deleteAttachment(attachment, boardId)
const existingIndex = this.attachments[attachment.cardId].findIndex(a => a.id === attachment.id && a.type === attachment.type)
if (existingIndex !== -1) {
Vue.set(this.attachments[attachment.cardId][existingIndex], 'deletedAt', Date.now() / 1000 | 0)
}
this.$vuex.commit('cardDecreaseAttachmentCount', { cardId: attachment.cardId })
},
async unshareAttachment(attachment) {
const boardId = this.$vuex.state.currentBoard.id
await apiClient.deleteAttachment(attachment, boardId)
const existingIndex = this.attachments[attachment.cardId].findIndex(a => a.id === attachment.id && a.type === attachment.type)
if (existingIndex !== -1) {
Vue.set(this.attachments[attachment.cardId][existingIndex], 'deletedAt', -1)
}
this.$vuex.commit('cardDecreaseAttachmentCount', { cardId: attachment.cardId })
},
async restoreAttachment(attachment) {
const boardId = this.$vuex.state.currentBoard.id
const restoredAttachment = await apiClient.restoreAttachment(attachment, boardId)
const existingIndex = this.attachments[restoredAttachment.cardId].findIndex(a => a.id === restoredAttachment.id && a.type === restoredAttachment.type)
if (existingIndex !== -1) {
Vue.set(this.attachments[restoredAttachment.cardId][existingIndex], 'deletedAt', 0)
}
this.$vuex.commit('cardIncreaseAttachmentCount', attachment.cardId)
},
},

})
Loading