forked from AkkomaGang/akkoma-fe
fixed v2 setting as default theme
This commit is contained in:
parent
3452864260
commit
fe2fe09236
2 changed files with 53 additions and 44 deletions
|
@ -1,6 +1,6 @@
|
||||||
import { rgb2hex, hex2rgb, getContrastRatio, alphaBlend } from '../../services/color_convert/color_convert.js'
|
import { rgb2hex, hex2rgb, getContrastRatio, alphaBlend } from '../../services/color_convert/color_convert.js'
|
||||||
import { set, delete as del } from 'vue'
|
import { set, delete as del } from 'vue'
|
||||||
import { generateColors, generateShadows, generateRadii, generateFonts, composePreset } from '../../services/style_setter/style_setter.js'
|
import { generateColors, generateShadows, generateRadii, generateFonts, composePreset, getThemes } from '../../services/style_setter/style_setter.js'
|
||||||
import ColorInput from '../color_input/color_input.vue'
|
import ColorInput from '../color_input/color_input.vue'
|
||||||
import RangeInput from '../range_input/range_input.vue'
|
import RangeInput from '../range_input/range_input.vue'
|
||||||
import OpacityInput from '../opacity_input/opacity_input.vue'
|
import OpacityInput from '../opacity_input/opacity_input.vue'
|
||||||
|
@ -104,35 +104,9 @@ export default {
|
||||||
created () {
|
created () {
|
||||||
const self = this
|
const self = this
|
||||||
|
|
||||||
window.fetch('/static/styles.json')
|
getThemes().then((themesComplete) => {
|
||||||
.then((data) => data.json())
|
self.availableStyles = themesComplete
|
||||||
.then((themes) => {
|
})
|
||||||
return Promise.all(Object.entries(themes).map(([k, v]) => {
|
|
||||||
if (typeof v === 'object') {
|
|
||||||
return Promise.resolve([k, v])
|
|
||||||
} else if (typeof v === 'string') {
|
|
||||||
return window.fetch(v)
|
|
||||||
.then((data) => data.json())
|
|
||||||
.then((theme) => {
|
|
||||||
return [k, theme]
|
|
||||||
})
|
|
||||||
.catch((e) => {
|
|
||||||
console.error(e)
|
|
||||||
return []
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}))
|
|
||||||
})
|
|
||||||
.then((promises) => {
|
|
||||||
return promises
|
|
||||||
.filter(([k, v]) => v)
|
|
||||||
.reduce((acc, [k, v]) => {
|
|
||||||
acc[k] = v
|
|
||||||
return acc
|
|
||||||
}, {})
|
|
||||||
}).then((themesComplete) => {
|
|
||||||
self.availableStyles = themesComplete
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
mounted () {
|
mounted () {
|
||||||
this.normalizeLocalState(this.$store.state.config.customTheme)
|
this.normalizeLocalState(this.$store.state.config.customTheme)
|
||||||
|
|
|
@ -449,11 +449,43 @@ const generatePreset = (input) => {
|
||||||
return composePreset(colors, radii, shadows, fonts)
|
return composePreset(colors, radii, shadows, fonts)
|
||||||
}
|
}
|
||||||
|
|
||||||
const setPreset = (val, commit) => {
|
const getThemes = () => {
|
||||||
window.fetch('/static/styles.json')
|
return window.fetch('/static/styles.json')
|
||||||
.then((data) => data.json())
|
.then((data) => data.json())
|
||||||
.then((themes) => {
|
.then((themes) => {
|
||||||
const theme = themes[val] ? themes[val] : themes['pleroma-dark']
|
return Promise.all(Object.entries(themes).map(([k, v]) => {
|
||||||
|
if (typeof v === 'object') {
|
||||||
|
return Promise.resolve([k, v])
|
||||||
|
} else if (typeof v === 'string') {
|
||||||
|
return window.fetch(v)
|
||||||
|
.then((data) => data.json())
|
||||||
|
.then((theme) => {
|
||||||
|
return [k, theme]
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
console.error(e)
|
||||||
|
return []
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
})
|
||||||
|
.then((promises) => {
|
||||||
|
return promises
|
||||||
|
.filter(([k, v]) => v)
|
||||||
|
.reduce((acc, [k, v]) => {
|
||||||
|
acc[k] = v
|
||||||
|
return acc
|
||||||
|
}, {})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const setPreset = (val, commit) => {
|
||||||
|
getThemes().then((themes) => {
|
||||||
|
const theme = themes[val] ? themes[val] : themes['pleroma-dark']
|
||||||
|
const isV1 = Array.isArray(theme)
|
||||||
|
const data = isV1 ? {} : theme.theme
|
||||||
|
|
||||||
|
if (isV1) {
|
||||||
const bgRgb = hex2rgb(theme[1])
|
const bgRgb = hex2rgb(theme[1])
|
||||||
const fgRgb = hex2rgb(theme[2])
|
const fgRgb = hex2rgb(theme[2])
|
||||||
const textRgb = hex2rgb(theme[3])
|
const textRgb = hex2rgb(theme[3])
|
||||||
|
@ -464,7 +496,7 @@ const setPreset = (val, commit) => {
|
||||||
const cBlueRgb = hex2rgb(theme[7] || '#0000FF')
|
const cBlueRgb = hex2rgb(theme[7] || '#0000FF')
|
||||||
const cOrangeRgb = hex2rgb(theme[8] || '#E3FF00')
|
const cOrangeRgb = hex2rgb(theme[8] || '#E3FF00')
|
||||||
|
|
||||||
const colors = {
|
data.colors = {
|
||||||
bg: bgRgb,
|
bg: bgRgb,
|
||||||
fg: fgRgb,
|
fg: fgRgb,
|
||||||
text: textRgb,
|
text: textRgb,
|
||||||
|
@ -474,17 +506,19 @@ const setPreset = (val, commit) => {
|
||||||
cGreen: cGreenRgb,
|
cGreen: cGreenRgb,
|
||||||
cOrange: cOrangeRgb
|
cOrange: cOrangeRgb
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// This is a hack, this function is only called during initial load.
|
console.log(data)
|
||||||
// We want to cancel loading the theme from config.json if we're already
|
// This is a hack, this function is only called during initial load.
|
||||||
// loading a theme from the persisted state.
|
// We want to cancel loading the theme from config.json if we're already
|
||||||
// Needed some way of dealing with the async way of things.
|
// loading a theme from the persisted state.
|
||||||
// load config -> set preset -> wait for styles.json to load ->
|
// Needed some way of dealing with the async way of things.
|
||||||
// load persisted state -> set colors -> styles.json loaded -> set colors
|
// load config -> set preset -> wait for styles.json to load ->
|
||||||
if (!window.themeLoaded) {
|
// load persisted state -> set colors -> styles.json loaded -> set colors
|
||||||
setColors({ colors }, commit)
|
if (!window.themeLoaded) {
|
||||||
}
|
setColors(data, commit)
|
||||||
})
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
@ -497,6 +531,7 @@ export {
|
||||||
generateShadows,
|
generateShadows,
|
||||||
generateFonts,
|
generateFonts,
|
||||||
generatePreset,
|
generatePreset,
|
||||||
|
getThemes,
|
||||||
composePreset,
|
composePreset,
|
||||||
getCssShadow,
|
getCssShadow,
|
||||||
getCssShadowFilter
|
getCssShadowFilter
|
||||||
|
|
Loading…
Reference in a new issue