diff --git a/package.json b/package.json index fc4c725ec..d8d1a2fd2 100644 --- a/package.json +++ b/package.json @@ -113,7 +113,6 @@ "leaflet": "^1.8.0", "lexical": "^0.18.0", "line-awesome": "^1.3.0", - "localforage": "^1.10.0", "lodash": "^4.7.11", "mini-css-extract-plugin": "^2.6.0", "nostr-tools": "^2.3.0", diff --git a/src/actions/auth.ts b/src/actions/auth.ts index 13d4fc72a..08ecb51fe 100644 --- a/src/actions/auth.ts +++ b/src/actions/auth.ts @@ -18,7 +18,6 @@ import { custom } from 'soapbox/custom.ts'; import { queryClient } from 'soapbox/queries/client.ts'; import { selectAccount } from 'soapbox/selectors/index.ts'; import { unsetSentryAccount } from 'soapbox/sentry.ts'; -import KVStore from 'soapbox/storage/kv-store.ts'; import toast from 'soapbox/toast.tsx'; import { getLoggedInAccount, parseBaseURL } from 'soapbox/utils/auth.ts'; import sourceCode from 'soapbox/utils/code.ts'; @@ -164,23 +163,6 @@ export const verifyCredentials = (token: string, accountUrl?: string) => { }; }; -export const rememberAuthAccount = (accountUrl: string) => - (dispatch: AppDispatch, getState: () => RootState) => { - dispatch({ type: AUTH_ACCOUNT_REMEMBER_REQUEST, accountUrl }); - return KVStore.getItemOrError(`authAccount:${accountUrl}`).then(account => { - dispatch(importFetchedAccount(account)); - dispatch({ type: AUTH_ACCOUNT_REMEMBER_SUCCESS, account, accountUrl }); - if (account.id === getState().me) dispatch(fetchMeSuccess(account)); - return account; - }).catch(error => { - dispatch({ type: AUTH_ACCOUNT_REMEMBER_FAIL, error, accountUrl, skipAlert: true }); - }); - }; - -export const loadCredentials = (token: string, accountUrl: string) => - (dispatch: AppDispatch) => dispatch(rememberAuthAccount(accountUrl)) - .finally(() => dispatch(verifyCredentials(token, accountUrl))); - export const logIn = (username: string, password: string) => (dispatch: AppDispatch) => dispatch(getAuthApp()).then(() => { return dispatch(createUserToken(normalizeUsername(username), password)); diff --git a/src/actions/me.ts b/src/actions/me.ts index 47641594f..01354a1df 100644 --- a/src/actions/me.ts +++ b/src/actions/me.ts @@ -1,11 +1,10 @@ import { selectAccount } from 'soapbox/selectors/index.ts'; import { setSentryAccount } from 'soapbox/sentry.ts'; -import KVStore from 'soapbox/storage/kv-store.ts'; import { getAuthUserId, getAuthUserUrl } from 'soapbox/utils/auth.ts'; import api from '../api/index.ts'; -import { loadCredentials } from './auth.ts'; +import { verifyCredentials } from './auth.ts'; import { importFetchedAccount } from './importer/index.ts'; import type { RawAxiosRequestHeaders } from 'axios'; @@ -51,22 +50,10 @@ const fetchMe = () => } dispatch(fetchMeRequest()); - return dispatch(loadCredentials(token, accountUrl!)) + return dispatch(verifyCredentials(token, accountUrl!)) .catch(error => dispatch(fetchMeFail(error))); }; -/** Update the auth account in IndexedDB for Mastodon, etc. */ -const persistAuthAccount = (account: APIEntity, params: Record) => { - if (account && account.url) { - if (!account.pleroma) account.pleroma = {}; - - if (!account.pleroma.settings_store) { - account.pleroma.settings_store = params.pleroma_settings_store || {}; - } - KVStore.setItem(`authAccount:${account.url}`, account).catch(console.error); - } -}; - const patchMe = (params: Record, isFormData = false) => (dispatch: AppDispatch, getState: () => RootState) => { dispatch(patchMeRequest()); @@ -78,7 +65,6 @@ const patchMe = (params: Record, isFormData = false) => return api(getState) .patch('/api/v1/accounts/update_credentials', params, { headers }) .then(response => { - persistAuthAccount(response.data, params); dispatch(patchMeSuccess(response.data)); }).catch(error => { dispatch(patchMeFail(error)); diff --git a/src/actions/soapbox.ts b/src/actions/soapbox.ts index cd0170c90..dd9ad5d25 100644 --- a/src/actions/soapbox.ts +++ b/src/actions/soapbox.ts @@ -1,8 +1,6 @@ import { createSelector } from 'reselect'; -import { getHost } from 'soapbox/actions/instance.ts'; import { normalizeSoapboxConfig } from 'soapbox/normalizers/index.ts'; -import KVStore from 'soapbox/storage/kv-store.ts'; import { getFeatures } from 'soapbox/utils/features.ts'; import api from '../api/index.ts'; @@ -31,17 +29,6 @@ const getSoapboxConfig = createSelector([ }); }); -const rememberSoapboxConfig = (host: string | null) => - (dispatch: AppDispatch) => { - dispatch({ type: SOAPBOX_CONFIG_REMEMBER_REQUEST, host }); - return KVStore.getItemOrError(`soapbox_config:${host}`).then(soapboxConfig => { - dispatch({ type: SOAPBOX_CONFIG_REMEMBER_SUCCESS, host, soapboxConfig }); - return soapboxConfig; - }).catch(error => { - dispatch({ type: SOAPBOX_CONFIG_REMEMBER_FAIL, host, error, skipAlert: true }); - }); - }; - const fetchFrontendConfigurations = () => (dispatch: AppDispatch, getState: () => RootState) => api(getState) @@ -49,7 +36,7 @@ const fetchFrontendConfigurations = () => .then(({ data }) => data); /** Conditionally fetches Soapbox config depending on backend features */ -const fetchSoapboxConfig = (host: string | null) => +const fetchSoapboxConfig = (host: string | null = null) => (dispatch: AppDispatch, getState: () => RootState) => { const features = getFeatures(getState().instance); @@ -67,16 +54,6 @@ const fetchSoapboxConfig = (host: string | null) => } }; -/** Tries to remember the config from browser storage before fetching it */ -const loadSoapboxConfig = () => - (dispatch: AppDispatch, getState: () => RootState) => { - const host = getHost(getState()); - - return dispatch(rememberSoapboxConfig(host)).then(() => - dispatch(fetchSoapboxConfig(host)), - ); - }; - const fetchSoapboxJson = (host: string | null) => (dispatch: AppDispatch) => fetch('/instance/soapbox.json').then((response) => response.json()).then((data) => { @@ -115,10 +92,8 @@ export { SOAPBOX_CONFIG_REMEMBER_SUCCESS, SOAPBOX_CONFIG_REMEMBER_FAIL, getSoapboxConfig, - rememberSoapboxConfig, fetchFrontendConfigurations, fetchSoapboxConfig, - loadSoapboxConfig, fetchSoapboxJson, importSoapboxConfig, soapboxConfigFail, diff --git a/src/components/site-error-boundary.tsx b/src/components/site-error-boundary.tsx index b18dcba21..eb2afe50f 100644 --- a/src/components/site-error-boundary.tsx +++ b/src/components/site-error-boundary.tsx @@ -8,7 +8,6 @@ import Text from 'soapbox/components/ui/text.tsx'; import Textarea from 'soapbox/components/ui/textarea.tsx'; import { useSoapboxConfig } from 'soapbox/hooks/useSoapboxConfig.ts'; import { captureSentryException } from 'soapbox/sentry.ts'; -import KVStore from 'soapbox/storage/kv-store.ts'; import sourceCode from 'soapbox/utils/code.ts'; import { unregisterSW } from 'soapbox/utils/sw.ts'; @@ -32,7 +31,6 @@ const SiteErrorBoundary: React.FC = ({ children }) => { const clearCookies: React.MouseEventHandler = (e) => { localStorage.clear(); sessionStorage.clear(); - KVStore.clear(); if ('serviceWorker' in navigator) { e.preventDefault(); diff --git a/src/init/soapbox-load.tsx b/src/init/soapbox-load.tsx index fa77d86e0..2fddc0445 100644 --- a/src/init/soapbox-load.tsx +++ b/src/init/soapbox-load.tsx @@ -3,7 +3,7 @@ import { IntlProvider } from 'react-intl'; import { fetchMe } from 'soapbox/actions/me.ts'; -import { loadSoapboxConfig } from 'soapbox/actions/soapbox.ts'; +import { fetchSoapboxConfig } from 'soapbox/actions/soapbox.ts'; import LoadingScreen from 'soapbox/components/loading-screen.tsx'; import { useNostr } from 'soapbox/contexts/nostr-context.tsx'; import { useBunker } from 'soapbox/hooks/nostr/useBunker.ts'; @@ -22,7 +22,7 @@ const loadInitial = () => { // Await for authenticated fetch await dispatch(fetchMe()); // Await for configuration - await dispatch(loadSoapboxConfig()); + await dispatch(fetchSoapboxConfig()); }; }; diff --git a/src/reducers/soapbox.ts b/src/reducers/soapbox.ts index a8ba53d2b..753adb526 100644 --- a/src/reducers/soapbox.ts +++ b/src/reducers/soapbox.ts @@ -1,7 +1,6 @@ import { List as ImmutableList, Map as ImmutableMap, fromJS } from 'immutable'; import { PLEROMA_PRELOAD_IMPORT } from 'soapbox/actions/preload.ts'; -import KVStore from 'soapbox/storage/kv-store.ts'; import { ConfigDB } from 'soapbox/utils/config-db.ts'; import { ADMIN_CONFIG_UPDATE_SUCCESS } from '../actions/admin.ts'; @@ -40,14 +39,7 @@ const preloadImport = (state: ImmutableMap, action: Record, host: string) => { - if (host) { - KVStore.setItem(`soapbox_config:${host}`, soapboxConfig.toJS()).catch(console.error); - } -}; - const importSoapboxConfig = (state: ImmutableMap, soapboxConfig: ImmutableMap, host: string) => { - persistSoapboxConfig(soapboxConfig, host); return soapboxConfig; }; diff --git a/src/storage/kv-store.ts b/src/storage/kv-store.ts deleted file mode 100644 index a8886aa12..000000000 --- a/src/storage/kv-store.ts +++ /dev/null @@ -1,28 +0,0 @@ -import localforage from 'localforage'; - -interface IKVStore extends LocalForage { - getItemOrError: (key: string) => Promise; -} - -// localForage -// https://localforage.github.io/localForage/#settings-api-config -export const KVStore = localforage.createInstance({ - name: 'soapbox', - description: 'Soapbox offline data store', - driver: localforage.INDEXEDDB, - storeName: 'keyvaluepairs', -}) as IKVStore; - -// localForage returns 'null' when a key isn't found. -// In the Redux action flow, we want it to fail harder. -KVStore.getItemOrError = (key: string) => { - return KVStore.getItem(key).then(value => { - if (value === null) { - throw new Error(`KVStore: null value for key ${key}`); - } else { - return value; - } - }); -}; - -export default KVStore; diff --git a/yarn.lock b/yarn.lock index ba844369f..2ed2ba762 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5297,11 +5297,6 @@ ignore@^6.0.2: resolved "https://registry.yarnpkg.com/ignore/-/ignore-6.0.2.tgz#77cccb72a55796af1b6d2f9eb14fa326d24f4283" integrity sha512-InwqeHHN2XpumIkMvpl/DCJVrAHgCsG5+cn1XlnLWGwtZBm8QJfSusItfrwx81CTp5agNZqpKU2J/ccC5nGT4A== -immediate@~3.0.5: - version "3.0.6" - resolved "https://registry.yarnpkg.com/immediate/-/immediate-3.0.6.tgz#9db1dbd0faf8de6fbe0f5dd5e56bb606280de69b" - integrity sha1-nbHb0Pr43m++D13V5Wu2BigN5ps= - immer@^10.0.0, immer@^10.0.3: version "10.0.3" resolved "https://registry.yarnpkg.com/immer/-/immer-10.0.3.tgz#a8de42065e964aa3edf6afc282dfc7f7f34ae3c9" @@ -5889,13 +5884,6 @@ li@^1.3.0: resolved "https://registry.yarnpkg.com/li/-/li-1.3.0.tgz#22c59bcaefaa9a8ef359cf759784e4bf106aea1b" integrity sha512-z34TU6GlMram52Tss5mt1m//ifRIpKH5Dqm7yUVOdHI+BQCs9qGPHFaCUTIzsWX7edN30aa2WrPwR7IO10FHaw== -lie@3.1.1: - version "3.1.1" - resolved "https://registry.yarnpkg.com/lie/-/lie-3.1.1.tgz#9a436b2cc7746ca59de7a41fa469b3efb76bd87e" - integrity sha1-mkNrLMd0bKWd56QfpGmz77dr2H4= - dependencies: - immediate "~3.0.5" - lilconfig@^2.0.5, lilconfig@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/lilconfig/-/lilconfig-2.1.0.tgz#78e23ac89ebb7e1bfbf25b18043de756548e7f52" @@ -5949,13 +5937,6 @@ load-tsconfig@^0.2.3: resolved "https://registry.yarnpkg.com/load-tsconfig/-/load-tsconfig-0.2.5.tgz#453b8cd8961bfb912dea77eb6c168fe8cca3d3a1" integrity sha512-IXO6OCs9yg8tMKzfPZ1YmheJbZCiEsnBdcB03l0OcfK9prKnJb96siuHCr5Fl37/yo9DnKU+TLpxzTUspw9shg== -localforage@^1.10.0: - version "1.10.0" - resolved "https://registry.yarnpkg.com/localforage/-/localforage-1.10.0.tgz#5c465dc5f62b2807c3a84c0c6a1b1b3212781dd4" - integrity sha512-14/H1aX7hzBBmmh7sGPd+AOMkkIrHM3Z1PAyGgZigA1H1p5O5ANnMyWzvpAETtG68/dC4pC0ncy3+PPGzXZHPg== - dependencies: - lie "3.1.1" - locate-path@^6.0.0: version "6.0.0" resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-6.0.0.tgz#55321eb309febbc59c4801d931a72452a681d286"