From 20f64079e05ce493edf9ada0b33e217e8c17b165 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 24 Aug 2020 15:53:38 -0500 Subject: [PATCH] Preload /api/v1/instance --- app/soapbox/actions/preload.js | 2 +- app/soapbox/reducers/instance.js | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/soapbox/actions/preload.js b/app/soapbox/actions/preload.js index 405e144f3..0f19ec721 100644 --- a/app/soapbox/actions/preload.js +++ b/app/soapbox/actions/preload.js @@ -1,6 +1,6 @@ import { mapValues } from 'lodash'; -const PRELOAD_IMPORT = 'PRELOAD_IMPORT'; +export const PRELOAD_IMPORT = 'PRELOAD_IMPORT'; // https://git.pleroma.social/pleroma/pleroma-fe/-/merge_requests/1176/diffs const decodeUTF8Base64 = (data) => { diff --git a/app/soapbox/reducers/instance.js b/app/soapbox/reducers/instance.js index f2fc6b5ca..3bcd1c4ba 100644 --- a/app/soapbox/reducers/instance.js +++ b/app/soapbox/reducers/instance.js @@ -2,6 +2,7 @@ import { INSTANCE_FETCH_SUCCESS, NODEINFO_FETCH_SUCCESS, } from '../actions/instance'; +import { PRELOAD_IMPORT } from 'soapbox/actions/preload'; import { Map as ImmutableMap, fromJS } from 'immutable'; const nodeinfoToInstance = nodeinfo => { @@ -31,8 +32,15 @@ const initialState = ImmutableMap({ }), }); +const preloadImport = (state, action, path) => { + const data = action.data[path]; + return data ? initialState.mergeDeep(fromJS(data)) : state; +}; + export default function instance(state = initialState, action) { switch(action.type) { + case PRELOAD_IMPORT: + return preloadImport(state, action, '/api/v1/instance'); case INSTANCE_FETCH_SUCCESS: return initialState.mergeDeep(fromJS(action.instance)); case NODEINFO_FETCH_SUCCESS: