move `toLocalePublicationString` to`utils/helper` (#2748)
* move toLocalePublicationString to helper * remove unnecessary assignments Co-Authored-By: absidue <48293849+absidue@users.noreply.github.com> * Update src/renderer/components/ft-list-video/ft-list-video.js Co-authored-by: PikachuEXE <pikachuexe@gmail.com> * fix linter issue Co-authored-by: absidue <48293849+absidue@users.noreply.github.com> Co-authored-by: PikachuEXE <pikachuexe@gmail.com>
This commit is contained in:
parent
7819dcd99f
commit
2c5c654b66
|
@ -2,7 +2,12 @@ import Vue from 'vue'
|
||||||
import FtIconButton from '../ft-icon-button/ft-icon-button.vue'
|
import FtIconButton from '../ft-icon-button/ft-icon-button.vue'
|
||||||
import { mapActions } from 'vuex'
|
import { mapActions } from 'vuex'
|
||||||
import i18n from '../../i18n/index'
|
import i18n from '../../i18n/index'
|
||||||
import { copyToClipboard, openExternalLink, showToast } from '../../helpers/utils'
|
import {
|
||||||
|
copyToClipboard,
|
||||||
|
openExternalLink,
|
||||||
|
showToast,
|
||||||
|
toLocalePublicationString
|
||||||
|
} from '../../helpers/utils'
|
||||||
|
|
||||||
export default Vue.extend({
|
export default Vue.extend({
|
||||||
name: 'FtListVideo',
|
name: 'FtListVideo',
|
||||||
|
@ -392,15 +397,11 @@ export default Vue.extend({
|
||||||
|
|
||||||
if (typeof (this.data.publishedText) !== 'undefined' && this.data.publishedText !== null && !this.isLive) {
|
if (typeof (this.data.publishedText) !== 'undefined' && this.data.publishedText !== null && !this.isLive) {
|
||||||
// produces a string according to the template in the locales string
|
// produces a string according to the template in the locales string
|
||||||
this.toLocalePublicationString({
|
this.uploadedTime = toLocalePublicationString({
|
||||||
publishText: this.publishedText,
|
publishText: this.publishedText,
|
||||||
isLive: this.isLive,
|
isLive: this.isLive,
|
||||||
isUpcoming: this.isUpcoming,
|
isUpcoming: this.isUpcoming,
|
||||||
isRSS: this.data.isRSS
|
isRSS: this.data.isRSS
|
||||||
}).then((data) => {
|
|
||||||
this.uploadedTime = data
|
|
||||||
}).catch((error) => {
|
|
||||||
console.error(error)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -503,7 +504,6 @@ export default Vue.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
...mapActions([
|
...mapActions([
|
||||||
'toLocalePublicationString',
|
|
||||||
'openInExternalPlayer',
|
'openInExternalPlayer',
|
||||||
'updateHistory',
|
'updateHistory',
|
||||||
'removeFromHistory',
|
'removeFromHistory',
|
||||||
|
|
|
@ -6,7 +6,7 @@ import FtSelect from '../../components/ft-select/ft-select.vue'
|
||||||
import FtTimestampCatcher from '../../components/ft-timestamp-catcher/ft-timestamp-catcher.vue'
|
import FtTimestampCatcher from '../../components/ft-timestamp-catcher/ft-timestamp-catcher.vue'
|
||||||
import autolinker from 'autolinker'
|
import autolinker from 'autolinker'
|
||||||
import ytcm from '@freetube/yt-comment-scraper'
|
import ytcm from '@freetube/yt-comment-scraper'
|
||||||
import { copyToClipboard, showToast } from '../../helpers/utils'
|
import { copyToClipboard, showToast, toLocalePublicationString } from '../../helpers/utils'
|
||||||
|
|
||||||
export default Vue.extend({
|
export default Vue.extend({
|
||||||
name: 'WatchVideoComments',
|
name: 'WatchVideoComments',
|
||||||
|
@ -204,16 +204,10 @@ export default Vue.extend({
|
||||||
comment.authorThumb = comment.authorThumb[0].url
|
comment.authorThumb = comment.authorThumb[0].url
|
||||||
comment.replies = []
|
comment.replies = []
|
||||||
comment.dataType = 'local'
|
comment.dataType = 'local'
|
||||||
this.toLocalePublicationString({
|
comment.time = toLocalePublicationString({
|
||||||
publishText: (comment.time + ' ago'),
|
publishText: (comment.time + ' ago')
|
||||||
isLive: false,
|
|
||||||
isUpcoming: false,
|
|
||||||
isRSS: false
|
|
||||||
}).then((data) => {
|
|
||||||
comment.time = data
|
|
||||||
}).catch((error) => {
|
|
||||||
console.error(error)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if (this.hideCommentLikes) {
|
if (this.hideCommentLikes) {
|
||||||
comment.likes = null
|
comment.likes = null
|
||||||
}
|
}
|
||||||
|
@ -352,7 +346,6 @@ export default Vue.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
...mapActions([
|
...mapActions([
|
||||||
'toLocalePublicationString',
|
|
||||||
'invidiousAPICall'
|
'invidiousAPICall'
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,6 +102,55 @@ export function calculatePublishedDate(publishedText) {
|
||||||
return date.getTime() - timeSpan
|
return date.getTime() - timeSpan
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function toLocalePublicationString ({ publishText, isLive = false, isUpcoming = false, isRSS = false }) {
|
||||||
|
if (isLive) {
|
||||||
|
return '0' + i18n.t('Video.Watching')
|
||||||
|
} else if (isUpcoming || publishText === null) {
|
||||||
|
// the check for null is currently just an inferring of knowledge, because there is no other possibility left
|
||||||
|
return `${i18n.t('Video.Published.Upcoming')}: ${publishText}`
|
||||||
|
} else if (isRSS) {
|
||||||
|
return publishText
|
||||||
|
}
|
||||||
|
const strings = publishText.split(' ')
|
||||||
|
// filters out the streamed x hours ago and removes the streamed in order to keep the rest of the code working
|
||||||
|
if (strings[0].toLowerCase() === 'streamed') {
|
||||||
|
strings.shift()
|
||||||
|
}
|
||||||
|
const singular = (strings[0] === '1')
|
||||||
|
let translationKey = ''
|
||||||
|
switch (strings[1].substring(0, 2)) {
|
||||||
|
case 'se':
|
||||||
|
translationKey = 'Video.Published.Second'
|
||||||
|
break
|
||||||
|
case 'mi':
|
||||||
|
translationKey = 'Video.Published.Minute'
|
||||||
|
break
|
||||||
|
case 'ho':
|
||||||
|
translationKey = 'Video.Published.Hour'
|
||||||
|
break
|
||||||
|
case 'da':
|
||||||
|
translationKey = 'Video.Published.Day'
|
||||||
|
break
|
||||||
|
case 'we':
|
||||||
|
translationKey = 'Video.Published.Week'
|
||||||
|
break
|
||||||
|
case 'mo':
|
||||||
|
translationKey = 'Video.Published.Month'
|
||||||
|
break
|
||||||
|
case 'ye':
|
||||||
|
translationKey = 'Video.Published.Year'
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
return publishText
|
||||||
|
}
|
||||||
|
if (!singular) {
|
||||||
|
translationKey += 's'
|
||||||
|
}
|
||||||
|
|
||||||
|
const unit = i18n.t(translationKey)
|
||||||
|
return i18n.t('Video.Publicationtemplate', { number: strings[0], unit })
|
||||||
|
}
|
||||||
|
|
||||||
export function buildVTTFileLocally(storyboard) {
|
export function buildVTTFileLocally(storyboard) {
|
||||||
let vttString = 'WEBVTT\n\n'
|
let vttString = 'WEBVTT\n\n'
|
||||||
// how many images are in one image
|
// how many images are in one image
|
||||||
|
|
|
@ -697,76 +697,6 @@ const actions = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
toLocalePublicationString ({ dispatch }, payload) {
|
|
||||||
if (payload.isLive) {
|
|
||||||
return '0' + i18n.t('Video.Watching')
|
|
||||||
} else if (payload.isUpcoming || payload.publishText === null) {
|
|
||||||
// the check for null is currently just an inferring of knowledge, because there is no other possibility left
|
|
||||||
return `${i18n.t('Video.Published.Upcoming')}: ${payload.publishText}`
|
|
||||||
} else if (payload.isRSS) {
|
|
||||||
return payload.publishText
|
|
||||||
}
|
|
||||||
const strings = payload.publishText.split(' ')
|
|
||||||
// filters out the streamed x hours ago and removes the streamed in order to keep the rest of the code working
|
|
||||||
if (strings[0].toLowerCase() === 'streamed') {
|
|
||||||
strings.shift()
|
|
||||||
}
|
|
||||||
const singular = (strings[0] === '1')
|
|
||||||
let unit
|
|
||||||
switch (strings[1].substring(0, 2)) {
|
|
||||||
case 'se':
|
|
||||||
if (singular) {
|
|
||||||
unit = i18n.t('Video.Published.Second')
|
|
||||||
} else {
|
|
||||||
unit = i18n.t('Video.Published.Seconds')
|
|
||||||
}
|
|
||||||
break
|
|
||||||
case 'mi':
|
|
||||||
if (singular) {
|
|
||||||
unit = i18n.t('Video.Published.Minute')
|
|
||||||
} else {
|
|
||||||
unit = i18n.t('Video.Published.Minutes')
|
|
||||||
}
|
|
||||||
break
|
|
||||||
case 'ho':
|
|
||||||
if (singular) {
|
|
||||||
unit = i18n.t('Video.Published.Hour')
|
|
||||||
} else {
|
|
||||||
unit = i18n.t('Video.Published.Hours')
|
|
||||||
}
|
|
||||||
break
|
|
||||||
case 'da':
|
|
||||||
if (singular) {
|
|
||||||
unit = i18n.t('Video.Published.Day')
|
|
||||||
} else {
|
|
||||||
unit = i18n.t('Video.Published.Days')
|
|
||||||
}
|
|
||||||
break
|
|
||||||
case 'we':
|
|
||||||
if (singular) {
|
|
||||||
unit = i18n.t('Video.Published.Week')
|
|
||||||
} else {
|
|
||||||
unit = i18n.t('Video.Published.Weeks')
|
|
||||||
}
|
|
||||||
break
|
|
||||||
case 'mo':
|
|
||||||
if (singular) {
|
|
||||||
unit = i18n.t('Video.Published.Month')
|
|
||||||
} else {
|
|
||||||
unit = i18n.t('Video.Published.Months')
|
|
||||||
}
|
|
||||||
break
|
|
||||||
case 'ye':
|
|
||||||
if (singular) {
|
|
||||||
unit = i18n.t('Video.Published.Year')
|
|
||||||
} else {
|
|
||||||
unit = i18n.t('Video.Published.Years')
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
return i18n.t('Video.Publicationtemplate', { number: strings[0], unit })
|
|
||||||
},
|
|
||||||
|
|
||||||
clearSessionSearchHistory ({ commit }) {
|
clearSessionSearchHistory ({ commit }) {
|
||||||
commit('setSessionSearchHistory', [])
|
commit('setSessionSearchHistory', [])
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue