Start progress on adding profiles

This commit is contained in:
Preston 2020-08-23 15:07:29 -04:00
parent cb2fd51dc5
commit b291cbf37b
7 changed files with 155 additions and 1 deletions

5
package-lock.json generated
View File

@ -13318,6 +13318,11 @@
"integrity": "sha1-SLtQiECfFvGCFmZkHETdGqrjzYg=", "integrity": "sha1-SLtQiECfFvGCFmZkHETdGqrjzYg=",
"dev": true "dev": true
}, },
"lodash.uniqwith": {
"version": "4.5.0",
"resolved": "https://registry.npmjs.org/lodash.uniqwith/-/lodash.uniqwith-4.5.0.tgz",
"integrity": "sha1-egy/ZfQ7WShiWp1NDcVLGMrcfvM="
},
"log-symbols": { "log-symbols": {
"version": "4.0.0", "version": "4.0.0",
"resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-4.0.0.tgz", "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-4.0.0.tgz",

View File

@ -20,6 +20,7 @@
"js-yaml": "^3.14.0", "js-yaml": "^3.14.0",
"lodash.debounce": "^4.0.8", "lodash.debounce": "^4.0.8",
"lodash.isequal": "^4.5.0", "lodash.isequal": "^4.5.0",
"lodash.uniqwith": "^4.5.0",
"material-design-icons": "^3.0.1", "material-design-icons": "^3.0.1",
"mediaelement": "^4.2.16", "mediaelement": "^4.2.16",
"nedb": "^1.8.0", "nedb": "^1.8.0",

View File

@ -33,6 +33,7 @@ export default Vue.extend({
mounted: function () { mounted: function () {
this.$store.dispatch('grabUserSettings') this.$store.dispatch('grabUserSettings')
this.$store.dispatch('grabHistory') this.$store.dispatch('grabHistory')
this.$store.dispatch('grabAllProfiles', this.$t('Profile.All Channels'))
this.$store.commit('setUsingElectron', useElectron) this.$store.commit('setUsingElectron', useElectron)
this.checkThemeSettings() this.checkThemeSettings()
this.checkLocale() this.checkLocale()

View File

@ -0,0 +1,106 @@
import Datastore from 'nedb'
let dbLocation
if (window && window.process && window.process.type === 'renderer') {
// Electron is being used
/* let dbLocation = localStorage.getItem('dbLocation')
if (dbLocation === null) {
const electron = require('electron')
dbLocation = electron.remote.app.getPath('userData')
} */
const electron = require('electron')
dbLocation = electron.remote.app.getPath('userData')
dbLocation = dbLocation + '/profiles.db'
} else {
dbLocation = 'profiles.db'
}
const profileDb = new Datastore({
filename: dbLocation,
autoload: true
})
const state = {
profileList: [],
activeProfile: 'allChannels'
}
const getters = {
getProfileList: () => {
return state.historyCache
}
}
const actions = {
grabAllProfiles ({ dispatch, commit }, defaultName = null) {
profileDb.find({}, (err, results) => {
if (!err) {
if (results.length === 0) {
dispatch('createDefaultProfile', defaultName)
} else {
commit('setProfileList', results)
}
}
})
},
async createDefaultProfile ({ dispatch }, defaultName) {
const randomColor = await dispatch('getRandomColor')
const textColor = await dispatch('calculateColorLuminance', randomColor)
const defaultProfile = {
_id: 'allChannels',
name: defaultName,
bgColor: randomColor,
textColor: textColor,
subscriptions: []
}
console.log(defaultProfile)
return
profileDb.update({ _id: 'allChannels' }, defaultProfile, { upsert: true }, (err, numReplaced) => {
if (!err) {
dispatch('grabAllProfiles')
}
})
},
updateProfile ({ dispatch }, profile) {
profileDb.update({ name: profile.name }, profile, { upsert: true }, (err, numReplaced) => {
if (!err) {
dispatch('grabAllProfiles')
}
})
},
removeFromHistory ({ dispatch }, videoId) {
historyDb.remove({ videoId: videoId }, (err, numReplaced) => {
if (!err) {
dispatch('grabHistory')
}
})
},
updateWatchProgress ({ dispatch }, videoData) {
historyDb.update({ videoId: videoData.videoId }, { $set: { watchProgress: videoData.watchProgress } }, { upsert: true }, (err, numReplaced) => {
if (!err) {
dispatch('grabHistory')
}
})
}
}
const mutations = {
setHistoryCache (state, historyCache) {
state.historyCache = historyCache
}
}
export default {
state,
getters,
actions,
mutations
}

View File

@ -28,6 +28,24 @@ const state = {
'mainAmber', 'mainAmber',
'mainOrange', 'mainOrange',
'mainDeepOrange' 'mainDeepOrange'
],
colorValues: [
'#d50000',
'#C51162',
'#AA00FF',
'#6200EA',
'#304FFE',
'#2962FF',
'#0091EA',
'#00B8D4',
'#00BFA5',
'#00C853',
'#64DD17',
'#AEEA00',
'#FFD600',
'#FFAB00',
'#FF6D00',
'#DD2C00'
] ]
} }
@ -63,6 +81,26 @@ const actions = {
return state.colorClasses[randomInt] return state.colorClasses[randomInt]
}, },
getRandomColor () {
const randomInt = Math.floor(Math.random() * state.colorValues.length)
return state.colorValues[randomInt]
},
calculateColorLuminance (_, colorValue) {
const cutHex = colorValue.substring(1, 7)
const colorValueR = parseInt(cutHex.substring(0, 2), 16)
const colorValueG = parseInt(cutHex.substring(2, 4), 16)
const colorValueB = parseInt(cutHex.substring(4, 6), 16)
const luminance = (0.299 * colorValueR + 0.587 * colorValueG + 0.114 * colorValueB) / 255
if (luminance > 0.5) {
return '#000000'
} else {
return '#FFFFFF'
}
},
getVideoIdFromUrl (_, url) { getVideoIdFromUrl (_, url) {
/** @type {URL} */ /** @type {URL} */
let urlObject let urlObject

View File

@ -1,7 +1,7 @@
<template> <template>
<div> <div>
<ft-card class="card"> <ft-card class="card">
<h3>{{ $t("Subscriptions.Subscriptions") }}</h3> <h3>{{ $t("Profile.Profile Manager") }}</h3>
<ft-flex-box> <ft-flex-box>
<p class="message"> <p class="message">
{{ $t("This part of the app is not ready yet. Come back later when progress has been made.") }} {{ $t("This part of the app is not ready yet. Come back later when progress has been made.") }}

View File

@ -246,6 +246,9 @@ About:
Latest FreeTube News: Latest FreeTube News Latest FreeTube News: Latest FreeTube News
Profile:
All Channels: All Channels
Profile Manager: Profile Manager
#On Channel Page #On Channel Page
Channel: Channel:
Subscriber: Subscriber Subscriber: Subscriber