diff --git a/routes/_actions/accounts.js b/routes/_actions/accounts.js index f8e981361..c90df7222 100644 --- a/routes/_actions/accounts.js +++ b/routes/_actions/accounts.js @@ -52,11 +52,10 @@ export async function clearProfileAndRelationship () { } export async function updateProfileAndRelationship (accountId) { - let instanceName = store.get('currentInstance') - let accessToken = store.get('accessToken') + let { currentInstance, accessToken } = store.get() await Promise.all([ - updateAccount(accountId, instanceName, accessToken), - updateRelationship(accountId, instanceName, accessToken) + updateAccount(accountId, currentInstance, accessToken), + updateRelationship(accountId, currentInstance, accessToken) ]) } diff --git a/routes/_actions/addInstance.js b/routes/_actions/addInstance.js index 8fe69f9e1..69fcfc7e8 100644 --- a/routes/_actions/addInstance.js +++ b/routes/_actions/addInstance.js @@ -11,24 +11,23 @@ const REDIRECT_URI = (typeof location !== 'undefined' ? location.origin : 'https://pinafore.social') + '/settings/instances/add' async function redirectToOauth () { - let instanceName = store.get('instanceNameInSearch') - let loggedInInstances = store.get('loggedInInstances') - instanceName = instanceName.replace(/^https?:\/\//, '').replace(/\/$/, '').replace('/$', '').toLowerCase() - if (Object.keys(loggedInInstances).includes(instanceName)) { - store.set({logInToInstanceError: `You've already logged in to ${instanceName}`}) + let { instanceNameInSearch, loggedInInstances } = store.get() + instanceNameInSearch = instanceNameInSearch.replace(/^https?:\/\//, '').replace(/\/$/, '').replace('/$', '').toLowerCase() + if (Object.keys(loggedInInstances).includes(instanceNameInSearch)) { + store.set({logInToInstanceError: `You've already logged in to ${instanceNameInSearch}`}) return } - let registrationPromise = registerApplication(instanceName, REDIRECT_URI) - let instanceInfo = await getInstanceInfo(instanceName) - await setInstanceInfoInDatabase(instanceName, instanceInfo) // cache for later + let registrationPromise = registerApplication(instanceNameInSearch, REDIRECT_URI) + let instanceInfo = await getInstanceInfo(instanceNameInSearch) + await setInstanceInfoInDatabase(instanceNameInSearch, instanceInfo) // cache for later let instanceData = await registrationPromise store.set({ - currentRegisteredInstanceName: instanceName, + currentRegisteredInstanceName: instanceNameInSearch, currentRegisteredInstance: instanceData }) store.save() let oauthUrl = generateAuthLink( - instanceName, + instanceNameInSearch, instanceData.client_id, REDIRECT_URI ) @@ -48,9 +47,10 @@ export async function logInToInstance () { (navigator.onLine ? `Is this a valid Mastodon instance? Is a browser extension blocking the request?` : `Are you offline?`) + let { instanceNameInSearch } = store.get() store.set({ logInToInstanceError: error, - logInToInstanceErrorForText: store.get('instanceNameInSearch') + logInToInstanceErrorForText: instanceNameInSearch }) } finally { store.set({logInToInstanceLoading: false}) @@ -58,8 +58,7 @@ export async function logInToInstance () { } async function registerNewInstance (code) { - let currentRegisteredInstanceName = store.get('currentRegisteredInstanceName') - let currentRegisteredInstance = store.get('currentRegisteredInstance') + let { currentRegisteredInstanceName, currentRegisteredInstance } = store.get() let instanceData = await getAccessTokenFromAuthCode( currentRegisteredInstanceName, currentRegisteredInstance.client_id, @@ -67,9 +66,7 @@ async function registerNewInstance (code) { code, REDIRECT_URI ) - let loggedInInstances = store.get('loggedInInstances') - let loggedInInstancesInOrder = store.get('loggedInInstancesInOrder') - let instanceThemes = store.get('instanceThemes') + let { loggedInInstances, loggedInInstancesInOrder, instanceThemes } = store.get() instanceThemes[currentRegisteredInstanceName] = 'default' loggedInInstances[currentRegisteredInstanceName] = instanceData if (!loggedInInstancesInOrder.includes(currentRegisteredInstanceName)) { diff --git a/routes/_actions/block.js b/routes/_actions/block.js index 075877577..850cce060 100644 --- a/routes/_actions/block.js +++ b/routes/_actions/block.js @@ -4,13 +4,12 @@ import { toast } from '../_utils/toast' import { updateProfileAndRelationship } from './accounts' export async function setAccountBlocked (accountId, block, toastOnSuccess) { - let instanceName = store.get('currentInstance') - let accessToken = store.get('accessToken') + let { currentInstance, accessToken } = store.get() try { if (block) { - await blockAccount(instanceName, accessToken, accountId) + await blockAccount(currentInstance, accessToken, accountId) } else { - await unblockAccount(instanceName, accessToken, accountId) + await unblockAccount(currentInstance, accessToken, accountId) } await updateProfileAndRelationship(accountId) if (toastOnSuccess) { diff --git a/routes/_actions/compose.js b/routes/_actions/compose.js index ae933f9d3..5a763d11a 100644 --- a/routes/_actions/compose.js +++ b/routes/_actions/compose.js @@ -7,12 +7,12 @@ import { emit } from '../_utils/eventBus' import { putMediaDescription } from '../_api/media' export async function insertHandleForReply (statusId) { - let instanceName = store.get('currentInstance') - let status = await getStatusFromDatabase(instanceName, statusId) - let verifyCredentials = store.get('currentVerifyCredentials') + let { currentInstance } = store.get() + let status = await getStatusFromDatabase(currentInstance, statusId) + let { currentVerifyCredentials } = store.get() let originalStatus = status.reblog || status let accounts = [originalStatus.account].concat(originalStatus.mentions || []) - .filter(account => account.id !== verifyCredentials.id) + .filter(account => account.id !== currentVerifyCredentials.id) if (!store.getComposeData(statusId, 'text') && accounts.length) { store.setComposeData(statusId, { text: accounts.map(account => `@${account.acct} `).join('') @@ -23,9 +23,7 @@ export async function insertHandleForReply (statusId) { export async function postStatus (realm, text, inReplyToId, mediaIds, sensitive, spoilerText, visibility, mediaDescriptions = [], inReplyToUuid) { - let instanceName = store.get('currentInstance') - let accessToken = store.get('accessToken') - let online = store.get('online') + let { currentInstance, accessToken, online } = store.get() if (!online) { toast.say('You cannot post while offline') @@ -37,11 +35,11 @@ export async function postStatus (realm, text, inReplyToId, mediaIds, }) try { await Promise.all(mediaDescriptions.map(async (description, i) => { - return description && putMediaDescription(instanceName, accessToken, mediaIds[i], description) + return description && putMediaDescription(currentInstance, accessToken, mediaIds[i], description) })) - let status = await postStatusToServer(instanceName, accessToken, text, + let status = await postStatusToServer(currentInstance, accessToken, text, inReplyToId, mediaIds, sensitive, spoilerText, visibility) - addStatusOrNotification(instanceName, 'home', status) + addStatusOrNotification(currentInstance, 'home', status) store.clearComposeData(realm) emit('postedStatus', realm, inReplyToUuid) } catch (e) { @@ -61,12 +59,16 @@ export async function insertUsername (realm, username, startIndex, endIndex) { } export async function clickSelectedAutosuggestionUsername (realm) { - let selectionStart = store.get('composeSelectionStart') - let searchText = store.get('composeAutosuggestionSearchText') - let selection = store.get('composeAutosuggestionSelected') || 0 - let account = store.get('composeAutosuggestionSearchResults')[selection] - let startIndex = selectionStart - searchText.length - let endIndex = selectionStart + let { + composeSelectionStart, + composeAutosuggestionSearchText, + composeAutosuggestionSelected, + composeAutosuggestionSearchResults + } = store.get() + composeAutosuggestionSelected = composeAutosuggestionSelected || 0 + let account = composeAutosuggestionSearchResults[composeAutosuggestionSelected] + let startIndex = composeSelectionStart - composeAutosuggestionSearchText.length + let endIndex = composeSelectionStart await insertUsername(realm, account.acct, startIndex, endIndex) } @@ -96,8 +98,8 @@ export function setReplyVisibility (realm, replyVisibility) { if (typeof postPrivacy !== 'undefined') { return // user has already set the postPrivacy } - let verifyCredentials = store.get('currentVerifyCredentials') - let defaultVisibility = verifyCredentials.source.privacy + let { currentVerifyCredentials } = store.get() + let defaultVisibility = currentVerifyCredentials.source.privacy let visibility = PRIVACY_LEVEL[replyVisibility] < PRIVACY_LEVEL[defaultVisibility] ? replyVisibility : defaultVisibility diff --git a/routes/_actions/delete.js b/routes/_actions/delete.js index a127b45b6..edc6a823f 100644 --- a/routes/_actions/delete.js +++ b/routes/_actions/delete.js @@ -3,10 +3,9 @@ import { deleteStatus } from '../_api/delete' import { toast } from '../_utils/toast' export async function doDeleteStatus (statusId) { - let instanceName = store.get('currentInstance') - let accessToken = store.get('accessToken') + let { currentInstance, accessToken } = store.get() try { - await deleteStatus(instanceName, accessToken, statusId) + await deleteStatus(currentInstance, accessToken, statusId) toast.say('Status deleted.') } catch (e) { console.error(e) diff --git a/routes/_actions/emoji.js b/routes/_actions/emoji.js index 624882068..d63a6a2ad 100644 --- a/routes/_actions/emoji.js +++ b/routes/_actions/emoji.js @@ -12,7 +12,7 @@ export async function updateCustomEmojiForInstance (instanceName) { () => getCustomEmojiFromDatabase(instanceName), emoji => setCustomEmojiInDatabase(instanceName, emoji), emoji => { - let customEmoji = store.get('customEmoji') + let { customEmoji } = store.get() customEmoji[instanceName] = emoji store.set({customEmoji: customEmoji}) } @@ -20,7 +20,8 @@ export async function updateCustomEmojiForInstance (instanceName) { } export function insertEmoji (realm, emoji) { - let idx = store.get('composeSelectionStart') || 0 + let { composeSelectionStart } = store.get() + let idx = composeSelectionStart || 0 let oldText = store.getComposeData(realm, 'text') || '' let pre = oldText.substring(0, idx) let post = oldText.substring(idx) @@ -37,11 +38,15 @@ export function insertEmojiAtPosition (realm, emoji, startIndex, endIndex) { } export async function clickSelectedAutosuggestionEmoji (realm) { - let selectionStart = store.get('composeSelectionStart') - let searchText = store.get('composeAutosuggestionSearchText') - let selection = store.get('composeAutosuggestionSelected') || 0 - let emoji = store.get('composeAutosuggestionSearchResults')[selection] - let startIndex = selectionStart - searchText.length - let endIndex = selectionStart + let { + composeSelectionStart, + composeAutosuggestionSearchText, + composeAutosuggestionSelected, + composeAutosuggestionSearchResults + } = store.get() + composeAutosuggestionSelected = composeAutosuggestionSelected || 0 + let emoji = composeAutosuggestionSearchResults[composeAutosuggestionSelected] + let startIndex = composeSelectionStart - composeAutosuggestionSearchText.length + let endIndex = composeSelectionStart await insertEmojiAtPosition(realm, emoji, startIndex, endIndex) } diff --git a/routes/_actions/favorite.js b/routes/_actions/favorite.js index 15f4eb7d1..d667b882f 100644 --- a/routes/_actions/favorite.js +++ b/routes/_actions/favorite.js @@ -6,22 +6,22 @@ import { } from '../_database/timelines/updateStatus' export async function setFavorited (statusId, favorited) { - if (!store.get('online')) { + let { online } = store.get() + if (!online) { toast.say(`You cannot ${favorited ? 'favorite' : 'unfavorite'} while offline.`) return } - let instanceName = store.get('currentInstance') - let accessToken = store.get('accessToken') + let { currentInstance, accessToken } = store.get() let networkPromise = favorited - ? favoriteStatus(instanceName, accessToken, statusId) - : unfavoriteStatus(instanceName, accessToken, statusId) - store.setStatusFavorited(instanceName, statusId, favorited) // optimistic update + ? favoriteStatus(currentInstance, accessToken, statusId) + : unfavoriteStatus(currentInstance, accessToken, statusId) + store.setStatusFavorited(currentInstance, statusId, favorited) // optimistic update try { await networkPromise - await setStatusFavoritedInDatabase(instanceName, statusId, favorited) + await setStatusFavoritedInDatabase(currentInstance, statusId, favorited) } catch (e) { console.error(e) toast.say(`Failed to ${favorited ? 'favorite' : 'unfavorite'}. ` + (e.message || '')) - store.setStatusFavorited(instanceName, statusId, !favorited) // undo optimistic update + store.setStatusFavorited(currentInstance, statusId, !favorited) // undo optimistic update } } diff --git a/routes/_actions/follow.js b/routes/_actions/follow.js index 95751d5ac..ffad433be 100644 --- a/routes/_actions/follow.js +++ b/routes/_actions/follow.js @@ -7,17 +7,16 @@ import { } from '../_database/accountsAndRelationships' export async function setAccountFollowed (accountId, follow, toastOnSuccess) { - let instanceName = store.get('currentInstance') - let accessToken = store.get('accessToken') + let { currentInstance, accessToken } = store.get() try { let account if (follow) { - account = await followAccount(instanceName, accessToken, accountId) + account = await followAccount(currentInstance, accessToken, accountId) } else { - account = await unfollowAccount(instanceName, accessToken, accountId) + account = await unfollowAccount(currentInstance, accessToken, accountId) } await updateProfileAndRelationship(accountId) - let relationship = await getRelationshipFromDatabase(instanceName, accountId) + let relationship = await getRelationshipFromDatabase(currentInstance, accountId) if (toastOnSuccess) { if (follow) { if (account.locked && relationship.requested) { diff --git a/routes/_actions/instances.js b/routes/_actions/instances.js index d1ea08277..377fb77ff 100644 --- a/routes/_actions/instances.js +++ b/routes/_actions/instances.js @@ -14,17 +14,18 @@ import { } from '../_database/meta' export function changeTheme (instanceName, newTheme) { - let instanceThemes = store.get('instanceThemes') + let { instanceThemes } = store.get() instanceThemes[instanceName] = newTheme store.set({instanceThemes: instanceThemes}) store.save() - if (instanceName === store.get('currentInstance')) { + let { currentInstance } = store.get() + if (instanceName === currentInstance) { switchToTheme(newTheme) } } export function switchToInstance (instanceName) { - let instanceThemes = store.get('instanceThemes') + let { instanceThemes } = store.get() store.set({ currentInstance: instanceName, searchResults: null, @@ -35,11 +36,13 @@ export function switchToInstance (instanceName) { } export async function logOutOfInstance (instanceName) { - let loggedInInstances = store.get('loggedInInstances') - let instanceThemes = store.get('instanceThemes') - let loggedInInstancesInOrder = store.get('loggedInInstancesInOrder') - let composeData = store.get('composeData') - let currentInstance = store.get('currentInstance') + let { + loggedInInstances, + instanceThemes, + loggedInInstancesInOrder, + composeData, + currentInstance + } = store.get() loggedInInstancesInOrder.splice(loggedInInstancesInOrder.indexOf(instanceName), 1) let newInstance = instanceName === currentInstance ? loggedInInstancesInOrder[0] @@ -64,13 +67,13 @@ export async function logOutOfInstance (instanceName) { } function setStoreVerifyCredentials (instanceName, thisVerifyCredentials) { - let verifyCredentials = store.get('verifyCredentials') + let { verifyCredentials } = store.get() verifyCredentials[instanceName] = thisVerifyCredentials store.set({verifyCredentials: verifyCredentials}) } export async function updateVerifyCredentialsForInstance (instanceName) { - let loggedInInstances = store.get('loggedInInstances') + let { loggedInInstances } = store.get() let accessToken = loggedInInstances[instanceName].access_token await cacheFirstUpdateAfter( () => getVerifyCredentials(instanceName, accessToken), @@ -81,7 +84,8 @@ export async function updateVerifyCredentialsForInstance (instanceName) { } export async function updateVerifyCredentialsForCurrentInstance () { - await updateVerifyCredentialsForInstance(store.get('currentInstance')) + let { currentInstance } = store.get() + await updateVerifyCredentialsForInstance(currentInstance) } export async function updateInstanceInfo (instanceName) { @@ -90,7 +94,7 @@ export async function updateInstanceInfo (instanceName) { () => getInstanceInfoFromDatabase(instanceName), info => setInstanceInfoInDatabase(instanceName, info), info => { - let instanceInfos = store.get('instanceInfos') + let { instanceInfos } = store.get() instanceInfos[instanceName] = info store.set({instanceInfos: instanceInfos}) } diff --git a/routes/_actions/lists.js b/routes/_actions/lists.js index a2429260a..df510736e 100644 --- a/routes/_actions/lists.js +++ b/routes/_actions/lists.js @@ -7,16 +7,15 @@ import { } from '../_database/meta' export async function updateLists () { - let instanceName = store.get('currentInstance') - let accessToken = store.get('accessToken') + let { currentInstance, accessToken } = store.get() await cacheFirstUpdateAfter( - () => getLists(instanceName, accessToken), - () => getListsFromDatabase(instanceName), - lists => setListsInDatabase(instanceName, lists), + () => getLists(currentInstance, accessToken), + () => getListsFromDatabase(currentInstance), + lists => setListsInDatabase(currentInstance, lists), lists => { - let instanceLists = store.get('instanceLists') - instanceLists[instanceName] = lists + let { instanceLists } = store.get() + instanceLists[currentInstance] = lists store.set({instanceLists: instanceLists}) } ) diff --git a/routes/_actions/media.js b/routes/_actions/media.js index 131f3938e..1a3808f7a 100644 --- a/routes/_actions/media.js +++ b/routes/_actions/media.js @@ -4,11 +4,10 @@ import { toast } from '../_utils/toast' import { scheduleIdleTask } from '../_utils/scheduleIdleTask' export async function doMediaUpload (realm, file) { - let instanceName = store.get('currentInstance') - let accessToken = store.get('accessToken') + let { currentInstance, accessToken } = store.get() store.set({uploadingMedia: true}) try { - let response = await uploadMedia(instanceName, accessToken, file) + let response = await uploadMedia(currentInstance, accessToken, file) let composeMedia = store.getComposeData(realm, 'media') || [] composeMedia.push({ data: response, diff --git a/routes/_actions/mute.js b/routes/_actions/mute.js index a0bc6e476..ff6571f1d 100644 --- a/routes/_actions/mute.js +++ b/routes/_actions/mute.js @@ -4,13 +4,12 @@ import { toast } from '../_utils/toast' import { updateProfileAndRelationship } from './accounts' export async function setAccountMuted (accountId, mute, toastOnSuccess) { - let instanceName = store.get('currentInstance') - let accessToken = store.get('accessToken') + let { currentInstance, accessToken } = store.get() try { if (mute) { - await muteAccount(instanceName, accessToken, accountId) + await muteAccount(currentInstance, accessToken, accountId) } else { - await unmuteAccount(instanceName, accessToken, accountId) + await unmuteAccount(currentInstance, accessToken, accountId) } await updateProfileAndRelationship(accountId) if (toastOnSuccess) { diff --git a/routes/_actions/pinnedStatuses.js b/routes/_actions/pinnedStatuses.js index 87ac664fd..52d37040f 100644 --- a/routes/_actions/pinnedStatuses.js +++ b/routes/_actions/pinnedStatuses.js @@ -9,18 +9,17 @@ import { } from '../_api/pinnedStatuses' export async function updatePinnedStatusesForAccount (accountId) { - let instanceName = store.get('currentInstance') - let accessToken = store.get('accessToken') + let { currentInstance, accessToken } = store.get() await cacheFirstUpdateAfter( - () => getPinnedStatuses(instanceName, accessToken, accountId), - () => getPinnedStatusesFromDatabase(instanceName, accountId), - statuses => insertPinnedStatusesInDatabase(instanceName, accountId, statuses), + () => getPinnedStatuses(currentInstance, accessToken, accountId), + () => getPinnedStatusesFromDatabase(currentInstance, accountId), + statuses => insertPinnedStatusesInDatabase(currentInstance, accountId, statuses), statuses => { - let $pinnedStatuses = store.get('pinnedStatuses') - $pinnedStatuses[instanceName] = $pinnedStatuses[instanceName] || {} - $pinnedStatuses[instanceName][accountId] = statuses - store.set({pinnedStatuses: $pinnedStatuses}) + let { pinnedStatuses } = store.get() + pinnedStatuses[currentInstance] = pinnedStatuses[currentInstance] || {} + pinnedStatuses[currentInstance][accountId] = statuses + store.set({pinnedStatuses: pinnedStatuses}) } ) } diff --git a/routes/_actions/reblog.js b/routes/_actions/reblog.js index 5e91c78ec..b583ef847 100644 --- a/routes/_actions/reblog.js +++ b/routes/_actions/reblog.js @@ -4,22 +4,22 @@ import { reblogStatus, unreblogStatus } from '../_api/reblog' import { setStatusReblogged as setStatusRebloggedInDatabase } from '../_database/timelines/updateStatus' export async function setReblogged (statusId, reblogged) { - if (!store.get('online')) { + let online = store.get() + if (!online) { toast.say(`You cannot ${reblogged ? 'boost' : 'unboost'} while offline.`) return } - let instanceName = store.get('currentInstance') - let accessToken = store.get('accessToken') + let { currentInstance, accessToken } = store.get() let networkPromise = reblogged - ? reblogStatus(instanceName, accessToken, statusId) - : unreblogStatus(instanceName, accessToken, statusId) - store.setStatusReblogged(instanceName, statusId, reblogged) // optimistic update + ? reblogStatus(currentInstance, accessToken, statusId) + : unreblogStatus(currentInstance, accessToken, statusId) + store.setStatusReblogged(currentInstance, statusId, reblogged) // optimistic update try { await networkPromise - await setStatusRebloggedInDatabase(instanceName, statusId, reblogged) + await setStatusRebloggedInDatabase(currentInstance, statusId, reblogged) } catch (e) { console.error(e) toast.say(`Failed to ${reblogged ? 'boost' : 'unboost'}. ` + (e.message || '')) - store.setStatusReblogged(instanceName, statusId, !reblogged) // undo optimistic update + store.setStatusReblogged(currentInstance, statusId, !reblogged) // undo optimistic update } } diff --git a/routes/_actions/search.js b/routes/_actions/search.js index 2fb25d8f6..55a8f2d21 100644 --- a/routes/_actions/search.js +++ b/routes/_actions/search.js @@ -3,14 +3,12 @@ import { toast } from '../_utils/toast' import { search } from '../_api/search' export async function doSearch () { - let instanceName = store.get('currentInstance') - let accessToken = store.get('accessToken') - let queryInSearch = store.get('queryInSearch') + let { currentInstance, accessToken, queryInSearch } = store.get() store.set({searchLoading: true}) try { - let results = await search(instanceName, accessToken, queryInSearch) - let currentQueryInSearch = store.get('queryInSearch') // avoid race conditions - if (currentQueryInSearch === queryInSearch) { + let results = await search(currentInstance, accessToken, queryInSearch) + let { queryInSearch: newQueryInSearch } = store.get() // avoid race conditions + if (newQueryInSearch === queryInSearch) { store.set({ searchResultsForQuery: queryInSearch, searchResults: results diff --git a/routes/_actions/timeline.js b/routes/_actions/timeline.js index 28bcdf4be..c2d322c0d 100644 --- a/routes/_actions/timeline.js +++ b/routes/_actions/timeline.js @@ -60,14 +60,16 @@ export async function addTimelineItemIds (instanceName, timelineName, newIds, ne async function fetchTimelineItemsAndPossiblyFallBack () { mark('fetchTimelineItemsAndPossiblyFallBack') - let timelineName = store.get('currentTimeline') - let instanceName = store.get('currentInstance') - let accessToken = store.get('accessToken') - let lastTimelineItemId = store.get('lastTimelineItemId') - let online = store.get('online') + let { + currentTimeline, + currentInstance, + accessToken, + lastTimelineItemId, + online + } = store.get() - let { items, stale } = await fetchTimelineItems(instanceName, accessToken, timelineName, lastTimelineItemId, online) - addTimelineItems(instanceName, timelineName, items, stale) + let { items, stale } = await fetchTimelineItems(currentInstance, accessToken, currentTimeline, lastTimelineItemId, online) + addTimelineItems(currentInstance, currentTimeline, items, stale) stop('fetchTimelineItemsAndPossiblyFallBack') } @@ -77,10 +79,11 @@ export async function setupTimeline () { // (i.e. via offline mode), then we need to re-fetch // Also do this if it's a thread, because threads change pretty frequently and // we don't have a good way to update them. - - let timelineItemIds = store.get('timelineItemIds') - let timelineItemIdsAreStale = store.get('timelineItemIdsAreStale') - let currentTimeline = store.get('currentTimeline') + let { + timelineItemIds, + timelineItemIdsAreStale, + currentTimeline + } = store.get() if (!timelineItemIds || timelineItemIdsAreStale || currentTimeline.startsWith('status/')) { @@ -109,9 +112,10 @@ export async function showMoreItemsForTimeline (instanceName, timelineName) { } export async function showMoreItemsForCurrentTimeline () { + let { currentInstance, currentTimeline } = store.get() return showMoreItemsForTimeline( - store.get('currentInstance'), - store.get('currentTimeline') + currentInstance, + currentTimeline ) } diff --git a/routes/_components/AccountsListPage.html b/routes/_components/AccountsListPage.html index 73681a10e..73e1f5adf 100644 --- a/routes/_components/AccountsListPage.html +++ b/routes/_components/AccountsListPage.html @@ -34,7 +34,7 @@ export default { async oncreate() { - let accountsFetcher = this.get('accountsFetcher') + let { accountsFetcher } = this.get() try { // TODO: paginate let accounts = await accountsFetcher() diff --git a/routes/_components/IconButton.html b/routes/_components/IconButton.html index 02d4d9fa0..fc166951e 100644 --- a/routes/_components/IconButton.html +++ b/routes/_components/IconButton.html @@ -107,7 +107,8 @@ export default { oncreate() { this.observe('animation', animation => { - if (!animation || this.store.get('reduceMotion')) { + let reduceMotion = this.store.get() + if (!animation || reduceMotion) { return } let svg = this.refs.svg diff --git a/routes/_components/LazyImage.html b/routes/_components/LazyImage.html index 55b629114..39041357c 100644 --- a/routes/_components/LazyImage.html +++ b/routes/_components/LazyImage.html @@ -28,8 +28,8 @@ oncreate() { mark('LazyImage oncreate()') let img = new Image() - let src = this.get('src') - let fallback = this.get('fallback') + let { src } = this.get() + let { fallback } = this.get() img.onload = () => { requestAnimationFrame(() => { this.set({ diff --git a/routes/_components/NavItem.html b/routes/_components/NavItem.html index 9e0848d85..77388a581 100644 --- a/routes/_components/NavItem.html +++ b/routes/_components/NavItem.html @@ -136,7 +136,8 @@ }, methods: { onClick(e) { - if (!this.get('selected')) { + let { selected } = this.get() + if (!selected) { return } e.preventDefault() diff --git a/routes/_components/NonAutoplayImg.html b/routes/_components/NonAutoplayImg.html index b1571634c..be8df07df 100644 --- a/routes/_components/NonAutoplayImg.html +++ b/routes/_components/NonAutoplayImg.html @@ -28,11 +28,8 @@ export default { methods: { onMouseOver(mouseOver) { - if (mouseOver) { - this.refs.node.src = this.get('src') - } else { - this.refs.node.src = this.get('staticSrc') - } + let { src, staticSrc } = this.get() + this.refs.node.src = mouseOver ? src : staticSrc } }, events: { diff --git a/routes/_components/community/PageListItem.html b/routes/_components/community/PageListItem.html index 951b6035b..4bc8ad7f7 100644 --- a/routes/_components/community/PageListItem.html +++ b/routes/_components/community/PageListItem.html @@ -75,9 +75,8 @@ methods: { onPinClick(e) { e.preventDefault() - let currentInstance = this.store.get('currentInstance') - let pinnedPages = this.store.get('pinnedPages') - let href = this.get('href') + let { currentInstance, pinnedPages } = this.store.get() + let { href } = this.get() pinnedPages[currentInstance] = href this.store.set({pinnedPages: pinnedPages}) this.store.save() diff --git a/routes/_components/compose/ComposeAutosuggest.html b/routes/_components/compose/ComposeAutosuggest.html index 8f2ce1593..0dc4bf49d 100644 --- a/routes/_components/compose/ComposeAutosuggest.html +++ b/routes/_components/compose/ComposeAutosuggest.html @@ -59,13 +59,15 @@ // perf improves for input responsiveness this.observe('composeSelectionStart', () => { scheduleIdleTask(() => { - this.set({composeSelectionStartDeferred: this.get('composeSelectionStart')}) + let { composeSelectionStart } = this.get() || {} // TODO: wtf svelte? + this.set({composeSelectionStartDeferred: composeSelectionStart}) }) }) this.observe('composeFocused', (composeFocused) => { let updateFocusedState = () => { scheduleIdleTask(() => { - this.set({composeFocusedDeferred: this.get('composeFocused')}) + let { composeFocused } = this.get() || {} // TODO: wtf svelte? + this.set({composeFocusedDeferred: composeFocused}) }) } @@ -103,11 +105,10 @@ once: once, onClick(item) { this.fire('autosuggestItemSelected') - let realm = this.get('realm') - let selectionStart = this.store.get('composeSelectionStart') - let searchText = this.store.get('composeAutosuggestionSearchText') - let startIndex = selectionStart - searchText.length - let endIndex = selectionStart + let { realm } = this.get() + let { composeSelectionStart, composeAutosuggestionSearchText } = this.store.get() + let startIndex = composeSelectionStart - composeAutosuggestionSearchText.length + let endIndex = composeSelectionStart if (item.acct) { /* no await */ insertUsername(realm, item.acct, startIndex, endIndex) } else { @@ -117,15 +118,15 @@ }, async searchAccounts(searchText) { searchText = searchText.substring(1) - let currentInstance = this.store.get('currentInstance') + let { currentInstance } = this.store.get() let results = await searchAccountsByUsernameInDatabase( currentInstance, searchText, DATABASE_SEARCH_RESULTS_LIMIT) return results.slice(0, SEARCH_RESULTS_LIMIT) }, searchEmoji(searchText) { searchText = searchText.toLowerCase().substring(1) - let customEmoji = this.store.get('currentCustomEmoji') - let results = customEmoji.filter(emoji => emoji.shortcode.toLowerCase().startsWith(searchText)) + let { currentCustomEmoji } = this.store.get() + let results = currentCustomEmoji.filter(emoji => emoji.shortcode.toLowerCase().startsWith(searchText)) .sort((a, b) => a.shortcode.toLowerCase() < b.shortcode.toLowerCase() ? -1 : 1) .slice(0, SEARCH_RESULTS_LIMIT) return results diff --git a/routes/_components/compose/ComposeBox.html b/routes/_components/compose/ComposeBox.html index 740151ad9..bde904df3 100644 --- a/routes/_components/compose/ComposeBox.html +++ b/routes/_components/compose/ComposeBox.html @@ -118,7 +118,7 @@