diff --git a/app/soapbox/actions/preload.js b/app/soapbox/actions/preload.js new file mode 100644 index 000000000..405e144f3 --- /dev/null +++ b/app/soapbox/actions/preload.js @@ -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), + }; +} diff --git a/app/soapbox/containers/soapbox.js b/app/soapbox/containers/soapbox.js index 2c7d6f85c..a2fcda9b6 100644 --- a/app/soapbox/containers/soapbox.js +++ b/app/soapbox/containers/soapbox.js @@ -14,9 +14,8 @@ import { ScrollContext } from 'react-router-scroll-4'; import UI from '../features/ui'; // import Introduction from '../features/introduction'; import { fetchCustomEmojis } from '../actions/custom_emojis'; -import { hydrateStore } from '../actions/store'; +import { preload } from '../actions/preload'; import { IntlProvider } from 'react-intl'; -import initialState from '../initial_state'; import ErrorBoundary from '../components/error_boundary'; import { fetchInstance } from 'soapbox/actions/instance'; import { fetchSoapboxConfig } from 'soapbox/actions/soapbox'; @@ -30,9 +29,8 @@ import messages from 'soapbox/locales/messages'; const validLocale = locale => Object.keys(messages).includes(locale); export const store = configureStore(); -const hydrateAction = hydrateStore(initialState); -store.dispatch(hydrateAction); +store.dispatch(preload()); store.dispatch(fetchMe()); store.dispatch(fetchInstance()); store.dispatch(fetchSoapboxConfig());