Preload: dispatch preload action
This commit is contained in:
parent
31d007eeb1
commit
57340496bc
|
@ -0,0 +1,25 @@
|
||||||
|
import { mapValues } from 'lodash';
|
||||||
|
|
||||||
|
const PRELOAD_IMPORT = 'PRELOAD_IMPORT';
|
||||||
|
|
||||||
|
// https://git.pleroma.social/pleroma/pleroma-fe/-/merge_requests/1176/diffs
|
||||||
|
const decodeUTF8Base64 = (data) => {
|
||||||
|
const rawData = atob(data);
|
||||||
|
const array = Uint8Array.from(rawData.split('').map((char) => char.charCodeAt(0)));
|
||||||
|
const text = new TextDecoder().decode(array);
|
||||||
|
return text;
|
||||||
|
};
|
||||||
|
|
||||||
|
const decodeData = data =>
|
||||||
|
mapValues(data, base64string =>
|
||||||
|
JSON.parse(decodeUTF8Base64(base64string)));
|
||||||
|
|
||||||
|
export function preload() {
|
||||||
|
const element = document.getElementById('initial-results');
|
||||||
|
const data = element ? JSON.parse(element.textContent) : {};
|
||||||
|
|
||||||
|
return {
|
||||||
|
type: PRELOAD_IMPORT,
|
||||||
|
data: decodeData(data),
|
||||||
|
};
|
||||||
|
}
|
|
@ -14,9 +14,8 @@ import { ScrollContext } from 'react-router-scroll-4';
|
||||||
import UI from '../features/ui';
|
import UI from '../features/ui';
|
||||||
// import Introduction from '../features/introduction';
|
// import Introduction from '../features/introduction';
|
||||||
import { fetchCustomEmojis } from '../actions/custom_emojis';
|
import { fetchCustomEmojis } from '../actions/custom_emojis';
|
||||||
import { hydrateStore } from '../actions/store';
|
import { preload } from '../actions/preload';
|
||||||
import { IntlProvider } from 'react-intl';
|
import { IntlProvider } from 'react-intl';
|
||||||
import initialState from '../initial_state';
|
|
||||||
import ErrorBoundary from '../components/error_boundary';
|
import ErrorBoundary from '../components/error_boundary';
|
||||||
import { fetchInstance } from 'soapbox/actions/instance';
|
import { fetchInstance } from 'soapbox/actions/instance';
|
||||||
import { fetchSoapboxConfig } from 'soapbox/actions/soapbox';
|
import { fetchSoapboxConfig } from 'soapbox/actions/soapbox';
|
||||||
|
@ -30,9 +29,8 @@ import messages from 'soapbox/locales/messages';
|
||||||
const validLocale = locale => Object.keys(messages).includes(locale);
|
const validLocale = locale => Object.keys(messages).includes(locale);
|
||||||
|
|
||||||
export const store = configureStore();
|
export const store = configureStore();
|
||||||
const hydrateAction = hydrateStore(initialState);
|
|
||||||
|
|
||||||
store.dispatch(hydrateAction);
|
store.dispatch(preload());
|
||||||
store.dispatch(fetchMe());
|
store.dispatch(fetchMe());
|
||||||
store.dispatch(fetchInstance());
|
store.dispatch(fetchInstance());
|
||||||
store.dispatch(fetchSoapboxConfig());
|
store.dispatch(fetchSoapboxConfig());
|
||||||
|
|
Loading…
Reference in New Issue