perf: Add sum of selected torrents' size to selectedTorrentCountString (#803)

This commit is contained in:
Rémi Marseault 2023-05-08 21:23:34 +02:00 committed by GitHub
parent 0deb6f8e47
commit cf66103aca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 11 deletions

View file

@ -23,5 +23,9 @@ export class Torrents {
if (import.meta.env.VITE_USE_FAKE_TORRENTS === 'false') return
const count = import.meta.env.VITE_FAKE_TORRENT_COUNT
store.state.torrents.push(...generateMultiple(count))
// filter out deleted torrents from selection
const hash_index = store.state.torrents.map(torrent => torrent.hash)
store.state.selected_torrents = store.state.selected_torrents.filter(hash => hash_index.includes(hash))
}
}

View file

@ -47,7 +47,6 @@
"feed": "Feed",
"rule": "Rule",
"then": "Then",
"of": "of",
"yes": "yes",
"no": "no",
"filter": "Filter",
@ -62,7 +61,9 @@
"selectAllCaption": "Select / Release All (Ctrl + A)"
},
"emptyTorrentList": "Nothing to see here!",
"not_complete": "Not Yet Completed"
"not_complete": "Not Yet Completed",
"torrentsCount": "No torrent | {n} torrent | {n} torrents",
"selectedTorrentsCount": "No torrent | $0 of {n} torrent ($1) | $0 of {n} torrents ($1)"
},
"torrent": {
"properties": {
@ -135,8 +136,7 @@
"altSpeed": "Alt Speeds",
"dark": "Dark",
"light": "Light"
},
"torrentsCount": "No torrents | {n} torrent | {n} torrents"
}
},
"modals": {
"newFeed": {

View file

@ -1,5 +1,6 @@
import { i18n } from '@/plugins/i18n'
import type { StoreState } from '@/types/vuetorrent'
import {formatSize} from '@/filters'
export default {
getAppVersion: (state: StoreState) => () => state.version,
@ -20,14 +21,17 @@ export default {
getTrackers: (state: StoreState) => () => state.trackers,
getAuthenticated: (state: StoreState) => () => state.authenticated,
getTorrentCountString: (state: StoreState) => () => {
if (state.selected_torrents && state.selected_torrents.length) {
if (i18n.locale === 'zh-hans' || i18n.locale === 'zh-hant') {
return `${i18n.tc('navbar.torrentsCount', state.filteredTorrentsCount)}${i18n.t('of')} ${state.selected_torrents.length}`
} else {
return `${state.selected_torrents.length} ${i18n.t('of')} ${i18n.tc('navbar.torrentsCount', state.filteredTorrentsCount)}`
}
if (state.selected_torrents.length) {
let selectedSize = state.selected_torrents.map(hash => state.torrents.filter(el => el.hash === hash)[0])
.map(torrent => torrent.size)
.reduce((partialSum, newVal) => partialSum + newVal)
return i18n.tc('dashboard.selectedTorrentsCount', state.filteredTorrentsCount)
.replace('$0', state.selected_torrents.length.toString())
.replace('$1', formatSize(selectedSize))
} else {
return i18n.tc('dashboard.torrentsCount', state.filteredTorrentsCount)
}
return i18n.tc('navbar.torrentsCount', state.filteredTorrentsCount)
},
getSearchPlugins: (state: StoreState) => () => state.searchPlugins
}