optimized theme loading so that it wouldn't wait until ALL themes are loaded to
select one by default
This commit is contained in:
parent
24a7a9bfd8
commit
f77d675434
|
@ -96,7 +96,24 @@ export default {
|
||||||
created () {
|
created () {
|
||||||
const self = this
|
const self = this
|
||||||
|
|
||||||
getThemes().then((themesComplete) => {
|
getThemes()
|
||||||
|
.then((promises) => {
|
||||||
|
return Promise.all(
|
||||||
|
Object.entries(promises)
|
||||||
|
.map(([k, v]) => v.then(res => [k, res]))
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.then(themes => themes.reduce((acc, [k, v]) => {
|
||||||
|
if (v) {
|
||||||
|
return {
|
||||||
|
...acc,
|
||||||
|
[k]: v
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return acc
|
||||||
|
}
|
||||||
|
}, {}))
|
||||||
|
.then((themesComplete) => {
|
||||||
self.availableStyles = themesComplete
|
self.availableStyles = themesComplete
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
|
@ -336,25 +336,23 @@ export const getThemes = () => {
|
||||||
return window.fetch('/static/styles.json')
|
return window.fetch('/static/styles.json')
|
||||||
.then((data) => data.json())
|
.then((data) => data.json())
|
||||||
.then((themes) => {
|
.then((themes) => {
|
||||||
return Promise.all(Object.entries(themes).map(([k, v]) => {
|
return Object.entries(themes).map(([k, v]) => {
|
||||||
|
let promise = null
|
||||||
if (typeof v === 'object') {
|
if (typeof v === 'object') {
|
||||||
return Promise.resolve([k, v])
|
promise = Promise.resolve(v)
|
||||||
} else if (typeof v === 'string') {
|
} else if (typeof v === 'string') {
|
||||||
return window.fetch(v)
|
promise = window.fetch(v)
|
||||||
.then((data) => data.json())
|
.then((data) => data.json())
|
||||||
.then((theme) => {
|
|
||||||
return [k, theme]
|
|
||||||
})
|
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
return []
|
return null
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}))
|
return [k, promise]
|
||||||
|
})
|
||||||
})
|
})
|
||||||
.then((promises) => {
|
.then((promises) => {
|
||||||
return promises
|
return promises
|
||||||
.filter(([k, v]) => v)
|
|
||||||
.reduce((acc, [k, v]) => {
|
.reduce((acc, [k, v]) => {
|
||||||
acc[k] = v
|
acc[k] = v
|
||||||
return acc
|
return acc
|
||||||
|
@ -363,8 +361,9 @@ export const getThemes = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const setPreset = (val, commit) => {
|
export const setPreset = (val, commit) => {
|
||||||
return getThemes().then((themes) => {
|
return getThemes()
|
||||||
const theme = themes[val] ? themes[val] : themes['pleroma-dark']
|
.then((themes) => console.log(themes) || themes[val] ? themes[val] : themes['pleroma-dark'])
|
||||||
|
.then((theme) => {
|
||||||
const isV1 = Array.isArray(theme)
|
const isV1 = Array.isArray(theme)
|
||||||
const data = isV1 ? {} : theme.theme
|
const data = isV1 ? {} : theme.theme
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue