diff --git a/src/app.tsx b/src/app.tsx index 45d5571c..a05ced07 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -82,10 +82,12 @@ import { navigatePath } from './utils/router'; import states, { hideAllModals, initStates, statusKey } from './utils/states'; import store from './utils/store'; import { + getAccounts, getAccount, getCredentialApplication, getCurrentAccount, getVapidKey, + removeAccount, setCurrentAccountID, } from './utils/store-utils'; @@ -684,11 +686,20 @@ function App() { if (!account) { account = getCurrentAccount(); } - if (account) { + while (account) { setCurrentAccountID(account.info.id); - account.accessToken = await hydrateAtprotoOAuthAccessToken( - account.accessToken, - ); + try { + account.accessToken = await hydrateAtprotoOAuthAccessToken( + account.accessToken, + ); + break; + } catch (error) { + console.error(error); + removeAccount(account.info.id); + account = getAccounts()[0] ?? null; + } + } + if (account) { const { client } = api({ account }); const { instance } = client; // console.log('masto', masto); @@ -717,6 +728,7 @@ function App() { } } else { if (cancelled) return; + setIsLoggedIn(false); setUIState('default'); __BENCHMARK.end('app-init'); } diff --git a/src/components/camera-capture-input.tsx b/src/components/camera-capture-input.tsx index 83564b56..b9de747d 100644 --- a/src/components/camera-capture-input.tsx +++ b/src/components/camera-capture-input.tsx @@ -44,13 +44,13 @@ function CameraCaptureInput({ // It also can't switch between photo and video mode like iOS/Safari const filteredSupportedMimeTypes = isMobileSafari ? supportedMimeTypes - : supportedMimeTypes?.filter((mimeType) => !/^image\//i.test(mimeType)); + : supportedMimeTypes?.filter((mimeType) => /^image\//i.test(mimeType)); return ( (null); useEffect(() => { + const composeContainer = composeContainerRef.current; + if (!composeContainer) return undefined; + const handleFocus = (e: FocusEvent): void => { // Toggle focused if in or out if any fields are focused - // The container is non-null at handler time (the listener is only - // attached when composeContainer was defined). Mirror the original JS - // direct access. - (composeContainerRef.current as HTMLDivElement).classList.toggle( - 'focused', - e.type === 'focusin', - ); + composeContainer.classList.toggle('focused', e.type === 'focusin'); - const target = e.target as HTMLElement; + const target = e.target; + if (!(target instanceof HTMLElement)) return; if (target.hasAttribute('data-allow-custom-emoji')) { lastFocusedEmojiFieldRef.current = target; } @@ -838,17 +841,12 @@ function Compose({ } }; - const composeContainer = composeContainerRef.current; - if (composeContainer) { - composeContainer.addEventListener('focusin', handleFocus); - composeContainer.addEventListener('focusout', handleFocus); - } + composeContainer.addEventListener('focusin', handleFocus); + composeContainer.addEventListener('focusout', handleFocus); return () => { - if (composeContainer) { - composeContainer.removeEventListener('focusin', handleFocus); - composeContainer.removeEventListener('focusout', handleFocus); - } + composeContainer.removeEventListener('focusin', handleFocus); + composeContainer.removeEventListener('focusout', handleFocus); }; }, []); @@ -2359,123 +2357,119 @@ function Compose({
{showAddButton && ( - ( - - )} - > + <> {supportsCameraCapture && ( - + setMediaAttachments={setMediaAttachments} + /> )} - - - {_(ADD_LABELS.sensitive)} - - {showPollButton && ( + className="compose-menu-add-media" + onClick={(event) => { + event.keepOpen = true; + clickFileInput(menuCameraInputId); + }} + > + {' '} + {_(ADD_LABELS.camera)} + + )} { + event.keepOpen = true; + clickFileInput(menuMediaInputId); + }} > - {_(ADD_LABELS.poll)} + {_(ADD_LABELS.media)} - )} - - { - setShowEmoji2Picker({ - targetElement: lastFocusedEmojiFieldRef, - }); - }} - > - {' '} - {_(ADD_LABELS.customEmoji)} - - {states.settings.composerGIFPicker && ( + {' '} + {_(ADD_LABELS.sensitive)} + + {showPollButton && ( + + {_(ADD_LABELS.poll)} + + )} + + { - setShowGIFPicker(true); + setShowEmoji2Picker({ + targetElement: lastFocusedEmojiFieldRef, + }); }} > - - {_(ADD_LABELS.gif)} + {' '} + {_(ADD_LABELS.customEmoji)} - )} - {showScheduledAt && ( - <> - + {states.settings.composerGIFPicker && ( { + setShowGIFPicker(true); + }} > - {' '} - {_(ADD_LABELS.scheduledPost)} + + {_(ADD_LABELS.gif)} - - )} - + )} + {showScheduledAt && ( + <> + + + {' '} + {_(ADD_LABELS.scheduledPost)} + + + )} + + )}