Skip to content

Commit

Permalink
fix(content): Fix regressions after #1779 (#1785)
Browse files Browse the repository at this point in the history
- Improve concurrency of updateFileTree
- Fix selection toggle **enabling** all files on mixed priority
- Fix mixed priority folder render (checkbox / color)
- Only display selected size on folders
  • Loading branch information
Larsluph authored Jul 10, 2024
1 parent 1eb0a93 commit b977713
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 20 deletions.
20 changes: 14 additions & 6 deletions src/components/TorrentDetail/Content/ContentNode.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<script setup lang="ts">
import { getFileIcon } from '@/constants/vuetorrent'
import { useI18n } from 'vue-i18n'
import { FilePriority } from '@/constants/qbit'
import { getFileIcon } from '@/constants/vuetorrent'
import { doesCommand, formatData } from '@/helpers'
import { useContentStore, useVueTorrentStore } from '@/stores'
import { TreeNode } from '@/types/vuetorrent'
import { computed } from 'vue'
import { useI18n } from 'vue-i18n'
import { useDisplay } from 'vuetify'
const props = defineProps<{
Expand Down Expand Up @@ -92,10 +92,18 @@ function getNodeSubtitle(node: TreeNode) {
const size = formatData(node.size, vuetorrentStore.useBinarySize)
const selectedSize = formatData(node.selectedSize, vuetorrentStore.useBinarySize)
const values = [size + (node.selectedSize > 0 ? ` (${selectedSize})` : '')]
let values: string[]
if (node.type === 'folder') {
values.push(getNodeDeepCount(node))
let displayedSize = size
if (node.selectedSize > 0) {
displayedSize += ` (${selectedSize})`
}
values = [
displayedSize,
getNodeDeepCount(node)
]
} else {
values = [size]
}
return values.join(' | ')
Expand All @@ -111,7 +119,7 @@ function getNodeSubtitle(node: TreeNode) {
<div class="d-flex">
<!-- Selection checkbox -->
<div class="d-flex align-center" @click.stop="toggleFileSelection(node)">
<v-icon v-if="node.wanted === null" :color="getNodeColor(node)" icon="mdi-checkbox-intermediate-variant" />
<v-icon v-if="node.priority === FilePriority.MIXED" :color="getNodeColor(node)" icon="mdi-checkbox-intermediate-variant" />
<v-icon v-else-if="node.wanted" :color="getNodeColor(node)" icon="mdi-checkbox-marked" />
<v-icon v-else :color="getNodeColor(node)" icon="mdi-checkbox-blank-outline" />
</div>
Expand Down
6 changes: 3 additions & 3 deletions src/stores/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,13 @@ export const useContentStore = defineStore('content', () => {
isFolder: node.type === 'folder',
oldName: node.fullName
}
dialogStore.createDialog(MoveTorrentFileDialog, payload, updateFileTree)
dialogStore.createDialog(MoveTorrentFileDialog, payload, updateFileTreeTask.perform)
}

async function bulkRename(node: TreeFolder) {
const { default: BulkRenameFilesDialog } = await import('@/components/Dialogs/BulkRenameFilesDialog.vue')
const payload = { hash: hash.value, node }
dialogStore.createDialog(BulkRenameFilesDialog, payload, updateFileTree)
dialogStore.createDialog(BulkRenameFilesDialog, payload, updateFileTreeTask.perform)
}

async function renameTorrentFile(hash: string, oldPath: string, newPath: string) {
Expand All @@ -129,7 +129,7 @@ export const useContentStore = defineStore('content', () => {

async function setFilePriority(fileIdx: number[], priority: FilePriority) {
await qbit.setTorrentFilePriority(hash.value, fileIdx, priority)
await updateFileTree()
updateFileTreeTask.perform()
}

async function fetchFiles(hash: string, indexes?: number[]) {
Expand Down
5 changes: 4 additions & 1 deletion src/types/vuetorrent/TreeObjects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,17 @@ describe('TreeObjects', () => {
})

test('isWanted', () => {
// Mixed
folder.children = [file_unwanted, file_normal, file_high, file_maximal]
folder.buildCache()
expect(folder.wanted).toBe(null)
expect(folder.wanted).toBe(true)

// Selected
folder.children = [file_normal, file_high, file_maximal]
folder.buildCache()
expect(folder.wanted).toBe(true)

// Skipped
folder.children = [file_unwanted]
folder.buildCache()
expect(folder.wanted).toBe(false)
Expand Down
14 changes: 4 additions & 10 deletions src/types/vuetorrent/TreeObjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,15 @@ export class TreeFolder {

this.childrenIds = this.children.map(child => child.childrenIds ?? []).flat()

this.wanted = this.children
.map(child => child.wanted)
.reduce((prev, curr) => {
if (prev === null || prev === curr) return prev
return null
})
this.wanted = this.children.map(child => child.wanted).some(Boolean)

const values = this.children.filter(child => child.wanted)
if (values.length === 0) {
const wantedChildren = this.children.filter(child => child.wanted)
if (wantedChildren.length === 0) {
this.progress = 0
} else {
// Downloaded / total
const result = values.reduce((prev, child) => [prev[0] + child.selectedSize * child.progress, prev[1] + child.selectedSize], [0, 0])
const result = wantedChildren.reduce((prev, child) => [prev[0] + child.selectedSize * child.progress, prev[1] + child.selectedSize], [0, 0])
this.progress = result[0] / result[1]
console.log(values.length, result, this.progress)
}

this.deepCount = this.children
Expand Down

0 comments on commit b977713

Please sign in to comment.