forked from AkkomaGang/akkoma-fe
Merge branch 'feat/preload-data-from-html' into 'develop'
Add basic preloading for nodeinfo/config See merge request pleroma/pleroma-fe!1155
This commit is contained in:
commit
391f796cb4
1 changed files with 31 additions and 5 deletions
|
@ -8,9 +8,34 @@ import backendInteractorService from '../services/backend_interactor_service/bac
|
||||||
import { CURRENT_VERSION } from '../services/theme_data/theme_data.service.js'
|
import { CURRENT_VERSION } from '../services/theme_data/theme_data.service.js'
|
||||||
import { applyTheme } from '../services/style_setter/style_setter.js'
|
import { applyTheme } from '../services/style_setter/style_setter.js'
|
||||||
|
|
||||||
|
let staticInitialResults = null
|
||||||
|
|
||||||
|
const parsedInitialResults = () => {
|
||||||
|
if (!document.getElementById('initial-results')) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
if (!staticInitialResults) {
|
||||||
|
staticInitialResults = JSON.parse(document.getElementById('initial-results').textContent)
|
||||||
|
}
|
||||||
|
return staticInitialResults
|
||||||
|
}
|
||||||
|
|
||||||
|
const preloadFetch = async (request) => {
|
||||||
|
const data = parsedInitialResults()
|
||||||
|
if (!data || !data[request]) {
|
||||||
|
return window.fetch(request)
|
||||||
|
}
|
||||||
|
const requestData = atob(data[request])
|
||||||
|
return {
|
||||||
|
ok: true,
|
||||||
|
json: () => JSON.parse(requestData),
|
||||||
|
text: () => requestData
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const getInstanceConfig = async ({ store }) => {
|
const getInstanceConfig = async ({ store }) => {
|
||||||
try {
|
try {
|
||||||
const res = await window.fetch('/api/v1/instance')
|
const res = await preloadFetch('/api/v1/instance')
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
const data = await res.json()
|
const data = await res.json()
|
||||||
const textlimit = data.max_toot_chars
|
const textlimit = data.max_toot_chars
|
||||||
|
@ -133,7 +158,7 @@ const getTOS = async ({ store }) => {
|
||||||
|
|
||||||
const getInstancePanel = async ({ store }) => {
|
const getInstancePanel = async ({ store }) => {
|
||||||
try {
|
try {
|
||||||
const res = await window.fetch('/instance/panel.html')
|
const res = await preloadFetch('/instance/panel.html')
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
const html = await res.text()
|
const html = await res.text()
|
||||||
store.dispatch('setInstanceOption', { name: 'instanceSpecificPanelContent', value: html })
|
store.dispatch('setInstanceOption', { name: 'instanceSpecificPanelContent', value: html })
|
||||||
|
@ -196,7 +221,7 @@ const resolveStaffAccounts = ({ store, accounts }) => {
|
||||||
|
|
||||||
const getNodeInfo = async ({ store }) => {
|
const getNodeInfo = async ({ store }) => {
|
||||||
try {
|
try {
|
||||||
const res = await window.fetch('/nodeinfo/2.0.json')
|
const res = await preloadFetch('/nodeinfo/2.0.json')
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
const data = await res.json()
|
const data = await res.json()
|
||||||
const metadata = data.metadata
|
const metadata = data.metadata
|
||||||
|
@ -315,17 +340,18 @@ const afterStoreSetup = async ({ store, i18n }) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now we can try getting the server settings and logging in
|
// Now we can try getting the server settings and logging in
|
||||||
|
// Most of these are preloaded into the index.html so blocking is minimized
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
checkOAuthToken({ store }),
|
checkOAuthToken({ store }),
|
||||||
getTOS({ store }),
|
|
||||||
getInstancePanel({ store }),
|
getInstancePanel({ store }),
|
||||||
getStickers({ store }),
|
|
||||||
getNodeInfo({ store }),
|
getNodeInfo({ store }),
|
||||||
getInstanceConfig({ store })
|
getInstanceConfig({ store })
|
||||||
])
|
])
|
||||||
|
|
||||||
// Start fetching things that don't need to block the UI
|
// Start fetching things that don't need to block the UI
|
||||||
store.dispatch('fetchMutes')
|
store.dispatch('fetchMutes')
|
||||||
|
getTOS({ store })
|
||||||
|
getStickers({ store })
|
||||||
|
|
||||||
const router = new VueRouter({
|
const router = new VueRouter({
|
||||||
mode: 'history',
|
mode: 'history',
|
||||||
|
|
Loading…
Reference in a new issue