this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

DRY get current Account

+18 -21
+5 -9
src/components/compose.jsx
··· 13 13 import openCompose from '../utils/open-compose'; 14 14 import states from '../utils/states'; 15 15 import store from '../utils/store'; 16 + import { getCurrentAccount } from '../utils/store-utils'; 16 17 import useDebouncedCallback from '../utils/useDebouncedCallback'; 17 18 import visibilityIconsMap from '../utils/visibility-icons-map'; 18 19 ··· 80 81 console.warn('RENDER COMPOSER'); 81 82 const [uiState, setUIState] = useState('default'); 82 83 83 - const accounts = store.local.getJSON('accounts'); 84 - const currentAccount = store.session.get('currentAccount'); 85 - const currentAccountInfo = accounts.find( 86 - (a) => a.info.id === currentAccount, 87 - ).info; 84 + const currentAccount = getCurrentAccount(); 85 + const currentAccountInfo = currentAccount.info; 88 86 89 87 const configuration = useMemo(() => { 90 88 try { 91 89 const instances = store.local.getJSON('instances'); 92 - const currentInstance = accounts 93 - .find((a) => a.info.id === currentAccount) 94 - .instanceURL.toLowerCase(); 90 + const currentInstance = currentAccount.instanceURL.toLowerCase(); 95 91 const config = instances[currentInstance].configuration; 96 92 console.log(config); 97 93 return config; ··· 269 265 } 270 266 271 267 // check if status contains only "@acct", if replying 272 - const isSelf = replyToStatus?.account.id === currentAccount; 268 + const isSelf = replyToStatus?.account.id === currentAccountInfo.id; 273 269 const hasOnlyAcct = 274 270 replyToStatus && value.trim() === `@${replyToStatus.account.acct}`; 275 271 // TODO: check for mentions, or maybe just generic "@username<space>", including multiple mentions like "@username1<space>@username2<space>"
+2 -7
src/compose.jsx
··· 7 7 import { useEffect, useState } from 'preact/hooks'; 8 8 9 9 import Compose from './components/compose'; 10 - import store from './utils/store'; 10 + import { getCurrentAccount } from './utils/store-utils'; 11 11 import useTitle from './utils/useTitle'; 12 12 13 13 if (window.opener) { ··· 18 18 if (window.masto) return; 19 19 console.warn('window.masto not found. Trying to log in...'); 20 20 try { 21 - const accounts = store.local.getJSON('accounts') || []; 22 - const currentAccount = store.session.get('currentAccount'); 23 - const account = 24 - accounts.find((a) => a.info.id === currentAccount) || accounts[0]; 25 - const instanceURL = account.instanceURL; 26 - const accessToken = account.accessToken; 21 + const { instanceURL, accessToken } = getCurrentAccount(); 27 22 window.masto = await login({ 28 23 url: `https://${instanceURL}`, 29 24 accessToken,
+2 -5
src/pages/status.jsx
··· 16 16 import shortenNumber from '../utils/shorten-number'; 17 17 import states, { saveStatus } from '../utils/states'; 18 18 import store from '../utils/store'; 19 + import { getCurrentAccount } from '../utils/store-utils'; 19 20 import useDebouncedCallback from '../utils/useDebouncedCallback'; 20 21 import useScroll from '../utils/useScroll'; 21 22 import useTitle from '../utils/useTitle'; ··· 206 207 // Delete the cache for the context 207 208 (async () => { 208 209 try { 209 - const accounts = store.local.getJSON('accounts') || []; 210 - const currentAccount = store.session.get('currentAccount'); 211 - const account = 212 - accounts.find((a) => a.info.id === currentAccount) || accounts[0]; 213 - const instanceURL = account.instanceURL; 210 + const { instanceURL } = getCurrentAccount(); 214 211 const contextURL = `https://${instanceURL}/api/v1/statuses/${id}/context`; 215 212 console.log('Clear cache', contextURL); 216 213 const apiCache = await caches.open('api');
+9
src/utils/store-utils.js
··· 1 + import store from './store'; 2 + 3 + export function getCurrentAccount() { 4 + const accounts = store.local.getJSON('accounts') || []; 5 + const currentAccount = store.session.get('currentAccount'); 6 + const account = 7 + accounts.find((a) => a.info.id === currentAccount) || accounts[0]; 8 + return account; 9 + }