Skip to content

Commit

Permalink
feat: Speed cards as pills with icon in first column and speed on top…
Browse files Browse the repository at this point in the history
… of the unit in second column (#169)

Co-authored-by: Ievgen Sobko <ievgensobko@cloud.upwork.com>
  • Loading branch information
2 people authored and WDaan committed Feb 28, 2021
1 parent 1973b5d commit 354fe4f
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 44 deletions.
5 changes: 5 additions & 0 deletions src/actions/index.js
@@ -0,0 +1,5 @@
import { setDocumentTitle } from './setDocumentTitle'

export {
setDocumentTitle
}
35 changes: 35 additions & 0 deletions src/actions/setDocumentTitle.js
@@ -0,0 +1,35 @@
import { formatBytes } from '@/helpers'

export class setDocumentTitle {
static setDefault() {
this.set('VueTorrent')
}

static setGlobalSpeed(speeds) {
if (!speeds || speeds.length !== 2) return
this.set(`[D: ${formatBytes(speeds[0])}/s, U: ${formatBytes(speeds[1])}/s] VueTorrent`)
}

static setFirstTorrentStatus(torrent) {
if (!torrent) return
this.set(`${torrent.state.toLowerCase()} - ${torrent.progress}% - ${torrent.name}`)
}

static updateTitle(mode, speeds, torrent) {
if (!mode || !speeds.length || !torrent) return
switch (mode) {
case 'Default':
return this.setDefault()
case 'Global Speed':
return this.setGlobalSpeed(speeds)
case 'First Torrent Status':
return this.setFirstTorrentStatus(torrent)
default:
return this.setDefault()
}
}

static set(title) {
document.title = title
}
}
38 changes: 20 additions & 18 deletions src/components/Core/SpeedCard.vue
@@ -1,29 +1,31 @@
<template>
<v-card
flat
rounded="md"
color="secondary"
class="speedCard"
data-testid="SpeedCard"
>
<v-layout row :class="color + '--text'">
<v-flex v-if="icon" xs2>
<v-icon data-testid="SpeedCard-icon" :color="color" size="16px">
<v-layout row align-center :class="color + '--text'">
<v-flex v-if="icon" xs2 class="pl-1">
<v-icon data-testid="SpeedCard-icon" :color="color" size="20px">
{{ icon }}
</v-icon>
</v-flex>
<v-flex xs6 class="text-center font-weight-bold robot-mono">
<span data-testid="SpeedCard-value">
{{ value | getSpeedValue }}
</span>
</v-flex>
<v-flex
xs4
class="caption robot-mono text-right mt-1"
>
<span data-testid="SpeedCard-unit">
{{ value | getDataUnit(1) }}/s
</span>
</v-flex>
<v-layout column xs10>
<v-flex class="text-center font-weight-bold robot-mono">
<span data-testid="SpeedCard-value">
{{ value | getSpeedValue }}
</span>
</v-flex>
<v-flex
class="caption robot-mono text-center mt-n1"
>
<span data-testid="SpeedCard-unit">
{{ value | getDataUnit(1) }}/s
</span>
</v-flex>
</v-layout>
</v-layout>
</v-card>
</template>
Expand All @@ -47,7 +49,7 @@ export default {

<style scoped>
.speedCard {
padding: 32px 16px !important;
font-size: 1.05em;
padding: 20px 20px !important;
font-size: 1.10em;
}
</style>
39 changes: 22 additions & 17 deletions src/components/Modals/SettingsModal/Tabs/Vuetorrent/General.vue
Expand Up @@ -59,16 +59,6 @@
Show Tracker Filter
</template>
</v-switch>
<v-switch
v-model="showSpeedInTitle"
class="v-input--reverse v-input--expand pa-0 ma-0"
inset
color="accent"
>
<template #label>
Show Speed in Title
</template>
</v-switch>
<v-switch
v-model="useDeviceDarkMode"
class="v-input--reverse v-input--expand pa-0 ma-0"
Expand All @@ -94,6 +84,21 @@
/>
</v-col>
</v-row>
<v-row dense>
<v-col cols="8" sm="8" md="10">
<p class="subtitle-1">
VueTorrent title:
</p>
</v-col>
<v-col cols="4" sm="4" md="2">
<v-select
v-model="title"
class="pa-0 ma-0"
color="accent"
:items="titleOptions"
/>
</v-col>
</v-row>
<v-row dense>
<v-col cols="10" sm="10" md="11">
<p class="subtitle-1">
Expand Down Expand Up @@ -136,6 +141,7 @@ export default {
data() {
return {
paginationSizes: [5, 15, 30, 50],
titleOptions: ['Default', 'Global Speed', 'First Torrent Status'],
Qbitversion: 0
}
},
Expand Down Expand Up @@ -190,21 +196,20 @@ export default {
this.webuiSettings.useDeviceDarkMode = val
}
},
showSpeedInTitle: {
paginationSize: {
get() {
return this.webuiSettings.showSpeedInTitle
return this.webuiSettings.paginationSize
},
set(val) {
this.webuiSettings.showSpeedInTitle = val
document.title = 'VueTorrent'
this.webuiSettings.paginationSize = val
}
},
paginationSize: {
title: {
get() {
return this.webuiSettings.paginationSize
return this.webuiSettings.title
},
set(val) {
this.webuiSettings.paginationSize = val
this.webuiSettings.title = val
}
},
version() {
Expand Down
1 change: 1 addition & 0 deletions src/store/index.js
Expand Up @@ -57,6 +57,7 @@ export default new Vuex.Store({
showCurrentSpeed: true,
showTrackerFilter: false,
showSpeedInTitle: false,
title: 'Default',
useDeviceDarkMode: true,
paginationSize: 15,
busyTorrentProperties: [
Expand Down
18 changes: 10 additions & 8 deletions src/store/mutations.js
@@ -1,7 +1,8 @@
import Torrent from '../models/Torrent'
import Status from '../models/Status'
import qbit from '../services/qbit'
import { formatBytes, getHostName } from '@/helpers'
import { getHostName } from '@/helpers'
import { setDocumentTitle } from '@/actions'

export default {
SET_APP_VERSION(state, version) {
Expand Down Expand Up @@ -79,21 +80,22 @@ export default {
}
}

// torrent speed in title
if (state.webuiSettings.showSpeedInTitle) {
// eslint-disable-next-line max-len
document.title = `[D: ${formatBytes(state.status.dlspeed)}/s, U: ${formatBytes(state.status.upspeed)}/s] VueTorrent`
}

// torrents
state.torrents = data.map(t => new Torrent(t))

// update document title
setDocumentTitle.updateTitle(
state.webuiSettings.title,
[state.status.dlspeed, state.status.upspeed],
state.torrents ? state.torrents[0] : null
)
},
FETCH_SETTINGS: async state => {
const { data } = await qbit.getAppPreferences()
state.settings = data
},
UPDATE_SORT_OPTIONS: (state, {
hashes = [],
hashes = [],
filter = null,
category = null,
tracker = null
Expand Down
2 changes: 1 addition & 1 deletion tests/helpers.js
Expand Up @@ -10,4 +10,4 @@ export function setup(component, propsData) {
vuetify,
propsData
})
}
}

0 comments on commit 354fe4f

Please sign in to comment.