From a58c52631ed9e2cd3c7c5d531147bedcd946f63e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Mon, 13 May 2024 01:18:04 +0200 Subject: [PATCH] Arrow functions and so MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- package.json | 1 - src/actions/accounts.ts | 6 +- src/actions/auth.ts | 85 ++++-- src/actions/backups.ts | 27 +- src/actions/consumer-auth.ts | 12 +- src/actions/domain-blocks.ts | 4 +- src/actions/export-data.ts | 43 ++- src/actions/external-auth.ts | 14 +- src/actions/familiar-followers.ts | 15 +- src/actions/import-data.ts | 39 ++- src/actions/importer/index.ts | 4 +- src/actions/instance.ts | 12 +- src/actions/media.ts | 14 +- src/actions/modals.ts | 26 +- src/actions/notifications.ts | 9 +- src/actions/oauth.ts | 27 +- src/actions/patron.ts | 70 ----- src/actions/preload.ts | 5 +- src/actions/settings.ts | 6 +- src/actions/status-quotes.ts | 27 +- src/actions/statuses.ts | 20 +- src/actions/streaming.ts | 9 +- src/actions/timelines.ts | 12 +- src/api/__mocks__/index.ts | 5 +- src/api/hooks/accounts/useAccount.ts | 4 +- src/api/hooks/accounts/useAccountList.ts | 20 +- src/api/hooks/accounts/useAccountLookup.ts | 4 +- src/api/hooks/accounts/useFollow.ts | 20 +- src/api/hooks/accounts/usePatronUser.ts | 18 -- src/api/hooks/accounts/useRelationship.ts | 4 +- src/api/hooks/accounts/useRelationships.ts | 9 +- src/api/hooks/admin/useSuggest.ts | 16 +- src/api/hooks/admin/useVerify.ts | 16 +- .../hooks/announcements/useAnnouncements.ts | 9 +- src/api/hooks/groups/useBlockGroupMember.ts | 4 +- .../groups/useCancelMembershipRequest.ts | 4 +- src/api/hooks/groups/useCreateGroup.ts | 4 +- src/api/hooks/groups/useDeleteGroup.ts | 4 +- src/api/hooks/groups/useDeleteGroupStatus.ts | 4 +- src/api/hooks/groups/useDemoteGroupMember.ts | 4 +- src/api/hooks/groups/useGroup.ts | 4 +- src/api/hooks/groups/useGroupMedia.ts | 12 +- src/api/hooks/groups/useGroupMembers.ts | 4 +- .../groups/useGroupMembershipRequests.ts | 4 +- src/api/hooks/groups/useGroupRelationship.ts | 4 +- src/api/hooks/groups/useGroupRelationships.ts | 9 +- src/api/hooks/groups/useGroups.ts | 4 +- src/api/hooks/groups/useJoinGroup.ts | 4 +- src/api/hooks/groups/useLeaveGroup.ts | 4 +- src/api/hooks/groups/usePromoteGroupMember.ts | 4 +- src/api/hooks/groups/useUpdateGroup.ts | 4 +- src/api/hooks/index.ts | 1 - src/api/hooks/statuses/useBookmarkFolder.ts | 4 +- src/api/hooks/statuses/useBookmarkFolders.ts | 4 +- .../hooks/statuses/useCreateBookmarkFolder.ts | 4 +- .../hooks/statuses/useDeleteBookmarkFolder.ts | 4 +- .../hooks/statuses/useUpdateBookmarkFolder.ts | 4 +- src/api/hooks/streaming/useCommunityStream.ts | 5 +- src/api/hooks/streaming/useDirectStream.ts | 4 +- src/api/hooks/streaming/useGroupStream.ts | 7 +- src/api/hooks/streaming/useHashtagStream.ts | 7 +- src/api/hooks/streaming/useListStream.ts | 4 +- src/api/hooks/streaming/usePublicStream.ts | 8 +- src/api/hooks/streaming/useRemoteStream.ts | 5 +- src/api/hooks/streaming/useTimelineStream.ts | 4 +- src/api/hooks/streaming/useUserStream.ts | 10 +- src/api/index.ts | 36 +-- src/build-config-compiletime.ts | 4 +- src/components/account-search.tsx | 4 +- src/components/account.tsx | 12 +- src/components/authorize-reject-buttons.tsx | 90 +++--- src/components/autosuggest-input.tsx | 12 +- src/components/autosuggest-location.tsx | 7 +- src/components/big-card.tsx | 36 ++- src/components/birthday-input.tsx | 84 +++--- .../dropdown-menu/dropdown-menu.tsx | 6 +- src/components/extended-video-player.tsx | 2 +- src/components/gameboy.tsx | 192 ------------- src/components/group-card.tsx | 72 +++-- src/components/helmet.tsx | 4 +- src/components/icon-button.tsx | 2 +- src/components/icon-with-counter.tsx | 22 +- src/components/icon.tsx | 18 +- src/components/list.tsx | 28 +- src/components/loading-screen.tsx | 18 +- src/components/markup.tsx | 6 +- src/components/media-gallery.tsx | 30 +- src/components/modal-root.tsx | 24 +- src/components/outline-box.tsx | 18 +- src/components/pending-items-row.tsx | 66 +++-- src/components/polls/poll-option.tsx | 22 +- src/components/preview-card.tsx | 4 +- src/components/profile-hover-card.tsx | 24 +- src/components/radio.tsx | 24 +- src/components/scroll-top-button.tsx | 4 +- src/components/scrollable-list.tsx | 34 ++- src/components/sidebar-menu.tsx | 8 +- src/components/site-error-boundary.tsx | 26 +- src/components/status-content.tsx | 7 +- src/components/status-hover-card.tsx | 34 +-- src/components/status-list.tsx | 48 ++-- src/components/status-media.tsx | 16 +- src/components/status-reaction-wrapper.tsx | 10 +- src/components/still-image.tsx | 12 +- src/components/ui/banner/banner.tsx | 26 +- src/components/ui/checkbox/checkbox.tsx | 18 +- src/components/ui/counter/counter.tsx | 12 +- src/components/ui/datepicker/datepicker.tsx | 4 +- src/components/ui/file-input/file-input.tsx | 18 +- src/components/ui/streamfield/streamfield.tsx | 10 +- src/components/ui/tag-input/tag.tsx | 22 +- src/components/ui/widget/widget.tsx | 34 ++- src/components/upload-progress.tsx | 30 +- src/entity-store/actions.ts | 133 ++++----- src/entity-store/entities.ts | 2 - src/entity-store/hooks/useBatchedEntities.ts | 18 +- src/entity-store/hooks/useChangeEntity.ts | 8 +- src/entity-store/hooks/useCreateEntity.ts | 13 +- src/entity-store/hooks/useDeleteEntity.ts | 11 +- src/entity-store/hooks/useDismissEntity.ts | 8 +- src/entity-store/hooks/useEntities.ts | 6 +- src/entity-store/hooks/useEntity.ts | 6 +- src/entity-store/hooks/useEntityActions.ts | 6 +- src/entity-store/hooks/useEntityLookup.ts | 6 +- src/entity-store/hooks/useIncrementEntity.ts | 10 +- src/entity-store/hooks/useTransaction.ts | 8 +- src/entity-store/hooks/utils.ts | 4 +- src/entity-store/reducer.ts | 170 ++++++------ src/entity-store/selectors.ts | 27 +- src/entity-store/utils.ts | 10 +- .../account-gallery/components/media-item.tsx | 4 +- src/features/account-timeline/index.tsx | 11 +- src/features/admin/components/dashcounter.tsx | 12 +- src/features/admin/components/report.tsx | 22 +- src/features/admin/moderation-log.tsx | 34 ++- src/features/audio/index.tsx | 28 +- .../components/registration-form.tsx | 4 +- src/features/bookmarks/index.tsx | 4 +- .../chats/components/chat-composer.tsx | 5 +- .../components/chat-message-list.test.tsx | 2 +- .../chats/components/chat-message.tsx | 14 +- .../chats/components/chat-pending-upload.tsx | 12 +- .../chats/components/chat-textarea.tsx | 10 +- src/features/chats/components/chat-upload.tsx | 26 +- src/features/chats/components/ui/pane.tsx | 24 +- src/features/community-timeline/index.tsx | 4 +- .../components/compose-form-button.tsx | 34 ++- .../compose/components/compose-form.tsx | 22 +- .../compose/components/schedule-form.tsx | 5 +- .../compose/components/search-results.tsx | 4 +- src/features/compose/components/search.tsx | 19 +- .../components/text-character-counter.tsx | 22 +- .../compose/components/upload-button.tsx | 5 +- .../editor/plugins/autosuggest-plugin.tsx | 4 +- .../compose/editor/plugins/link-plugin.tsx | 4 +- src/features/compose/util/counter.ts | 5 +- .../crypto-donate/components/crypto-icon.tsx | 20 +- .../crypto-donate/utils/manifest-map.ts | 8 +- src/features/developers/apps/create.tsx | 84 +++--- .../developers/components/indicator.tsx | 24 +- src/features/draft-statuses/builder.tsx | 6 +- src/features/edit-profile/index.tsx | 49 ++-- .../components/emoji-picker-dropdown.tsx | 60 ++-- .../emoji/components/emoji-picker.tsx | 8 +- src/features/emoji/index.ts | 28 +- src/features/emoji/search.ts | 50 ++-- src/features/event/event-discussion.tsx | 54 ++-- src/features/external-login/index.tsx | 12 +- .../components/instance-restrictions.tsx | 18 +- src/features/filters/index.tsx | 4 +- .../group/components/group-member-count.tsx | 32 +-- src/features/group/edit-group.tsx | 4 +- .../group/group-membership-requests.tsx | 16 +- src/features/home-timeline/index.tsx | 4 +- .../landing-timeline/components/logo-text.tsx | 18 +- src/features/notifications/index.tsx | 4 +- .../steps/suggested-accounts-step.tsx | 16 +- .../components/placeholder-chat.tsx | 22 +- src/features/placeholder/utils.ts | 4 +- src/features/public-timeline/index.tsx | 4 +- .../components/crypto-address-input.tsx | 6 +- .../components/footer-link-input.tsx | 6 +- .../components/promo-panel-input.tsx | 6 +- src/features/soapbox-config/index.tsx | 58 ++-- .../components/status-interaction-bar.tsx | 14 +- src/features/status/components/thread.tsx | 56 ++-- src/features/status/index.tsx | 4 +- .../theme-editor/components/palette.tsx | 12 +- src/features/theme-editor/index.tsx | 42 ++- src/features/ui/components/funding-panel.tsx | 76 ------ .../components/instance-moderation-panel.tsx | 12 +- src/features/ui/components/modal-root.tsx | 4 +- .../modals/edit-federation-modal.tsx | 6 +- .../steps/confirmation-step.tsx | 30 +- .../manage-group-modal/steps/details-step.tsx | 9 +- .../modals/missing-description-modal.tsx | 30 +- .../ui/components/modals/reactions-modal.tsx | 2 +- .../modals/report-modal/report-modal.tsx | 6 +- src/features/ui/components/pending-status.tsx | 4 +- .../ui/components/profile-dropdown.tsx | 14 +- .../ui/components/profile-fields-panel.tsx | 20 +- .../ui/components/profile-info-panel.tsx | 7 - src/features/ui/util/async-components.ts | 1 - src/features/ui/util/fullscreen.ts | 8 +- src/features/ui/util/global-hotkeys.tsx | 5 +- .../ui/util/pending-status-builder.ts | 6 +- src/globals.ts | 4 +- src/hooks/forms/useImageField.ts | 4 +- src/hooks/forms/usePreview.ts | 12 +- src/hooks/forms/useTextField.ts | 4 +- src/hooks/useCompose.ts | 5 +- src/hooks/useDraggedFiles.ts | 17 +- src/hooks/useGetState.ts | 4 +- src/hooks/useInstance.ts | 4 +- src/hooks/useLoading.ts | 8 +- src/hooks/useLoggedIn.ts | 5 +- src/hooks/useOwnAccount.ts | 8 +- src/hooks/useSoapboxConfig.ts | 4 +- src/init/soapbox-mount.tsx | 5 +- src/init/soapbox.tsx | 28 +- src/jest/factory.ts | 48 ++-- src/jest/test-helpers.tsx | 9 +- src/messages.ts | 4 +- src/middleware/errors.ts | 5 +- src/middleware/sounds.ts | 20 +- src/normalizers/account.ts | 114 ++++---- src/normalizers/admin-account.ts | 12 +- src/normalizers/admin-report.ts | 12 +- src/normalizers/attachment.ts | 14 +- src/normalizers/chat-message.ts | 14 +- src/normalizers/chat.ts | 8 +- src/normalizers/emoji.ts | 8 +- src/normalizers/group-relationship.ts | 8 +- src/normalizers/group.ts | 38 ++- src/normalizers/history.ts | 8 +- src/normalizers/list.ts | 6 +- src/normalizers/location.ts | 5 +- src/normalizers/notification.ts | 14 +- src/normalizers/soapbox/soapbox-config.ts | 37 ++- src/normalizers/status-edit.ts | 36 ++- src/normalizers/status.ts | 78 +++--- src/normalizers/tag.ts | 16 +- src/pages/admin-page.tsx | 24 +- src/pages/chats-page.tsx | 12 +- src/pages/empty-page.tsx | 18 +- src/pages/home-page.tsx | 5 - src/precheck.ts | 4 +- src/queries/chats.ts | 12 +- src/queries/embed.ts | 6 +- src/queries/search.ts | 6 +- src/queries/suggestions.ts | 4 +- src/queries/trends.ts | 6 +- src/reducers/accounts-meta.ts | 10 +- src/reducers/accounts.ts | 107 ++++---- src/reducers/admin-user-index.ts | 6 +- src/reducers/admin.ts | 59 ++-- src/reducers/aliases.ts | 6 +- src/reducers/auth.ts | 38 ++- src/reducers/backups.tsx | 18 +- src/reducers/compose-event.ts | 6 +- src/reducers/compose.ts | 16 +- src/reducers/contexts.ts | 26 +- src/reducers/conversations.ts | 6 +- src/reducers/custom-emojis.ts | 6 +- src/reducers/domain-lists.ts | 6 +- src/reducers/draft-statuses.ts | 11 +- src/reducers/dropdown-menu.ts | 6 +- src/reducers/filters.ts | 6 +- src/reducers/followed-tags.ts | 6 +- src/reducers/history.ts | 6 +- src/reducers/index.ts | 2 - src/reducers/instance.ts | 10 +- src/reducers/list-adder.ts | 6 +- src/reducers/list-editor.ts | 6 +- src/reducers/lists.ts | 6 +- src/reducers/locations.ts | 11 +- src/reducers/me.ts | 6 +- src/reducers/meta.ts | 7 +- src/reducers/modals.ts | 6 +- src/reducers/mutes.ts | 6 +- src/reducers/notifications.ts | 39 ++- src/reducers/onboarding.ts | 6 +- src/reducers/patron.ts | 50 ---- src/reducers/pending-statuses.ts | 11 +- src/reducers/polls.ts | 17 +- src/reducers/profile-hover-card.ts | 6 +- src/reducers/push-notifications.ts | 6 +- src/reducers/relationships.ts | 11 +- src/reducers/reports.ts | 6 +- src/reducers/scheduled-statuses.ts | 6 +- src/reducers/search.ts | 25 +- src/reducers/security.ts | 24 +- src/reducers/settings.ts | 9 +- src/reducers/sidebar.ts | 6 +- src/reducers/soapbox.ts | 6 +- src/reducers/status-hover-card.ts | 6 +- src/reducers/status-lists.ts | 17 +- src/reducers/statuses.ts | 36 ++- src/reducers/suggestions.ts | 36 ++- src/reducers/tags.ts | 6 +- src/reducers/timelines.ts | 60 ++-- src/reducers/trending-statuses.ts | 11 +- src/reducers/trends.ts | 6 +- src/reducers/user-lists.ts | 43 ++- src/schemas/card.ts | 10 +- src/schemas/index.ts | 1 - src/schemas/patron.ts | 15 - src/schemas/relay.ts | 4 +- src/schemas/rule.ts | 10 +- src/schemas/status.ts | 26 +- src/schemas/utils.ts | 17 +- src/selectors/index.ts | 258 +++++++++--------- src/sentry.ts | 23 +- src/service-worker/sw.ts | 17 +- src/settings.ts | 9 +- src/storage/kv-store.ts | 23 +- src/toast.test.tsx | 186 +++++++------ src/utils/accounts.ts | 20 +- src/utils/auth.ts | 41 ++- src/utils/badges.ts | 4 +- src/utils/base64.ts | 4 +- src/utils/chats.ts | 10 +- src/utils/colors.ts | 30 +- src/utils/comparators.ts | 8 +- src/utils/config-db.ts | 15 +- src/utils/download.ts | 4 +- src/utils/emoji-reacts.ts | 24 +- src/utils/errors.ts | 5 +- src/utils/features.ts | 48 +++- src/utils/html.ts | 12 +- src/utils/input.ts | 12 +- src/utils/legacy.ts | 59 ---- src/utils/media-aspect-ratio.ts | 18 +- src/utils/normalizers.ts | 24 +- src/utils/numbers.tsx | 21 +- src/utils/permissions.ts | 18 +- src/utils/queries.ts | 14 +- src/utils/quirks.ts | 34 +-- src/utils/resize-image.ts | 10 +- src/utils/rich-content.ts | 4 +- src/utils/rtl.ts | 8 +- src/utils/state.ts | 20 +- src/utils/static.ts | 6 +- src/utils/status.ts | 30 +- src/utils/strings.ts | 4 +- src/utils/sw.ts | 8 +- src/utils/tailwind.ts | 17 +- src/utils/theme.ts | 39 +-- src/utils/timelines.ts | 8 +- tailwind/colors.ts | 10 +- vite.config.ts | 3 - yarn.lock | 26 +- 352 files changed, 2894 insertions(+), 3693 deletions(-) delete mode 100644 src/actions/patron.ts delete mode 100644 src/api/hooks/accounts/usePatronUser.ts delete mode 100644 src/components/gameboy.tsx delete mode 100644 src/features/ui/components/funding-panel.tsx delete mode 100644 src/reducers/patron.ts delete mode 100644 src/schemas/patron.ts diff --git a/package.json b/package.json index 155ed1933..64d1b3ef3 100644 --- a/package.json +++ b/package.json @@ -71,7 +71,6 @@ "@reduxjs/toolkit": "^2.0.1", "@sentry/browser": "^7.74.1", "@sentry/react": "^7.74.1", - "@soapbox.pub/wasmboy": "^0.8.0", "@tabler/icons": "^3.1.0", "@tailwindcss/aspect-ratio": "^0.4.2", "@tailwindcss/forms": "^0.5.7", diff --git a/src/actions/accounts.ts b/src/actions/accounts.ts index dd4754fe6..75b6c83db 100644 --- a/src/actions/accounts.ts +++ b/src/actions/accounts.ts @@ -132,9 +132,9 @@ const createAccount = (params: Record) => return api(getState, 'app')('/api/v1/accounts', { method: 'POST', body: JSON.stringify(params), - }).then(({ json: token }) => { - return dispatch({ type: ACCOUNT_CREATE_SUCCESS, params, token }); - }).catch(error => { + }).then(({ json: token }) => + dispatch({ type: ACCOUNT_CREATE_SUCCESS, params, token }), + ).catch(error => { dispatch({ type: ACCOUNT_CREATE_FAIL, error, params }); throw error; }); diff --git a/src/actions/auth.ts b/src/actions/auth.ts index 558616416..dfbcc8eea 100644 --- a/src/actions/auth.ts +++ b/src/actions/auth.ts @@ -32,24 +32,24 @@ import { importFetchedAccount } from './importer'; import type { AppDispatch, RootState } from 'soapbox/store'; -export const SWITCH_ACCOUNT = 'SWITCH_ACCOUNT'; +const SWITCH_ACCOUNT = 'SWITCH_ACCOUNT'; -export const AUTH_APP_CREATED = 'AUTH_APP_CREATED'; -export const AUTH_APP_AUTHORIZED = 'AUTH_APP_AUTHORIZED'; -export const AUTH_LOGGED_IN = 'AUTH_LOGGED_IN'; -export const AUTH_LOGGED_OUT = 'AUTH_LOGGED_OUT'; +const AUTH_APP_CREATED = 'AUTH_APP_CREATED'; +const AUTH_APP_AUTHORIZED = 'AUTH_APP_AUTHORIZED'; +const AUTH_LOGGED_IN = 'AUTH_LOGGED_IN'; +const AUTH_LOGGED_OUT = 'AUTH_LOGGED_OUT'; -export const VERIFY_CREDENTIALS_REQUEST = 'VERIFY_CREDENTIALS_REQUEST'; -export const VERIFY_CREDENTIALS_SUCCESS = 'VERIFY_CREDENTIALS_SUCCESS'; -export const VERIFY_CREDENTIALS_FAIL = 'VERIFY_CREDENTIALS_FAIL'; +const VERIFY_CREDENTIALS_REQUEST = 'VERIFY_CREDENTIALS_REQUEST'; +const VERIFY_CREDENTIALS_SUCCESS = 'VERIFY_CREDENTIALS_SUCCESS'; +const VERIFY_CREDENTIALS_FAIL = 'VERIFY_CREDENTIALS_FAIL'; -export const AUTH_ACCOUNT_REMEMBER_REQUEST = 'AUTH_ACCOUNT_REMEMBER_REQUEST'; -export const AUTH_ACCOUNT_REMEMBER_SUCCESS = 'AUTH_ACCOUNT_REMEMBER_SUCCESS'; -export const AUTH_ACCOUNT_REMEMBER_FAIL = 'AUTH_ACCOUNT_REMEMBER_FAIL'; +const AUTH_ACCOUNT_REMEMBER_REQUEST = 'AUTH_ACCOUNT_REMEMBER_REQUEST'; +const AUTH_ACCOUNT_REMEMBER_SUCCESS = 'AUTH_ACCOUNT_REMEMBER_SUCCESS'; +const AUTH_ACCOUNT_REMEMBER_FAIL = 'AUTH_ACCOUNT_REMEMBER_FAIL'; const customApp = custom('app'); -export const messages = defineMessages({ +const messages = defineMessages({ loggedOut: { id: 'auth.logged_out', defaultMessage: 'Logged out.' }, awaitingApproval: { id: 'auth.awaiting_approval', defaultMessage: 'Your account is awaiting approval' }, invalidCredentials: { id: 'auth.invalid_credentials', defaultMessage: 'Wrong username or password' }, @@ -122,7 +122,7 @@ const createUserToken = (username: string, password: string) => .then((token: Record) => dispatch(authLoggedIn(token))); }; -export const otpVerify = (code: string, mfa_token: string) => +const otpVerify = (code: string, mfa_token: string) => (dispatch: AppDispatch, getState: () => RootState) => { const app = getState().auth.app; return api(getState, 'app')('/oauth/mfa/challenge', { @@ -139,7 +139,7 @@ export const otpVerify = (code: string, mfa_token: string) => }).then(({ json: token }) => dispatch(authLoggedIn(token))); }; -export const verifyCredentials = (token: string, accountUrl?: string) => { +const verifyCredentials = (token: string, accountUrl?: string) => { const baseURL = parseBaseURL(accountUrl); return (dispatch: AppDispatch, getState: () => RootState) => { @@ -167,7 +167,7 @@ export const verifyCredentials = (token: string, accountUrl?: string) => { }; }; -export const rememberAuthAccount = (accountUrl: string) => +const rememberAuthAccount = (accountUrl: string) => (dispatch: AppDispatch, getState: () => RootState) => { dispatch({ type: AUTH_ACCOUNT_REMEMBER_REQUEST, accountUrl }); return KVStore.getItemOrError(`authAccount:${accountUrl}`).then(account => { @@ -180,14 +180,14 @@ export const rememberAuthAccount = (accountUrl: string) => }); }; -export const loadCredentials = (token: string, accountUrl: string) => +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)); - }).catch((error: { response: Response }) => { +const logIn = (username: string, password: string) => + (dispatch: AppDispatch) => dispatch(getAuthApp()).then(() => + dispatch(createUserToken(normalizeUsername(username), password)), + ).catch((error: { response: Response }) => { if ((error.response?.json as any)?.error === 'mfa_required') { // If MFA is required, throw the error and handle it in the component. throw error; @@ -200,10 +200,10 @@ export const logIn = (username: string, password: string) => throw error; }); -export const deleteSession = () => +const deleteSession = () => (dispatch: AppDispatch, getState: () => RootState) => api(getState)('/api/sign_out', { method: 'DELETE' }); -export const logOut = () => +const logOut = () => (dispatch: AppDispatch, getState: () => RootState) => { const state = getState(); const account = getLoggedInAccount(state); @@ -232,7 +232,7 @@ export const logOut = () => }); }; -export const switchAccount = (accountId: string, background = false) => +const switchAccount = (accountId: string, background = false) => (dispatch: AppDispatch, getState: () => RootState) => { const account = selectAccount(getState(), accountId); // Clear all stored cache from React Query @@ -242,7 +242,7 @@ export const switchAccount = (accountId: string, background = false) => return dispatch({ type: SWITCH_ACCOUNT, account, background }); }; -export const fetchOwnAccounts = () => +const fetchOwnAccounts = () => (dispatch: AppDispatch, getState: () => RootState) => { const state = getState(); return state.auth.users.forEach((user) => { @@ -254,7 +254,7 @@ export const fetchOwnAccounts = () => }); }; -export const register = (params: Record) => +const register = (params: Record) => (dispatch: AppDispatch) => { params.fullname = params.username; @@ -266,13 +266,38 @@ export const register = (params: Record) => }); }; -export const fetchCaptcha = () => - (_dispatch: AppDispatch, getState: () => RootState) => { - return api(getState)('/api/pleroma/captcha'); - }; +const fetchCaptcha = () => + (_dispatch: AppDispatch, getState: () => RootState) => api(getState)('/api/pleroma/captcha'); -export const authLoggedIn = (token: Record) => +const authLoggedIn = (token: Record) => (dispatch: AppDispatch) => { dispatch({ type: AUTH_LOGGED_IN, token }); return token; }; + +export { + SWITCH_ACCOUNT, + AUTH_APP_CREATED, + AUTH_APP_AUTHORIZED, + AUTH_LOGGED_IN, + AUTH_LOGGED_OUT, + VERIFY_CREDENTIALS_REQUEST, + VERIFY_CREDENTIALS_SUCCESS, + VERIFY_CREDENTIALS_FAIL, + AUTH_ACCOUNT_REMEMBER_REQUEST, + AUTH_ACCOUNT_REMEMBER_SUCCESS, + AUTH_ACCOUNT_REMEMBER_FAIL, + messages, + otpVerify, + verifyCredentials, + rememberAuthAccount, + loadCredentials, + logIn, + deleteSession, + logOut, + switchAccount, + fetchOwnAccounts, + register, + fetchCaptcha, + authLoggedIn, +}; diff --git a/src/actions/backups.ts b/src/actions/backups.ts index a6aae5aee..0cf5ace85 100644 --- a/src/actions/backups.ts +++ b/src/actions/backups.ts @@ -2,15 +2,15 @@ import api from '../api'; import type { AppDispatch, RootState } from 'soapbox/store'; -export const BACKUPS_FETCH_REQUEST = 'BACKUPS_FETCH_REQUEST'; -export const BACKUPS_FETCH_SUCCESS = 'BACKUPS_FETCH_SUCCESS'; -export const BACKUPS_FETCH_FAIL = 'BACKUPS_FETCH_FAIL'; +const BACKUPS_FETCH_REQUEST = 'BACKUPS_FETCH_REQUEST'; +const BACKUPS_FETCH_SUCCESS = 'BACKUPS_FETCH_SUCCESS'; +const BACKUPS_FETCH_FAIL = 'BACKUPS_FETCH_FAIL'; -export const BACKUPS_CREATE_REQUEST = 'BACKUPS_CREATE_REQUEST'; -export const BACKUPS_CREATE_SUCCESS = 'BACKUPS_CREATE_SUCCESS'; -export const BACKUPS_CREATE_FAIL = 'BACKUPS_CREATE_FAIL'; +const BACKUPS_CREATE_REQUEST = 'BACKUPS_CREATE_REQUEST'; +const BACKUPS_CREATE_SUCCESS = 'BACKUPS_CREATE_SUCCESS'; +const BACKUPS_CREATE_FAIL = 'BACKUPS_CREATE_FAIL'; -export const fetchBackups = () => +const fetchBackups = () => (dispatch: AppDispatch, getState: () => RootState) => { dispatch({ type: BACKUPS_FETCH_REQUEST }); return api(getState)('/api/v1/pleroma/backups').then(({ json: backups }) => @@ -20,7 +20,7 @@ export const fetchBackups = () => }); }; -export const createBackup = () => +const createBackup = () => (dispatch: AppDispatch, getState: () => RootState) => { dispatch({ type: BACKUPS_CREATE_REQUEST }); return api(getState)('/api/v1/pleroma/backups').then(({ json: backups }) => @@ -29,3 +29,14 @@ export const createBackup = () => dispatch({ type: BACKUPS_CREATE_FAIL, error }); }); }; + +export { + BACKUPS_FETCH_REQUEST, + BACKUPS_FETCH_SUCCESS, + BACKUPS_FETCH_FAIL, + BACKUPS_CREATE_REQUEST, + BACKUPS_CREATE_SUCCESS, + BACKUPS_CREATE_FAIL, + fetchBackups, + createBackup, +}; diff --git a/src/actions/consumer-auth.ts b/src/actions/consumer-auth.ts index ee0e96ab4..6284408a9 100644 --- a/src/actions/consumer-auth.ts +++ b/src/actions/consumer-auth.ts @@ -9,8 +9,8 @@ import { createApp } from './apps'; import type { AppDispatch, RootState } from 'soapbox/store'; -const createProviderApp = () => { - return async(dispatch: AppDispatch, getState: () => RootState) => { +const createProviderApp = () => + async(dispatch: AppDispatch, getState: () => RootState) => { const scopes = getScopes(getState()); const params = { @@ -22,10 +22,9 @@ const createProviderApp = () => { return dispatch(createApp(params)); }; -}; -export const prepareRequest = (provider: string) => { - return async(dispatch: AppDispatch, getState: () => RootState) => { +const prepareRequest = (provider: string) => + async(dispatch: AppDispatch, getState: () => RootState) => { const baseURL = isURL(BuildConfig.BACKEND_URL) ? BuildConfig.BACKEND_URL : ''; const scopes = getScopes(getState()); @@ -47,4 +46,7 @@ export const prepareRequest = (provider: string) => { location.href = `${baseURL}/oauth/prepare_request?${query.toString()}`; }; + +export { + prepareRequest, }; diff --git a/src/actions/domain-blocks.ts b/src/actions/domain-blocks.ts index bc47c45c2..455cd5363 100644 --- a/src/actions/domain-blocks.ts +++ b/src/actions/domain-blocks.ts @@ -143,14 +143,14 @@ const expandDomainBlocks = () => }); }; -function selectAccountsByDomain(state: RootState, domain: string): string[] { +const selectAccountsByDomain = (state: RootState, domain: string): string[] => { const store = state.entities[Entities.ACCOUNTS]?.store as EntityStore | undefined; const entries = store ? Object.entries(store) : undefined; const accounts = entries ?.filter(([_, item]) => item && item.acct.endsWith(`@${domain}`)) .map(([_, item]) => item!.id); return accounts || []; -} +}; const expandDomainBlocksRequest = () => ({ type: DOMAIN_BLOCKS_EXPAND_REQUEST, diff --git a/src/actions/export-data.ts b/src/actions/export-data.ts index cbf2f84ba..8e6e7ac14 100644 --- a/src/actions/export-data.ts +++ b/src/actions/export-data.ts @@ -6,17 +6,17 @@ import toast from 'soapbox/toast'; import type { RootState } from 'soapbox/store'; -export const EXPORT_FOLLOWS_REQUEST = 'EXPORT_FOLLOWS_REQUEST'; -export const EXPORT_FOLLOWS_SUCCESS = 'EXPORT_FOLLOWS_SUCCESS'; -export const EXPORT_FOLLOWS_FAIL = 'EXPORT_FOLLOWS_FAIL'; +const EXPORT_FOLLOWS_REQUEST = 'EXPORT_FOLLOWS_REQUEST'; +const EXPORT_FOLLOWS_SUCCESS = 'EXPORT_FOLLOWS_SUCCESS'; +const EXPORT_FOLLOWS_FAIL = 'EXPORT_FOLLOWS_FAIL'; -export const EXPORT_BLOCKS_REQUEST = 'EXPORT_BLOCKS_REQUEST'; -export const EXPORT_BLOCKS_SUCCESS = 'EXPORT_BLOCKS_SUCCESS'; -export const EXPORT_BLOCKS_FAIL = 'EXPORT_BLOCKS_FAIL'; +const EXPORT_BLOCKS_REQUEST = 'EXPORT_BLOCKS_REQUEST'; +const EXPORT_BLOCKS_SUCCESS = 'EXPORT_BLOCKS_SUCCESS'; +const EXPORT_BLOCKS_FAIL = 'EXPORT_BLOCKS_FAIL'; -export const EXPORT_MUTES_REQUEST = 'EXPORT_MUTES_REQUEST'; -export const EXPORT_MUTES_SUCCESS = 'EXPORT_MUTES_SUCCESS'; -export const EXPORT_MUTES_FAIL = 'EXPORT_MUTES_FAIL'; +const EXPORT_MUTES_REQUEST = 'EXPORT_MUTES_REQUEST'; +const EXPORT_MUTES_SUCCESS = 'EXPORT_MUTES_SUCCESS'; +const EXPORT_MUTES_FAIL = 'EXPORT_MUTES_FAIL'; const messages = defineMessages({ blocksSuccess: { id: 'export_data.success.blocks', defaultMessage: 'Blocks exported successfully' }, @@ -37,7 +37,7 @@ type ExportDataActions = { error?: any; } -function fileExport(content: string, fileName: string) { +const fileExport = (content: string, fileName: string) => { const fileToDownload = document.createElement('a'); fileToDownload.setAttribute('href', 'data:text/csv;charset=utf-8,' + encodeURIComponent(content)); @@ -46,7 +46,7 @@ function fileExport(content: string, fileName: string) { document.body.appendChild(fileToDownload); fileToDownload.click(); document.body.removeChild(fileToDownload); -} +}; const listAccounts = (getState: () => RootState) => async(apiResponse: Response & { json: any }) => { const followings = apiResponse.json; @@ -62,7 +62,7 @@ const listAccounts = (getState: () => RootState) => async(apiResponse: Response return Array.from(new Set(accounts)); }; -export const exportFollows = () => (dispatch: React.Dispatch, getState: () => RootState) => { +const exportFollows = () => (dispatch: React.Dispatch, getState: () => RootState) => { dispatch({ type: EXPORT_FOLLOWS_REQUEST }); const me = getState().me; return api(getState)(`/api/v1/accounts/${me}/following?limit=40`) @@ -79,7 +79,7 @@ export const exportFollows = () => (dispatch: React.Dispatch, }); }; -export const exportBlocks = () => (dispatch: React.Dispatch, getState: () => RootState) => { +const exportBlocks = () => (dispatch: React.Dispatch, getState: () => RootState) => { dispatch({ type: EXPORT_BLOCKS_REQUEST }); return api(getState)('/api/v1/blocks?limit=40') .then(listAccounts(getState)) @@ -93,7 +93,7 @@ export const exportBlocks = () => (dispatch: React.Dispatch, }); }; -export const exportMutes = () => (dispatch: React.Dispatch, getState: () => RootState) => { +const exportMutes = () => (dispatch: React.Dispatch, getState: () => RootState) => { dispatch({ type: EXPORT_MUTES_REQUEST }); return api(getState)('/api/v1/mutes?limit=40') .then(listAccounts(getState)) @@ -106,3 +106,18 @@ export const exportMutes = () => (dispatch: React.Dispatch, g dispatch({ type: EXPORT_MUTES_FAIL, error }); }); }; + +export { + EXPORT_FOLLOWS_REQUEST, + EXPORT_FOLLOWS_SUCCESS, + EXPORT_FOLLOWS_FAIL, + EXPORT_BLOCKS_REQUEST, + EXPORT_BLOCKS_SUCCESS, + EXPORT_BLOCKS_FAIL, + EXPORT_MUTES_REQUEST, + EXPORT_MUTES_SUCCESS, + EXPORT_MUTES_FAIL, + exportFollows, + exportBlocks, + exportMutes, +}; diff --git a/src/actions/external-auth.ts b/src/actions/external-auth.ts index 17d56a3b5..cb79da5b9 100644 --- a/src/actions/external-auth.ts +++ b/src/actions/external-auth.ts @@ -19,8 +19,8 @@ import { getFetch } from '../api'; import type { AppDispatch, RootState } from 'soapbox/store'; -const fetchExternalInstance = (baseURL?: string) => { - return getFetch(null, baseURL)('/api/v1/instance') +const fetchExternalInstance = (baseURL?: string) => + getFetch(null, baseURL)('/api/v1/instance') .then(({ json: instance }) => instanceSchema.parse(instance)) .catch(error => { if (error.response?.status === 401) { @@ -31,7 +31,6 @@ const fetchExternalInstance = (baseURL?: string) => { throw error; } }); -}; const createExternalApp = (instance: Instance, baseURL?: string) => (dispatch: AppDispatch, _getState: () => RootState) => { @@ -70,7 +69,7 @@ const externalAuthorize = (instance: Instance, baseURL: string) => }); }; -export const externalLogin = (host: string) => +const externalLogin = (host: string) => (dispatch: AppDispatch) => { const baseURL = parseBaseURL(host) || parseBaseURL(`https://${host}`); @@ -79,7 +78,7 @@ export const externalLogin = (host: string) => }); }; -export const loginWithCode = (code: string) => +const loginWithCode = (code: string) => (dispatch: AppDispatch) => { const { client_id, client_secret, redirect_uri } = JSON.parse(localStorage.getItem('plfe:external:app')!); const baseURL = localStorage.getItem('plfe:external:baseurl')!; @@ -100,3 +99,8 @@ export const loginWithCode = (code: string) => .then((account: { id: string }) => dispatch(switchAccount(account.id))) .then(() => window.location.href = '/'); }; + +export { + externalLogin, + loginWithCode, +}; diff --git a/src/actions/familiar-followers.ts b/src/actions/familiar-followers.ts index 277dbf15f..deb13cdaa 100644 --- a/src/actions/familiar-followers.ts +++ b/src/actions/familiar-followers.ts @@ -7,11 +7,11 @@ import { importFetchedAccounts } from './importer'; import type { APIEntity } from 'soapbox/types/entities'; -export const FAMILIAR_FOLLOWERS_FETCH_REQUEST = 'FAMILIAR_FOLLOWERS_FETCH_REQUEST'; -export const FAMILIAR_FOLLOWERS_FETCH_SUCCESS = 'FAMILIAR_FOLLOWERS_FETCH_SUCCESS'; -export const FAMILIAR_FOLLOWERS_FETCH_FAIL = 'FAMILIAR_FOLLOWERS_FETCH_FAIL'; +const FAMILIAR_FOLLOWERS_FETCH_REQUEST = 'FAMILIAR_FOLLOWERS_FETCH_REQUEST'; +const FAMILIAR_FOLLOWERS_FETCH_SUCCESS = 'FAMILIAR_FOLLOWERS_FETCH_SUCCESS'; +const FAMILIAR_FOLLOWERS_FETCH_FAIL = 'FAMILIAR_FOLLOWERS_FETCH_FAIL'; -export const fetchAccountFamiliarFollowers = (accountId: string) => (dispatch: AppDispatch, getState: () => RootState) => { +const fetchAccountFamiliarFollowers = (accountId: string) => (dispatch: AppDispatch, getState: () => RootState) => { dispatch({ type: FAMILIAR_FOLLOWERS_FETCH_REQUEST, id: accountId, @@ -36,3 +36,10 @@ export const fetchAccountFamiliarFollowers = (accountId: string) => (dispatch: A skipAlert: true, })); }; + +export { + FAMILIAR_FOLLOWERS_FETCH_REQUEST, + FAMILIAR_FOLLOWERS_FETCH_SUCCESS, + FAMILIAR_FOLLOWERS_FETCH_FAIL, + fetchAccountFamiliarFollowers, +}; diff --git a/src/actions/import-data.ts b/src/actions/import-data.ts index e39f22fc5..8568366fb 100644 --- a/src/actions/import-data.ts +++ b/src/actions/import-data.ts @@ -6,17 +6,17 @@ import api from '../api'; import type { RootState } from 'soapbox/store'; -export const IMPORT_FOLLOWS_REQUEST = 'IMPORT_FOLLOWS_REQUEST'; -export const IMPORT_FOLLOWS_SUCCESS = 'IMPORT_FOLLOWS_SUCCESS'; -export const IMPORT_FOLLOWS_FAIL = 'IMPORT_FOLLOWS_FAIL'; +const IMPORT_FOLLOWS_REQUEST = 'IMPORT_FOLLOWS_REQUEST'; +const IMPORT_FOLLOWS_SUCCESS = 'IMPORT_FOLLOWS_SUCCESS'; +const IMPORT_FOLLOWS_FAIL = 'IMPORT_FOLLOWS_FAIL'; -export const IMPORT_BLOCKS_REQUEST = 'IMPORT_BLOCKS_REQUEST'; -export const IMPORT_BLOCKS_SUCCESS = 'IMPORT_BLOCKS_SUCCESS'; -export const IMPORT_BLOCKS_FAIL = 'IMPORT_BLOCKS_FAIL'; +const IMPORT_BLOCKS_REQUEST = 'IMPORT_BLOCKS_REQUEST'; +const IMPORT_BLOCKS_SUCCESS = 'IMPORT_BLOCKS_SUCCESS'; +const IMPORT_BLOCKS_FAIL = 'IMPORT_BLOCKS_FAIL'; -export const IMPORT_MUTES_REQUEST = 'IMPORT_MUTES_REQUEST'; -export const IMPORT_MUTES_SUCCESS = 'IMPORT_MUTES_SUCCESS'; -export const IMPORT_MUTES_FAIL = 'IMPORT_MUTES_FAIL'; +const IMPORT_MUTES_REQUEST = 'IMPORT_MUTES_REQUEST'; +const IMPORT_MUTES_SUCCESS = 'IMPORT_MUTES_SUCCESS'; +const IMPORT_MUTES_FAIL = 'IMPORT_MUTES_FAIL'; type ImportDataActions = { type: typeof IMPORT_FOLLOWS_REQUEST @@ -38,7 +38,7 @@ const messages = defineMessages({ mutesSuccess: { id: 'import_data.success.mutes', defaultMessage: 'Mutes imported successfully' }, }); -export const importFollows = (params: FormData) => +const importFollows = (params: FormData) => (dispatch: React.Dispatch, getState: () => RootState) => { dispatch({ type: IMPORT_FOLLOWS_REQUEST }); return api(getState)('/api/pleroma/follow_import', { @@ -52,7 +52,7 @@ export const importFollows = (params: FormData) => }); }; -export const importBlocks = (params: FormData) => +const importBlocks = (params: FormData) => (dispatch: React.Dispatch, getState: () => RootState) => { dispatch({ type: IMPORT_BLOCKS_REQUEST }); return api(getState)('/api/pleroma/blocks_import', { @@ -66,7 +66,7 @@ export const importBlocks = (params: FormData) => }); }; -export const importMutes = (params: FormData) => +const importMutes = (params: FormData) => (dispatch: React.Dispatch, getState: () => RootState) => { dispatch({ type: IMPORT_MUTES_REQUEST }); return api(getState)('/api/pleroma/mutes_import', { @@ -79,3 +79,18 @@ export const importMutes = (params: FormData) => dispatch({ type: IMPORT_MUTES_FAIL, error }); }); }; + +export { + IMPORT_FOLLOWS_REQUEST, + IMPORT_FOLLOWS_SUCCESS, + IMPORT_FOLLOWS_FAIL, + IMPORT_BLOCKS_REQUEST, + IMPORT_BLOCKS_SUCCESS, + IMPORT_BLOCKS_FAIL, + IMPORT_MUTES_REQUEST, + IMPORT_MUTES_SUCCESS, + IMPORT_MUTES_FAIL, + importFollows, + importBlocks, + importMutes, +}; diff --git a/src/actions/importer/index.ts b/src/actions/importer/index.ts index 43d28e863..c839d0d28 100644 --- a/src/actions/importer/index.ts +++ b/src/actions/importer/index.ts @@ -126,7 +126,7 @@ const importFetchedStatuses = (statuses: APIEntity[]) => (dispatch: AppDispatch) const normalStatuses: APIEntity[] = []; const polls: APIEntity[] = []; - function processStatus(status: APIEntity) { + const processStatus = (status: APIEntity) => { // Skip broken statuses if (isBroken(status)) return; @@ -153,7 +153,7 @@ const importFetchedStatuses = (statuses: APIEntity[]) => (dispatch: AppDispatch) if (status.poll?.id) { polls.push(status.poll); } - } + }; statuses.forEach(processStatus); diff --git a/src/actions/instance.ts b/src/actions/instance.ts index 061769937..d845b887b 100644 --- a/src/actions/instance.ts +++ b/src/actions/instance.ts @@ -9,7 +9,7 @@ import { MASTODON, parseVersion, PLEROMA, REBASED } from 'soapbox/utils/features import api from '../api'; /** Figure out the appropriate instance to fetch depending on the state */ -export const getHost = (state: RootState) => { +const getHost = (state: RootState) => { const accountUrl = getMeUrl(state) || getAuthUserUrl(state) as string; try { @@ -30,7 +30,7 @@ interface InstanceData { host: string | null | undefined; } -export const fetchInstance = createAsyncThunk( +const fetchInstance = createAsyncThunk( 'instance/fetch', async(host, { dispatch, getState, rejectWithValue }) => { try { @@ -48,7 +48,7 @@ export const fetchInstance = createAsyncThunk( +const fetchInstanceV2 = createAsyncThunk( 'instanceV2/fetch', async(host, { getState, rejectWithValue }) => { try { @@ -61,3 +61,9 @@ export const fetchInstanceV2 = createAsyncThunk {}; const fetchMedia = (mediaId: string) => - (dispatch: any, getState: () => RootState) => { - return api(getState)(`/api/v1/media/${mediaId}`); - }; + (dispatch: any, getState: () => RootState) => api(getState)(`/api/v1/media/${mediaId}`); const updateMedia = (mediaId: string, params: Record) => - (dispatch: any, getState: () => RootState) => { - return api(getState)(`/api/v1/media/${mediaId}`, { - method: 'PUT', - body: JSON.stringify(params), - }); - }; + (dispatch: any, getState: () => RootState) => api(getState)(`/api/v1/media/${mediaId}`, { + method: 'PUT', + body: JSON.stringify(params), + }); const uploadMedia = (body: FormData, onUploadProgress: (e: ProgressEvent) => void = noOp) => (dispatch: AppDispatch, getState: () => RootState) => { diff --git a/src/actions/modals.ts b/src/actions/modals.ts index 20ae13f0a..ef3f55a2c 100644 --- a/src/actions/modals.ts +++ b/src/actions/modals.ts @@ -2,16 +2,15 @@ import { AppDispatch } from 'soapbox/store'; import type { ModalType } from 'soapbox/features/ui/components/modal-root'; -export const MODAL_OPEN = 'MODAL_OPEN'; -export const MODAL_CLOSE = 'MODAL_CLOSE'; +const MODAL_OPEN = 'MODAL_OPEN'; +const MODAL_CLOSE = 'MODAL_CLOSE'; /** Open a modal of the given type */ -export function openModal(type: ModalType, props?: any) { - return (dispatch: AppDispatch) => { +const openModal = (type: ModalType, props?: any) => + (dispatch: AppDispatch) => { dispatch(closeModal(type)); dispatch(openModalSuccess(type, props)); }; -} const openModalSuccess = (type: ModalType, props?: any) => ({ type: MODAL_OPEN, @@ -20,9 +19,14 @@ const openModalSuccess = (type: ModalType, props?: any) => ({ }); /** Close the modal */ -export function closeModal(type?: ModalType) { - return { - type: MODAL_CLOSE, - modalType: type, - }; -} +const closeModal = (type?: ModalType) => ({ + type: MODAL_CLOSE, + modalType: type, +}); + +export { + MODAL_OPEN, + MODAL_CLOSE, + openModal, + closeModal, +}; diff --git a/src/actions/notifications.ts b/src/actions/notifications.ts index 789abc718..cc7a9419f 100644 --- a/src/actions/notifications.ts +++ b/src/actions/notifications.ts @@ -178,9 +178,7 @@ const dequeueNotifications = () => dispatch(markReadNotifications()); }; -const excludeTypesFromFilter = (filters: string[]) => { - return NOTIFICATION_TYPES.filter(item => !filters.includes(item)); -}; +const excludeTypesFromFilter = (filters: string[]) => NOTIFICATION_TYPES.filter(item => !filters.includes(item)); const noOp = () => new Promise(f => f(undefined)); @@ -359,12 +357,11 @@ const setFilter = (filterType: FilterType, abort?: boolean) => // Of course Markers don't work properly in Pleroma. // https://git.pleroma.social/pleroma/pleroma/-/issues/2769 const markReadPleroma = (max_id: string | number) => - (dispatch: AppDispatch, getState: () => RootState) => { - return api(getState)('/api/v1/pleroma/notifications/read', { + (dispatch: AppDispatch, getState: () => RootState) => + api(getState)('/api/v1/pleroma/notifications/read', { method: 'POST', body: JSON.stringify({ max_id }), }); - }; const markReadNotifications = () => (dispatch: AppDispatch, getState: () => RootState) => { diff --git a/src/actions/oauth.ts b/src/actions/oauth.ts index 23062dbba..00c82382a 100644 --- a/src/actions/oauth.ts +++ b/src/actions/oauth.ts @@ -12,15 +12,15 @@ import { getFetch } from '../api'; import type { AppDispatch, RootState } from 'soapbox/store'; -export const OAUTH_TOKEN_CREATE_REQUEST = 'OAUTH_TOKEN_CREATE_REQUEST'; -export const OAUTH_TOKEN_CREATE_SUCCESS = 'OAUTH_TOKEN_CREATE_SUCCESS'; -export const OAUTH_TOKEN_CREATE_FAIL = 'OAUTH_TOKEN_CREATE_FAIL'; +const OAUTH_TOKEN_CREATE_REQUEST = 'OAUTH_TOKEN_CREATE_REQUEST'; +const OAUTH_TOKEN_CREATE_SUCCESS = 'OAUTH_TOKEN_CREATE_SUCCESS'; +const OAUTH_TOKEN_CREATE_FAIL = 'OAUTH_TOKEN_CREATE_FAIL'; -export const OAUTH_TOKEN_REVOKE_REQUEST = 'OAUTH_TOKEN_REVOKE_REQUEST'; -export const OAUTH_TOKEN_REVOKE_SUCCESS = 'OAUTH_TOKEN_REVOKE_SUCCESS'; -export const OAUTH_TOKEN_REVOKE_FAIL = 'OAUTH_TOKEN_REVOKE_FAIL'; +const OAUTH_TOKEN_REVOKE_REQUEST = 'OAUTH_TOKEN_REVOKE_REQUEST'; +const OAUTH_TOKEN_REVOKE_SUCCESS = 'OAUTH_TOKEN_REVOKE_SUCCESS'; +const OAUTH_TOKEN_REVOKE_FAIL = 'OAUTH_TOKEN_REVOKE_FAIL'; -export const obtainOAuthToken = (params: Record, baseURL?: string) => +const obtainOAuthToken = (params: Record, baseURL?: string) => (dispatch: AppDispatch) => { dispatch({ type: OAUTH_TOKEN_CREATE_REQUEST, params }); return getFetch(null, baseURL)('/oauth/token', { @@ -35,7 +35,7 @@ export const obtainOAuthToken = (params: Record, bas }); }; -export const revokeOAuthToken = (params: Record) => +const revokeOAuthToken = (params: Record) => (dispatch: AppDispatch, getState: () => RootState) => { dispatch({ type: OAUTH_TOKEN_REVOKE_REQUEST, params }); const baseURL = getBaseURL(getState()); @@ -50,3 +50,14 @@ export const revokeOAuthToken = (params: Record) => throw error; }); }; + +export { + OAUTH_TOKEN_CREATE_REQUEST, + OAUTH_TOKEN_CREATE_SUCCESS, + OAUTH_TOKEN_CREATE_FAIL, + OAUTH_TOKEN_REVOKE_REQUEST, + OAUTH_TOKEN_REVOKE_SUCCESS, + OAUTH_TOKEN_REVOKE_FAIL, + obtainOAuthToken, + revokeOAuthToken, +}; diff --git a/src/actions/patron.ts b/src/actions/patron.ts deleted file mode 100644 index 97a115237..000000000 --- a/src/actions/patron.ts +++ /dev/null @@ -1,70 +0,0 @@ -import api from '../api'; - -import type { AppDispatch, RootState } from 'soapbox/store'; -import type { APIEntity } from 'soapbox/types/entities'; - -const PATRON_INSTANCE_FETCH_REQUEST = 'PATRON_INSTANCE_FETCH_REQUEST'; -const PATRON_INSTANCE_FETCH_SUCCESS = 'PATRON_INSTANCE_FETCH_SUCCESS'; -const PATRON_INSTANCE_FETCH_FAIL = 'PATRON_INSTANCE_FETCH_FAIL'; - -const PATRON_ACCOUNT_FETCH_REQUEST = 'PATRON_ACCOUNT_FETCH_REQUEST'; -const PATRON_ACCOUNT_FETCH_SUCCESS = 'PATRON_ACCOUNT_FETCH_SUCCESS'; -const PATRON_ACCOUNT_FETCH_FAIL = 'PATRON_ACCOUNT_FETCH_FAIL'; - -const fetchPatronInstance = () => - (dispatch: AppDispatch, getState: () => RootState) => { - dispatch({ type: PATRON_INSTANCE_FETCH_REQUEST }); - return api(getState)('/api/patron/v1/instance').then(response => { - dispatch(importFetchedInstance(response.json)); - }).catch(error => { - dispatch(fetchInstanceFail(error)); - }); - }; - -const fetchPatronAccount = (apId: string) => - (dispatch: AppDispatch, getState: () => RootState) => { - apId = encodeURIComponent(apId); - dispatch({ type: PATRON_ACCOUNT_FETCH_REQUEST }); - api(getState)(`/api/patron/v1/accounts/${apId}`).then(response => { - dispatch(importFetchedAccount(response.json)); - }).catch(error => { - dispatch(fetchAccountFail(error)); - }); - }; - -const importFetchedInstance = (instance: APIEntity) => ({ - type: PATRON_INSTANCE_FETCH_SUCCESS, - instance, -}); - -const fetchInstanceFail = (error: unknown) => ({ - type: PATRON_INSTANCE_FETCH_FAIL, - error, - skipAlert: true, -}); - -const importFetchedAccount = (account: APIEntity) => ({ - type: PATRON_ACCOUNT_FETCH_SUCCESS, - account, -}); - -const fetchAccountFail = (error: unknown) => ({ - type: PATRON_ACCOUNT_FETCH_FAIL, - error, - skipAlert: true, -}); - -export { - PATRON_INSTANCE_FETCH_REQUEST, - PATRON_INSTANCE_FETCH_SUCCESS, - PATRON_INSTANCE_FETCH_FAIL, - PATRON_ACCOUNT_FETCH_REQUEST, - PATRON_ACCOUNT_FETCH_SUCCESS, - PATRON_ACCOUNT_FETCH_FAIL, - fetchPatronInstance, - fetchPatronAccount, - importFetchedInstance, - fetchInstanceFail, - importFetchedAccount, - fetchAccountFail, -}; diff --git a/src/actions/preload.ts b/src/actions/preload.ts index 07b0aa0bb..1824afb8f 100644 --- a/src/actions/preload.ts +++ b/src/actions/preload.ts @@ -16,9 +16,8 @@ const decodeUTF8Base64 = (data: string) => { return text; }; -const decodePleromaData = (data: Record) => { - return mapValues(data, base64string => JSON.parse(decodeUTF8Base64(base64string))); -}; +const decodePleromaData = (data: Record) => + mapValues(data, base64string => JSON.parse(decodeUTF8Base64(base64string))); const pleromaDecoder = (json: string) => decodePleromaData(JSON.parse(json)); diff --git a/src/actions/settings.ts b/src/actions/settings.ts index d732c999b..e1b5ac478 100644 --- a/src/actions/settings.ts +++ b/src/actions/settings.ts @@ -127,11 +127,7 @@ const defaultSettings = ImmutableMap({ const getSettings = createSelector([ (state: RootState) => state.soapbox.get('defaultSettings'), (state: RootState) => state.settings, -], (soapboxSettings, settings) => { - return defaultSettings - .mergeDeep(soapboxSettings) - .mergeDeep(settings); -}); +], (soapboxSettings, settings) => defaultSettings.mergeDeep(soapboxSettings).mergeDeep(settings)); interface SettingChangeAction { type: typeof SETTING_CHANGE; diff --git a/src/actions/status-quotes.ts b/src/actions/status-quotes.ts index 1f986a117..d51afe7d9 100644 --- a/src/actions/status-quotes.ts +++ b/src/actions/status-quotes.ts @@ -4,17 +4,17 @@ import { importFetchedStatuses } from './importer'; import type { AppDispatch, RootState } from 'soapbox/store'; -export const STATUS_QUOTES_FETCH_REQUEST = 'STATUS_QUOTES_FETCH_REQUEST'; -export const STATUS_QUOTES_FETCH_SUCCESS = 'STATUS_QUOTES_FETCH_SUCCESS'; -export const STATUS_QUOTES_FETCH_FAIL = 'STATUS_QUOTES_FETCH_FAIL'; +const STATUS_QUOTES_FETCH_REQUEST = 'STATUS_QUOTES_FETCH_REQUEST'; +const STATUS_QUOTES_FETCH_SUCCESS = 'STATUS_QUOTES_FETCH_SUCCESS'; +const STATUS_QUOTES_FETCH_FAIL = 'STATUS_QUOTES_FETCH_FAIL'; -export const STATUS_QUOTES_EXPAND_REQUEST = 'STATUS_QUOTES_EXPAND_REQUEST'; -export const STATUS_QUOTES_EXPAND_SUCCESS = 'STATUS_QUOTES_EXPAND_SUCCESS'; -export const STATUS_QUOTES_EXPAND_FAIL = 'STATUS_QUOTES_EXPAND_FAIL'; +const STATUS_QUOTES_EXPAND_REQUEST = 'STATUS_QUOTES_EXPAND_REQUEST'; +const STATUS_QUOTES_EXPAND_SUCCESS = 'STATUS_QUOTES_EXPAND_SUCCESS'; +const STATUS_QUOTES_EXPAND_FAIL = 'STATUS_QUOTES_EXPAND_FAIL'; const noOp = () => new Promise(f => f(null)); -export const fetchStatusQuotes = (statusId: string) => +const fetchStatusQuotes = (statusId: string) => (dispatch: AppDispatch, getState: () => RootState) => { if (getState().status_lists.getIn([`quotes:${statusId}`, 'isLoading'])) { return dispatch(noOp); @@ -43,7 +43,7 @@ export const fetchStatusQuotes = (statusId: string) => }); }; -export const expandStatusQuotes = (statusId: string) => +const expandStatusQuotes = (statusId: string) => (dispatch: AppDispatch, getState: () => RootState) => { const url = getState().status_lists.getIn([`quotes:${statusId}`, 'next'], null) as string | null; @@ -73,3 +73,14 @@ export const expandStatusQuotes = (statusId: string) => }); }); }; + +export { + STATUS_QUOTES_FETCH_REQUEST, + STATUS_QUOTES_FETCH_SUCCESS, + STATUS_QUOTES_FETCH_FAIL, + STATUS_QUOTES_EXPAND_REQUEST, + STATUS_QUOTES_EXPAND_SUCCESS, + STATUS_QUOTES_EXPAND_FAIL, + fetchStatusQuotes, + expandStatusQuotes, +}; diff --git a/src/actions/statuses.ts b/src/actions/statuses.ts index 268537e7e..cc4543dcf 100644 --- a/src/actions/statuses.ts +++ b/src/actions/statuses.ts @@ -49,12 +49,11 @@ const STATUS_TRANSLATE_UNDO = 'STATUS_TRANSLATE_UNDO'; const STATUS_UNFILTER = 'STATUS_UNFILTER'; -const statusExists = (getState: () => RootState, statusId: string) => { - return (getState().statuses.get(statusId) || null) !== null; -}; +const statusExists = (getState: () => RootState, statusId: string) => + (getState().statuses.get(statusId) || null) !== null; -const createStatus = (params: Record, idempotencyKey: string, statusId: string | null) => { - return (dispatch: AppDispatch, getState: () => RootState) => { +const createStatus = (params: Record, idempotencyKey: string, statusId: string | null) => + (dispatch: AppDispatch, getState: () => RootState) => { dispatch({ type: STATUS_CREATE_REQUEST, params, idempotencyKey, editing: !!statusId }); return api(getState)(statusId === null ? '/api/v1/statuses' : `/api/v1/statuses/${statusId}`, { @@ -93,7 +92,6 @@ const createStatus = (params: Record, idempotencyKey: string, statu throw error; }); }; -}; const editStatus = (id: string) => (dispatch: AppDispatch, getState: () => RootState) => { let status = getState().statuses.get(id)!; @@ -114,8 +112,8 @@ const editStatus = (id: string) => (dispatch: AppDispatch, getState: () => RootS }); }; -const fetchStatus = (id: string) => { - return (dispatch: AppDispatch, getState: () => RootState) => { +const fetchStatus = (id: string) => + (dispatch: AppDispatch, getState: () => RootState) => { const skipLoading = statusExists(getState, id); dispatch({ type: STATUS_FETCH_REQUEST, id, skipLoading }); @@ -128,10 +126,9 @@ const fetchStatus = (id: string) => { dispatch({ type: STATUS_FETCH_FAIL, id, error, skipLoading, skipAlert: true }); }); }; -}; -const deleteStatus = (id: string, withRedraft = false) => { - return (dispatch: AppDispatch, getState: () => RootState) => { +const deleteStatus = (id: string, withRedraft = false) => + (dispatch: AppDispatch, getState: () => RootState) => { if (!isLoggedIn(getState)) return null; let status = getState().statuses.get(id)!; @@ -156,7 +153,6 @@ const deleteStatus = (id: string, withRedraft = false) => { dispatch({ type: STATUS_DELETE_FAIL, params: status, error }); }); }; -}; const updateStatus = (status: APIEntity) => (dispatch: AppDispatch) => dispatch(importFetchedStatus(status)); diff --git a/src/actions/streaming.ts b/src/actions/streaming.ts index 6a413cead..98c34bc0b 100644 --- a/src/actions/streaming.ts +++ b/src/actions/streaming.ts @@ -153,7 +153,7 @@ const connectTimelineStream = ( }; }); -function followStateToRelationship(followState: string) { +const followStateToRelationship = (followState: string) => { switch (followState) { case 'follow_pending': return { following: false, requested: true }; @@ -164,7 +164,7 @@ function followStateToRelationship(followState: string) { default: return {}; } -} +}; interface FollowUpdate { state: 'follow_pending' | 'follow_accept' | 'follow_reject'; @@ -180,8 +180,8 @@ interface FollowUpdate { }; } -function updateFollowRelationships(update: FollowUpdate) { - return (dispatch: AppDispatch, getState: () => RootState) => { +const updateFollowRelationships = (update: FollowUpdate) => + (dispatch: AppDispatch, getState: () => RootState) => { const me = getState().me; const relationship = selectEntity(getState(), Entities.RELATIONSHIPS, update.following.id); @@ -195,7 +195,6 @@ function updateFollowRelationships(update: FollowUpdate) { setTimeout(() => dispatch(importEntities([updated], Entities.RELATIONSHIPS)), 300); } }; -} export { connectTimelineStream, diff --git a/src/actions/timelines.ts b/src/actions/timelines.ts index 164fd0003..de7bff566 100644 --- a/src/actions/timelines.ts +++ b/src/actions/timelines.ts @@ -139,11 +139,8 @@ const clearTimeline = (timeline: string) => const noOp = () => { }; const noOpAsync = () => () => new Promise(f => f(undefined)); -const parseTags = (tags: Record = {}, mode: 'any' | 'all' | 'none') => { - return (tags[mode] || []).map((tag) => { - return tag.value; - }); -}; +const parseTags = (tags: Record = {}, mode: 'any' | 'all' | 'none') => + (tags[mode] || []).map((tag) => tag.value); const deduplicateStatuses = (statuses: any[]) => { const deduplicatedStatuses: any[] = []; @@ -266,14 +263,13 @@ const expandGroupFeaturedTimeline = (id: string) => const expandGroupMediaTimeline = (id: string | number, { maxId }: Record = {}) => expandTimeline(`group:${id}:media`, `/api/v1/timelines/group/${id}`, { max_id: maxId, only_media: true, limit: 40, with_muted: true }); -const expandHashtagTimeline = (hashtag: string, { url, maxId, tags }: Record = {}, done = noOp) => { - return expandTimeline(`hashtag:${hashtag}`, url || `/api/v1/timelines/tag/${hashtag}`, url ? {} : { +const expandHashtagTimeline = (hashtag: string, { url, maxId, tags }: Record = {}, done = noOp) => + expandTimeline(`hashtag:${hashtag}`, url || `/api/v1/timelines/tag/${hashtag}`, url ? {} : { max_id: maxId, any: parseTags(tags, 'any'), all: parseTags(tags, 'all'), none: parseTags(tags, 'none'), }, done); -}; const expandTimelineRequest = (timeline: string, isLoadingMore: boolean) => ({ type: TIMELINE_EXPAND_REQUEST, diff --git a/src/api/__mocks__/index.ts b/src/api/__mocks__/index.ts index 0e6e513cc..08260cb39 100644 --- a/src/api/__mocks__/index.ts +++ b/src/api/__mocks__/index.ts @@ -15,9 +15,8 @@ export const __clear = (): Function[] => mocks = []; export const staticClient = api.staticClient; -export const getLinks = (response: Response): LinkHeader => { - return new LinkHeader(response.headers?.get('link') || undefined); -}; +export const getLinks = (response: Response): LinkHeader => + new LinkHeader(response.headers?.get('link') || undefined); export const getNextLink = (response: Response) => { const nextLink = new LinkHeader(response.headers?.get('link') || undefined); diff --git a/src/api/hooks/accounts/useAccount.ts b/src/api/hooks/accounts/useAccount.ts index ff96b0574..1bc5fcdfe 100644 --- a/src/api/hooks/accounts/useAccount.ts +++ b/src/api/hooks/accounts/useAccount.ts @@ -13,7 +13,7 @@ interface UseAccountOpts { withRelationship?: boolean; } -function useAccount(accountId?: string, opts: UseAccountOpts = {}) { +const useAccount = (accountId?: string, opts: UseAccountOpts = {}) => { const api = useApi(); const history = useHistory(); const features = useFeatures(); @@ -53,6 +53,6 @@ function useAccount(accountId?: string, opts: UseAccountOpts = {}) { isUnavailable, account, }; -} +}; export { useAccount }; \ No newline at end of file diff --git a/src/api/hooks/accounts/useAccountList.ts b/src/api/hooks/accounts/useAccountList.ts index 28cef9d20..f5d74849a 100644 --- a/src/api/hooks/accounts/useAccountList.ts +++ b/src/api/hooks/accounts/useAccountList.ts @@ -11,7 +11,7 @@ interface useAccountListOpts { enabled?: boolean; } -function useAccountList(listKey: string[], entityFn: EntityFn, opts: useAccountListOpts = {}) { +const useAccountList = (listKey: string[], entityFn: EntityFn, opts: useAccountListOpts = {}) => { const { entities, ...rest } = useEntities( [Entities.ACCOUNTS, ...listKey], entityFn, @@ -29,19 +29,19 @@ function useAccountList(listKey: string[], entityFn: EntityFn, opts: useAc })); return { accounts, ...rest }; -} +}; -function useBlocks() { +const useBlocks = () => { const api = useApi(); return useAccountList(['blocks'], () => api('/api/v1/blocks')); -} +}; -function useMutes() { +const useMutes = () => { const api = useApi(); return useAccountList(['mutes'], () => api('/api/v1/mutes')); -} +}; -function useFollowing(accountId: string | undefined) { +const useFollowing = (accountId: string | undefined) => { const api = useApi(); return useAccountList( @@ -49,9 +49,9 @@ function useFollowing(accountId: string | undefined) { () => api(`/api/v1/accounts/${accountId}/following`), { enabled: !!accountId }, ); -} +}; -function useFollowers(accountId: string | undefined) { +const useFollowers = (accountId: string | undefined) => { const api = useApi(); return useAccountList( @@ -59,7 +59,7 @@ function useFollowers(accountId: string | undefined) { () => api(`/api/v1/accounts/${accountId}/followers`), { enabled: !!accountId }, ); -} +}; export { useAccountList, diff --git a/src/api/hooks/accounts/useAccountLookup.ts b/src/api/hooks/accounts/useAccountLookup.ts index 46886f0a8..6f1006e61 100644 --- a/src/api/hooks/accounts/useAccountLookup.ts +++ b/src/api/hooks/accounts/useAccountLookup.ts @@ -13,7 +13,7 @@ interface UseAccountLookupOpts { withRelationship?: boolean; } -function useAccountLookup(acct: string | undefined, opts: UseAccountLookupOpts = {}) { +const useAccountLookup = (acct: string | undefined, opts: UseAccountLookupOpts = {}) => { const api = useApi(); const features = useFeatures(); const history = useHistory(); @@ -49,6 +49,6 @@ function useAccountLookup(acct: string | undefined, opts: UseAccountLookupOpts = isUnavailable, account: account ? { ...account, relationship } : undefined, }; -} +}; export { useAccountLookup }; \ No newline at end of file diff --git a/src/api/hooks/accounts/useFollow.ts b/src/api/hooks/accounts/useFollow.ts index 13bf5efff..c6b73b93c 100644 --- a/src/api/hooks/accounts/useFollow.ts +++ b/src/api/hooks/accounts/useFollow.ts @@ -11,13 +11,13 @@ interface FollowOpts { languages?: string[]; } -function useFollow() { +const useFollow = () => { const api = useApi(); const dispatch = useAppDispatch(); const { isLoggedIn } = useLoggedIn(); const { transaction } = useTransaction(); - function followEffect(accountId: string) { + const followEffect = (accountId: string) => { transaction({ Accounts: { [accountId]: (account) => ({ @@ -32,9 +32,9 @@ function useFollow() { }), }, }); - } + }; - function unfollowEffect(accountId: string) { + const unfollowEffect = (accountId: string) => { transaction({ Accounts: { [accountId]: (account) => ({ @@ -49,9 +49,9 @@ function useFollow() { }), }, }); - } + }; - async function follow(accountId: string, options: FollowOpts = {}) { + const follow = async (accountId: string, options: FollowOpts = {}) => { if (!isLoggedIn) return; followEffect(accountId); @@ -67,9 +67,9 @@ function useFollow() { } catch (e) { unfollowEffect(accountId); } - } + }; - async function unfollow(accountId: string) { + const unfollow = async (accountId: string) => { if (!isLoggedIn) return; unfollowEffect(accountId); @@ -78,7 +78,7 @@ function useFollow() { } catch (e) { followEffect(accountId); } - } + }; return { follow, @@ -86,6 +86,6 @@ function useFollow() { followEffect, unfollowEffect, }; -} +}; export { useFollow }; \ No newline at end of file diff --git a/src/api/hooks/accounts/usePatronUser.ts b/src/api/hooks/accounts/usePatronUser.ts deleted file mode 100644 index c634472e3..000000000 --- a/src/api/hooks/accounts/usePatronUser.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { Entities } from 'soapbox/entity-store/entities'; -import { useEntity } from 'soapbox/entity-store/hooks'; -import { useApi } from 'soapbox/hooks/useApi'; -import { type PatronUser, patronUserSchema } from 'soapbox/schemas'; - -function usePatronUser(url?: string) { - const api = useApi(); - - const { entity: patronUser, ...result } = useEntity( - [Entities.PATRON_USERS, url || ''], - () => api(`/api/patron/v1/accounts/${encodeURIComponent(url!)}`), - { schema: patronUserSchema, enabled: !!url }, - ); - - return { patronUser, ...result }; -} - -export { usePatronUser }; \ No newline at end of file diff --git a/src/api/hooks/accounts/useRelationship.ts b/src/api/hooks/accounts/useRelationship.ts index c16d5c2b8..73f4ef2ab 100644 --- a/src/api/hooks/accounts/useRelationship.ts +++ b/src/api/hooks/accounts/useRelationship.ts @@ -9,7 +9,7 @@ interface UseRelationshipOpts { enabled?: boolean; } -function useRelationship(accountId: string | undefined, opts: UseRelationshipOpts = {}) { +const useRelationship = (accountId: string | undefined, opts: UseRelationshipOpts = {}) => { const api = useApi(); const { enabled = false } = opts; @@ -23,6 +23,6 @@ function useRelationship(accountId: string | undefined, opts: UseRelationshipOpt ); return { relationship, ...result }; -} +}; export { useRelationship }; \ No newline at end of file diff --git a/src/api/hooks/accounts/useRelationships.ts b/src/api/hooks/accounts/useRelationships.ts index bbca01f5a..cafc40b3c 100644 --- a/src/api/hooks/accounts/useRelationships.ts +++ b/src/api/hooks/accounts/useRelationships.ts @@ -4,13 +4,12 @@ import { useLoggedIn } from 'soapbox/hooks'; import { useApi } from 'soapbox/hooks/useApi'; import { type Relationship, relationshipSchema } from 'soapbox/schemas'; -function useRelationships(listKey: string[], ids: string[]) { +const useRelationships = (listKey: string[], ids: string[]) => { const api = useApi(); const { isLoggedIn } = useLoggedIn(); - function fetchRelationships(ids: string[]) { - return api('/api/v1/accounts/relationships', { params: { ids } }); - } + const fetchRelationships = (ids: string[]) => + api('/api/v1/accounts/relationships', { params: { ids } }); const { entityMap: relationships, ...result } = useBatchedEntities( [Entities.RELATIONSHIPS, ...listKey], @@ -20,6 +19,6 @@ function useRelationships(listKey: string[], ids: string[]) { ); return { relationships, ...result }; -} +}; export { useRelationships }; \ No newline at end of file diff --git a/src/api/hooks/admin/useSuggest.ts b/src/api/hooks/admin/useSuggest.ts index 154f965c2..a78cb228d 100644 --- a/src/api/hooks/admin/useSuggest.ts +++ b/src/api/hooks/admin/useSuggest.ts @@ -5,12 +5,12 @@ import { accountIdsToAccts } from 'soapbox/selectors'; import type { Account } from 'soapbox/schemas'; -function useSuggest() { +const useSuggest = () => { const api = useApi(); const getState = useGetState(); const { transaction } = useTransaction(); - function suggestEffect(accountIds: string[], suggested: boolean) { + const suggestEffect = (accountIds: string[], suggested: boolean) => { const updater = (account: Account): Account => { if (account.pleroma) { account.pleroma.is_suggested = suggested; @@ -23,9 +23,9 @@ function useSuggest() { (result, id) => ({ ...result, [id]: updater }), {}), }); - } + }; - async function suggest(accountIds: string[], callbacks?: EntityCallbacks) { + const suggest = async (accountIds: string[], callbacks?: EntityCallbacks) => { const accts = accountIdsToAccts(getState(), accountIds); suggestEffect(accountIds, true); try { @@ -38,9 +38,9 @@ function useSuggest() { callbacks?.onError?.(e); suggestEffect(accountIds, false); } - } + }; - async function unsuggest(accountIds: string[], callbacks?: EntityCallbacks) { + const unsuggest = async (accountIds: string[], callbacks?: EntityCallbacks) => { const accts = accountIdsToAccts(getState(), accountIds); suggestEffect(accountIds, false); try { @@ -53,12 +53,12 @@ function useSuggest() { callbacks?.onError?.(e); suggestEffect(accountIds, true); } - } + }; return { suggest, unsuggest, }; -} +}; export { useSuggest }; \ No newline at end of file diff --git a/src/api/hooks/admin/useVerify.ts b/src/api/hooks/admin/useVerify.ts index b8fcbd13c..0f98ca79e 100644 --- a/src/api/hooks/admin/useVerify.ts +++ b/src/api/hooks/admin/useVerify.ts @@ -5,12 +5,12 @@ import { accountIdsToAccts } from 'soapbox/selectors'; import type { Account } from 'soapbox/schemas'; -function useVerify() { +const useVerify = () => { const api = useApi(); const getState = useGetState(); const { transaction } = useTransaction(); - function verifyEffect(accountIds: string[], verified: boolean) { + const verifyEffect = (accountIds: string[], verified: boolean) => { const updater = (account: Account): Account => { if (account.pleroma) { const tags = account.pleroma.tags.filter((tag) => tag !== 'verified'); @@ -28,9 +28,9 @@ function useVerify() { (result, id) => ({ ...result, [id]: updater }), {}), }); - } + }; - async function verify(accountIds: string[], callbacks?: EntityCallbacks) { + const verify = async (accountIds: string[], callbacks?: EntityCallbacks) => { const accts = accountIdsToAccts(getState(), accountIds); verifyEffect(accountIds, true); try { @@ -43,9 +43,9 @@ function useVerify() { callbacks?.onError?.(e); verifyEffect(accountIds, false); } - } + }; - async function unverify(accountIds: string[], callbacks?: EntityCallbacks) { + const unverify = async (accountIds: string[], callbacks?: EntityCallbacks) => { const accts = accountIdsToAccts(getState(), accountIds); verifyEffect(accountIds, false); try { @@ -58,12 +58,12 @@ function useVerify() { callbacks?.onError?.(e); verifyEffect(accountIds, true); } - } + }; return { verify, unverify, }; -} +}; export { useVerify }; \ No newline at end of file diff --git a/src/api/hooks/announcements/useAnnouncements.ts b/src/api/hooks/announcements/useAnnouncements.ts index 777f913e8..cf767c2d2 100644 --- a/src/api/hooks/announcements/useAnnouncements.ts +++ b/src/api/hooks/announcements/useAnnouncements.ts @@ -10,7 +10,7 @@ const updateReaction = (reaction: AnnouncementReaction, count: number, me?: bool count: overwrite ? count : (reaction.count + count), }); -export const updateReactions = (reactions: AnnouncementReaction[], name: string, count: number, me?: boolean, overwrite?: boolean) => { +const updateReactions = (reactions: AnnouncementReaction[], name: string, count: number, me?: boolean, overwrite?: boolean) => { const idx = reactions.findIndex(reaction => reaction.name === name); if (idx > -1) { @@ -92,8 +92,7 @@ const useAnnouncements = () => { }; }; -function compareAnnouncements(a: Announcement, b: Announcement): number { - return new Date(a.starts_at || a.published_at).getDate() - new Date(b.starts_at || b.published_at).getDate(); -} +const compareAnnouncements = (a: Announcement, b: Announcement): number => + new Date(a.starts_at || a.published_at).getDate() - new Date(b.starts_at || b.published_at).getDate(); -export { useAnnouncements }; +export { updateReactions, useAnnouncements }; diff --git a/src/api/hooks/groups/useBlockGroupMember.ts b/src/api/hooks/groups/useBlockGroupMember.ts index 5155d18c6..b9d30d990 100644 --- a/src/api/hooks/groups/useBlockGroupMember.ts +++ b/src/api/hooks/groups/useBlockGroupMember.ts @@ -3,13 +3,13 @@ import { useEntityActions } from 'soapbox/entity-store/hooks'; import type { Account, Group, GroupMember } from 'soapbox/schemas'; -function useBlockGroupMember(group: Group, account: Account) { +const useBlockGroupMember = (group: Group, account: Account) => { const { createEntity } = useEntityActions( [Entities.GROUP_MEMBERSHIPS, account.id], { post: `/api/v1/groups/${group?.id}/blocks` }, ); return createEntity; -} +}; export { useBlockGroupMember }; \ No newline at end of file diff --git a/src/api/hooks/groups/useCancelMembershipRequest.ts b/src/api/hooks/groups/useCancelMembershipRequest.ts index 967a57bcd..03abf31f1 100644 --- a/src/api/hooks/groups/useCancelMembershipRequest.ts +++ b/src/api/hooks/groups/useCancelMembershipRequest.ts @@ -4,7 +4,7 @@ import { useApi, useOwnAccount } from 'soapbox/hooks'; import type { Group } from 'soapbox/schemas'; -function useCancelMembershipRequest(group: Group) { +const useCancelMembershipRequest = (group: Group) => { const api = useApi(); const { account: me } = useOwnAccount(); @@ -17,6 +17,6 @@ function useCancelMembershipRequest(group: Group) { mutate: createEntity, isSubmitting, }; -} +}; export { useCancelMembershipRequest }; diff --git a/src/api/hooks/groups/useCreateGroup.ts b/src/api/hooks/groups/useCreateGroup.ts index e916067d5..aad37b97f 100644 --- a/src/api/hooks/groups/useCreateGroup.ts +++ b/src/api/hooks/groups/useCreateGroup.ts @@ -15,7 +15,7 @@ interface CreateGroupParams { tags?: string[]; } -function useCreateGroup() { +const useCreateGroup = () => { const api = useApi(); const { createEntity, ...rest } = useCreateEntity([Entities.GROUPS, 'search', ''], (params: CreateGroupParams) => { @@ -32,6 +32,6 @@ function useCreateGroup() { createGroup: createEntity, ...rest, }; -} +}; export { useCreateGroup, type CreateGroupParams }; \ No newline at end of file diff --git a/src/api/hooks/groups/useDeleteGroup.ts b/src/api/hooks/groups/useDeleteGroup.ts index d1b25cccd..9e58250e5 100644 --- a/src/api/hooks/groups/useDeleteGroup.ts +++ b/src/api/hooks/groups/useDeleteGroup.ts @@ -3,7 +3,7 @@ import { useEntityActions } from 'soapbox/entity-store/hooks'; import type { Group } from 'soapbox/schemas'; -function useDeleteGroup() { +const useDeleteGroup = () => { const { deleteEntity, isSubmitting } = useEntityActions( [Entities.GROUPS], { delete: '/api/v1/groups/:id' }, @@ -13,6 +13,6 @@ function useDeleteGroup() { mutate: deleteEntity, isSubmitting, }; -} +}; export { useDeleteGroup }; \ No newline at end of file diff --git a/src/api/hooks/groups/useDeleteGroupStatus.ts b/src/api/hooks/groups/useDeleteGroupStatus.ts index 8f7916dc9..e3f84c609 100644 --- a/src/api/hooks/groups/useDeleteGroupStatus.ts +++ b/src/api/hooks/groups/useDeleteGroupStatus.ts @@ -4,7 +4,7 @@ import { useApi } from 'soapbox/hooks'; import type { Group } from 'soapbox/schemas'; -function useDeleteGroupStatus(group: Group, statusId: string) { +const useDeleteGroupStatus = (group: Group, statusId: string) => { const api = useApi(); const { deleteEntity, isSubmitting } = useDeleteEntity( Entities.STATUSES, @@ -15,6 +15,6 @@ function useDeleteGroupStatus(group: Group, statusId: string) { mutate: deleteEntity, isSubmitting, }; -} +}; export { useDeleteGroupStatus }; \ No newline at end of file diff --git a/src/api/hooks/groups/useDemoteGroupMember.ts b/src/api/hooks/groups/useDemoteGroupMember.ts index db38164b7..6ce4a55f7 100644 --- a/src/api/hooks/groups/useDemoteGroupMember.ts +++ b/src/api/hooks/groups/useDemoteGroupMember.ts @@ -6,7 +6,7 @@ import { groupMemberSchema } from 'soapbox/schemas'; import type { Group, GroupMember } from 'soapbox/schemas'; -function useDemoteGroupMember(group: Group, groupMember: GroupMember) { +const useDemoteGroupMember = (group: Group, groupMember: GroupMember) => { const { createEntity } = useEntityActions( [Entities.GROUP_MEMBERSHIPS, groupMember.id], { post: `/api/v1/groups/${group.id}/demote` }, @@ -14,6 +14,6 @@ function useDemoteGroupMember(group: Group, groupMember: GroupMember) { ); return createEntity; -} +}; export { useDemoteGroupMember }; \ No newline at end of file diff --git a/src/api/hooks/groups/useGroup.ts b/src/api/hooks/groups/useGroup.ts index befe2cf62..832cc795c 100644 --- a/src/api/hooks/groups/useGroup.ts +++ b/src/api/hooks/groups/useGroup.ts @@ -8,7 +8,7 @@ import { type Group, groupSchema } from 'soapbox/schemas'; import { useGroupRelationship } from './useGroupRelationship'; -function useGroup(groupId: string, refetch = true) { +const useGroup = (groupId: string, refetch = true) => { const api = useApi(); const history = useHistory(); @@ -34,6 +34,6 @@ function useGroup(groupId: string, refetch = true) { isUnauthorized, group: group ? { ...group, relationship: relationship || null } : undefined, }; -} +}; export { useGroup }; \ No newline at end of file diff --git a/src/api/hooks/groups/useGroupMedia.ts b/src/api/hooks/groups/useGroupMedia.ts index eba71afa1..3cb0a139d 100644 --- a/src/api/hooks/groups/useGroupMedia.ts +++ b/src/api/hooks/groups/useGroupMedia.ts @@ -6,12 +6,14 @@ import { toSchema } from 'soapbox/utils/normalizers'; const statusSchema = toSchema(normalizeStatus); -function useGroupMedia(groupId: string) { +const useGroupMedia = (groupId: string) => { const api = useApi(); - return useEntities([Entities.STATUSES, 'groupMedia', groupId], () => { - return api(`/api/v1/timelines/group/${groupId}?only_media=true`); - }, { schema: statusSchema }); -} + return useEntities( + [Entities.STATUSES, 'groupMedia', groupId], + () => api(`/api/v1/timelines/group/${groupId}?only_media=true`), + { schema: statusSchema }) + ; +}; export { useGroupMedia }; \ No newline at end of file diff --git a/src/api/hooks/groups/useGroupMembers.ts b/src/api/hooks/groups/useGroupMembers.ts index 42fb39dc4..6395e4b00 100644 --- a/src/api/hooks/groups/useGroupMembers.ts +++ b/src/api/hooks/groups/useGroupMembers.ts @@ -5,7 +5,7 @@ import { GroupRoles } from 'soapbox/schemas/group-member'; import { useApi } from '../../../hooks/useApi'; -function useGroupMembers(groupId: string, role: GroupRoles) { +const useGroupMembers = (groupId: string, role: GroupRoles) => { const api = useApi(); const { entities, ...result } = useEntities( @@ -18,6 +18,6 @@ function useGroupMembers(groupId: string, role: GroupRoles) { ...result, groupMembers: entities, }; -} +}; export { useGroupMembers }; \ No newline at end of file diff --git a/src/api/hooks/groups/useGroupMembershipRequests.ts b/src/api/hooks/groups/useGroupMembershipRequests.ts index a322359fa..db54aeb7f 100644 --- a/src/api/hooks/groups/useGroupMembershipRequests.ts +++ b/src/api/hooks/groups/useGroupMembershipRequests.ts @@ -8,7 +8,7 @@ import { useGroupRelationship } from './useGroupRelationship'; import type { ExpandedEntitiesPath } from 'soapbox/entity-store/hooks/types'; -function useGroupMembershipRequests(groupId: string) { +const useGroupMembershipRequests = (groupId: string) => { const api = useApi(); const path: ExpandedEntitiesPath = [Entities.ACCOUNTS, 'membership_requests', groupId]; @@ -42,6 +42,6 @@ function useGroupMembershipRequests(groupId: string) { reject, ...rest, }; -} +}; export { useGroupMembershipRequests }; \ No newline at end of file diff --git a/src/api/hooks/groups/useGroupRelationship.ts b/src/api/hooks/groups/useGroupRelationship.ts index ad80b3caf..28fce9e2c 100644 --- a/src/api/hooks/groups/useGroupRelationship.ts +++ b/src/api/hooks/groups/useGroupRelationship.ts @@ -5,7 +5,7 @@ import { useEntity } from 'soapbox/entity-store/hooks'; import { useApi } from 'soapbox/hooks'; import { type GroupRelationship, groupRelationshipSchema } from 'soapbox/schemas'; -function useGroupRelationship(groupId: string | undefined) { +const useGroupRelationship = (groupId: string | undefined) => { const api = useApi(); const { entity: groupRelationship, ...result } = useEntity( @@ -21,6 +21,6 @@ function useGroupRelationship(groupId: string | undefined) { groupRelationship, ...result, }; -} +}; export { useGroupRelationship }; \ No newline at end of file diff --git a/src/api/hooks/groups/useGroupRelationships.ts b/src/api/hooks/groups/useGroupRelationships.ts index 78ef51441..60598c2cc 100644 --- a/src/api/hooks/groups/useGroupRelationships.ts +++ b/src/api/hooks/groups/useGroupRelationships.ts @@ -3,13 +3,12 @@ import { useBatchedEntities } from 'soapbox/entity-store/hooks/useBatchedEntitie import { useApi, useLoggedIn } from 'soapbox/hooks'; import { type GroupRelationship, groupRelationshipSchema } from 'soapbox/schemas'; -function useGroupRelationships(listKey: string[], ids: string[]) { +const useGroupRelationships = (listKey: string[], ids: string[]) => { const api = useApi(); const { isLoggedIn } = useLoggedIn(); - function fetchGroupRelationships(ids: string[]) { - return api('/api/v1/groups/relationships', { params: { ids } }); - } + const fetchGroupRelationships = (ids: string[]) => + api('/api/v1/groups/relationships', { params: { ids } }); const { entityMap: relationships, ...result } = useBatchedEntities( [Entities.RELATIONSHIPS, ...listKey], @@ -19,6 +18,6 @@ function useGroupRelationships(listKey: string[], ids: string[]) { ); return { relationships, ...result }; -} +}; export { useGroupRelationships }; \ No newline at end of file diff --git a/src/api/hooks/groups/useGroups.ts b/src/api/hooks/groups/useGroups.ts index c51d5be38..7da4c3039 100644 --- a/src/api/hooks/groups/useGroups.ts +++ b/src/api/hooks/groups/useGroups.ts @@ -6,7 +6,7 @@ import { groupSchema, type Group } from 'soapbox/schemas/group'; import { useGroupRelationships } from './useGroupRelationships'; -function useGroups() { +const useGroups = () => { const api = useApi(); const features = useFeatures(); @@ -29,6 +29,6 @@ function useGroups() { ...result, groups, }; -} +}; export { useGroups }; diff --git a/src/api/hooks/groups/useJoinGroup.ts b/src/api/hooks/groups/useJoinGroup.ts index 0ea9293d9..de635397b 100644 --- a/src/api/hooks/groups/useJoinGroup.ts +++ b/src/api/hooks/groups/useJoinGroup.ts @@ -6,7 +6,7 @@ import { useGroups } from './useGroups'; import type { Group, GroupRelationship } from 'soapbox/schemas'; -function useJoinGroup(group: Group) { +const useJoinGroup = (group: Group) => { const { invalidate } = useGroups(); const { createEntity, isSubmitting } = useEntityActions( @@ -20,6 +20,6 @@ function useJoinGroup(group: Group) { isSubmitting, invalidate, }; -} +}; export { useJoinGroup }; \ No newline at end of file diff --git a/src/api/hooks/groups/useLeaveGroup.ts b/src/api/hooks/groups/useLeaveGroup.ts index e1b11e737..5253da306 100644 --- a/src/api/hooks/groups/useLeaveGroup.ts +++ b/src/api/hooks/groups/useLeaveGroup.ts @@ -6,7 +6,7 @@ import { useGroups } from './useGroups'; import type { Group, GroupRelationship } from 'soapbox/schemas'; -function useLeaveGroup(group: Group) { +const useLeaveGroup = (group: Group) => { const { invalidate } = useGroups(); const { createEntity, isSubmitting } = useEntityActions( @@ -20,6 +20,6 @@ function useLeaveGroup(group: Group) { isSubmitting, invalidate, }; -} +}; export { useLeaveGroup }; diff --git a/src/api/hooks/groups/usePromoteGroupMember.ts b/src/api/hooks/groups/usePromoteGroupMember.ts index 3d23dda62..124df8aee 100644 --- a/src/api/hooks/groups/usePromoteGroupMember.ts +++ b/src/api/hooks/groups/usePromoteGroupMember.ts @@ -6,7 +6,7 @@ import { groupMemberSchema } from 'soapbox/schemas'; import type { Group, GroupMember } from 'soapbox/schemas'; -function usePromoteGroupMember(group: Group, groupMember: GroupMember) { +const usePromoteGroupMember = (group: Group, groupMember: GroupMember) => { const { createEntity } = useEntityActions( [Entities.GROUP_MEMBERSHIPS, groupMember.account.id], { post: `/api/v1/groups/${group.id}/promote` }, @@ -14,6 +14,6 @@ function usePromoteGroupMember(group: Group, groupMember: GroupMember) { ); return createEntity; -} +}; export { usePromoteGroupMember }; \ No newline at end of file diff --git a/src/api/hooks/groups/useUpdateGroup.ts b/src/api/hooks/groups/useUpdateGroup.ts index 9052faa6c..abd09d784 100644 --- a/src/api/hooks/groups/useUpdateGroup.ts +++ b/src/api/hooks/groups/useUpdateGroup.ts @@ -14,7 +14,7 @@ interface UpdateGroupParams { discoverable?: boolean; } -function useUpdateGroup(groupId: string) { +const useUpdateGroup = (groupId: string) => { const api = useApi(); const { createEntity, ...rest } = useCreateEntity([Entities.GROUPS], (params: UpdateGroupParams) => { @@ -33,6 +33,6 @@ function useUpdateGroup(groupId: string) { updateGroup: createEntity, ...rest, }; -} +}; export { useUpdateGroup }; diff --git a/src/api/hooks/index.ts b/src/api/hooks/index.ts index bccb87cb2..d2ea782e8 100644 --- a/src/api/hooks/index.ts +++ b/src/api/hooks/index.ts @@ -10,7 +10,6 @@ export { } from './accounts/useAccountList'; export { useFollow } from './accounts/useFollow'; export { useRelationships } from './accounts/useRelationships'; -export { usePatronUser } from './accounts/usePatronUser'; // Groups export { useBlockGroupMember } from './groups/useBlockGroupMember'; diff --git a/src/api/hooks/statuses/useBookmarkFolder.ts b/src/api/hooks/statuses/useBookmarkFolder.ts index f81d9e7d1..f152827c0 100644 --- a/src/api/hooks/statuses/useBookmarkFolder.ts +++ b/src/api/hooks/statuses/useBookmarkFolder.ts @@ -5,7 +5,7 @@ import { type BookmarkFolder } from 'soapbox/schemas/bookmark-folder'; import { useBookmarkFolders } from './useBookmarkFolders'; -function useBookmarkFolder(folderId?: string) { +const useBookmarkFolder = (folderId?: string) => { const { isError, isFetched, @@ -26,6 +26,6 @@ function useBookmarkFolder(folderId?: string) { isLoading, invalidate, }; -} +}; export { useBookmarkFolder }; diff --git a/src/api/hooks/statuses/useBookmarkFolders.ts b/src/api/hooks/statuses/useBookmarkFolders.ts index efea1def8..c59fe93c9 100644 --- a/src/api/hooks/statuses/useBookmarkFolders.ts +++ b/src/api/hooks/statuses/useBookmarkFolders.ts @@ -4,7 +4,7 @@ import { useApi } from 'soapbox/hooks'; import { useFeatures } from 'soapbox/hooks/useFeatures'; import { bookmarkFolderSchema, type BookmarkFolder } from 'soapbox/schemas/bookmark-folder'; -function useBookmarkFolders() { +const useBookmarkFolders = () => { const api = useApi(); const features = useFeatures(); @@ -20,6 +20,6 @@ function useBookmarkFolders() { ...result, bookmarkFolders, }; -} +}; export { useBookmarkFolders }; diff --git a/src/api/hooks/statuses/useCreateBookmarkFolder.ts b/src/api/hooks/statuses/useCreateBookmarkFolder.ts index 010aa295d..463309b13 100644 --- a/src/api/hooks/statuses/useCreateBookmarkFolder.ts +++ b/src/api/hooks/statuses/useCreateBookmarkFolder.ts @@ -8,7 +8,7 @@ interface CreateBookmarkFolderParams { emoji?: string; } -function useCreateBookmarkFolder() { +const useCreateBookmarkFolder = () => { const api = useApi(); const { createEntity, ...rest } = useCreateEntity( @@ -25,6 +25,6 @@ function useCreateBookmarkFolder() { createBookmarkFolder: createEntity, ...rest, }; -} +}; export { useCreateBookmarkFolder }; diff --git a/src/api/hooks/statuses/useDeleteBookmarkFolder.ts b/src/api/hooks/statuses/useDeleteBookmarkFolder.ts index cd8018c2d..bf0bdc2d4 100644 --- a/src/api/hooks/statuses/useDeleteBookmarkFolder.ts +++ b/src/api/hooks/statuses/useDeleteBookmarkFolder.ts @@ -1,7 +1,7 @@ import { Entities } from 'soapbox/entity-store/entities'; import { useEntityActions } from 'soapbox/entity-store/hooks'; -function useDeleteBookmarkFolder() { +const useDeleteBookmarkFolder = () => { const { deleteEntity, isSubmitting } = useEntityActions( [Entities.BOOKMARK_FOLDERS], { delete: '/api/v1/pleroma/bookmark_folders/:id' }, @@ -11,6 +11,6 @@ function useDeleteBookmarkFolder() { deleteBookmarkFolder: deleteEntity, isSubmitting, }; -} +}; export { useDeleteBookmarkFolder }; diff --git a/src/api/hooks/statuses/useUpdateBookmarkFolder.ts b/src/api/hooks/statuses/useUpdateBookmarkFolder.ts index 7e4992b34..a092cb18b 100644 --- a/src/api/hooks/statuses/useUpdateBookmarkFolder.ts +++ b/src/api/hooks/statuses/useUpdateBookmarkFolder.ts @@ -8,7 +8,7 @@ interface UpdateBookmarkFolderParams { emoji?: string; } -function useUpdateBookmarkFolder(folderId: string) { +const useUpdateBookmarkFolder = (folderId: string) => { const api = useApi(); const { createEntity, ...rest } = useCreateEntity( @@ -25,6 +25,6 @@ function useUpdateBookmarkFolder(folderId: string) { updateBookmarkFolder: createEntity, ...rest, }; -} +}; export { useUpdateBookmarkFolder }; diff --git a/src/api/hooks/streaming/useCommunityStream.ts b/src/api/hooks/streaming/useCommunityStream.ts index ce00d4674..73cc0d5c1 100644 --- a/src/api/hooks/streaming/useCommunityStream.ts +++ b/src/api/hooks/streaming/useCommunityStream.ts @@ -5,14 +5,13 @@ interface UseCommunityStreamOpts { enabled?: boolean; } -function useCommunityStream({ onlyMedia, enabled }: UseCommunityStreamOpts = {}) { - return useTimelineStream( +const useCommunityStream = ({ onlyMedia, enabled }: UseCommunityStreamOpts = {}) => + useTimelineStream( `community${onlyMedia ? ':media' : ''}`, `public:local${onlyMedia ? ':media' : ''}`, undefined, undefined, { enabled }, ); -} export { useCommunityStream }; \ No newline at end of file diff --git a/src/api/hooks/streaming/useDirectStream.ts b/src/api/hooks/streaming/useDirectStream.ts index 972a5f769..e12815fbb 100644 --- a/src/api/hooks/streaming/useDirectStream.ts +++ b/src/api/hooks/streaming/useDirectStream.ts @@ -2,7 +2,7 @@ import { useLoggedIn } from 'soapbox/hooks/useLoggedIn'; import { useTimelineStream } from './useTimelineStream'; -function useDirectStream() { +const useDirectStream = () => { const { isLoggedIn } = useLoggedIn(); return useTimelineStream( @@ -12,6 +12,6 @@ function useDirectStream() { null, { enabled: isLoggedIn }, ); -} +}; export { useDirectStream }; \ No newline at end of file diff --git a/src/api/hooks/streaming/useGroupStream.ts b/src/api/hooks/streaming/useGroupStream.ts index f9db3f69e..5c68bb76e 100644 --- a/src/api/hooks/streaming/useGroupStream.ts +++ b/src/api/hooks/streaming/useGroupStream.ts @@ -1,10 +1,5 @@ import { useTimelineStream } from './useTimelineStream'; -function useGroupStream(groupId: string) { - return useTimelineStream( - `group:${groupId}`, - `group&group=${groupId}`, - ); -} +const useGroupStream = (groupId: string) => useTimelineStream(`group:${groupId}`, `group&group=${groupId}`); export { useGroupStream }; \ No newline at end of file diff --git a/src/api/hooks/streaming/useHashtagStream.ts b/src/api/hooks/streaming/useHashtagStream.ts index 4f9483bad..3a2935dd9 100644 --- a/src/api/hooks/streaming/useHashtagStream.ts +++ b/src/api/hooks/streaming/useHashtagStream.ts @@ -1,10 +1,5 @@ import { useTimelineStream } from './useTimelineStream'; -function useHashtagStream(tag: string) { - return useTimelineStream( - `hashtag:${tag}`, - `hashtag&tag=${tag}`, - ); -} +const useHashtagStream = (tag: string) => useTimelineStream(`hashtag:${tag}`, `hashtag&tag=${tag}`); export { useHashtagStream }; \ No newline at end of file diff --git a/src/api/hooks/streaming/useListStream.ts b/src/api/hooks/streaming/useListStream.ts index 661bdce4f..dc0561767 100644 --- a/src/api/hooks/streaming/useListStream.ts +++ b/src/api/hooks/streaming/useListStream.ts @@ -2,7 +2,7 @@ import { useLoggedIn } from 'soapbox/hooks'; import { useTimelineStream } from './useTimelineStream'; -function useListStream(listId: string) { +const useListStream = (listId: string) => { const { isLoggedIn } = useLoggedIn(); return useTimelineStream( @@ -12,6 +12,6 @@ function useListStream(listId: string) { null, { enabled: isLoggedIn }, ); -} +}; export { useListStream }; \ No newline at end of file diff --git a/src/api/hooks/streaming/usePublicStream.ts b/src/api/hooks/streaming/usePublicStream.ts index 7a6f7f61d..3807c72a0 100644 --- a/src/api/hooks/streaming/usePublicStream.ts +++ b/src/api/hooks/streaming/usePublicStream.ts @@ -4,11 +4,7 @@ interface UsePublicStreamOpts { onlyMedia?: boolean; } -function usePublicStream({ onlyMedia }: UsePublicStreamOpts = {}) { - return useTimelineStream( - `public${onlyMedia ? ':media' : ''}`, - `public${onlyMedia ? ':media' : ''}`, - ); -} +const usePublicStream = ({ onlyMedia }: UsePublicStreamOpts = {}) => + useTimelineStream(`public${onlyMedia ? ':media' : ''}`, `public${onlyMedia ? ':media' : ''}`); export { usePublicStream }; \ No newline at end of file diff --git a/src/api/hooks/streaming/useRemoteStream.ts b/src/api/hooks/streaming/useRemoteStream.ts index 6de560163..cc7497cef 100644 --- a/src/api/hooks/streaming/useRemoteStream.ts +++ b/src/api/hooks/streaming/useRemoteStream.ts @@ -5,11 +5,10 @@ interface UseRemoteStreamOpts { onlyMedia?: boolean; } -function useRemoteStream({ instance, onlyMedia }: UseRemoteStreamOpts) { - return useTimelineStream( +const useRemoteStream = ({ instance, onlyMedia }: UseRemoteStreamOpts) => + useTimelineStream( `remote${onlyMedia ? ':media' : ''}:${instance}`, `public:remote${onlyMedia ? ':media' : ''}&instance=${instance}`, ); -} export { useRemoteStream }; \ No newline at end of file diff --git a/src/api/hooks/streaming/useTimelineStream.ts b/src/api/hooks/streaming/useTimelineStream.ts index 22e9d0cf4..53df1ce9f 100644 --- a/src/api/hooks/streaming/useTimelineStream.ts +++ b/src/api/hooks/streaming/useTimelineStream.ts @@ -4,7 +4,7 @@ import { connectTimelineStream } from 'soapbox/actions/streaming'; import { useAppDispatch, useAppSelector, useInstance } from 'soapbox/hooks'; import { getAccessToken } from 'soapbox/utils/auth'; -function useTimelineStream(...args: Parameters) { +const useTimelineStream = (...args: Parameters) => { // TODO: get rid of streaming.ts and move the actual opts here. const [timelineId, path] = args; const { enabled = true } = args[4] ?? {}; @@ -37,6 +37,6 @@ function useTimelineStream(...args: Parameters) { return { disconnect, }; -} +}; export { useTimelineStream }; \ No newline at end of file diff --git a/src/api/hooks/streaming/useUserStream.ts b/src/api/hooks/streaming/useUserStream.ts index f068b3c1c..e8aa74189 100644 --- a/src/api/hooks/streaming/useUserStream.ts +++ b/src/api/hooks/streaming/useUserStream.ts @@ -7,7 +7,7 @@ import { useTimelineStream } from './useTimelineStream'; import type { AppDispatch } from 'soapbox/store'; -function useUserStream() { +const useUserStream = () => { const { isLoggedIn } = useLoggedIn(); const statContext = useStatContext(); @@ -18,12 +18,10 @@ function useUserStream() { null, { statContext, enabled: isLoggedIn }, ); -} +}; /** Refresh home timeline and notifications. */ -function refresh(dispatch: AppDispatch, done?: () => void) { - return dispatch(expandHomeTimeline({}, () => - dispatch(expandNotifications({}, done)))); -} +const refresh = (dispatch: AppDispatch, done?: () => void) => + dispatch(expandHomeTimeline({}, () => dispatch(expandNotifications({}, done)))); export { useUserStream }; \ No newline at end of file diff --git a/src/api/index.ts b/src/api/index.ts index 512bfd835..1d59e8d0f 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -16,21 +16,17 @@ import { buildFullPath } from 'soapbox/utils/url'; @param {object} response - Fetch API response object @returns {object} Link object */ -export const getLinks = (response: Pick): LinkHeader => { - return new LinkHeader(response.headers?.get('link') || undefined); -}; +const getLinks = (response: Pick): LinkHeader => + new LinkHeader(response.headers?.get('link') || undefined); -export const getNextLink = (response: Pick): string | undefined => { - return getLinks(response).refs.find(link => link.rel === 'next')?.uri; -}; +const getNextLink = (response: Pick): string | undefined => + getLinks(response).refs.find(link => link.rel === 'next')?.uri; -export const getPrevLink = (response: Pick): string | undefined => { - return getLinks(response).refs.find(link => link.rel === 'prev')?.uri; -}; +const getPrevLink = (response: Pick): string | undefined => + getLinks(response).refs.find(link => link.rel === 'prev')?.uri; -const getToken = (state: RootState, authType: string) => { - return authType === 'app' ? getAppToken(state) : getAccessToken(state); -}; +const getToken = (state: RootState, authType: string) => + authType === 'app' ? getAppToken(state) : getAccessToken(state); const getAuthBaseURL = createSelector([ (state: RootState, me: string | false | null) => me ? selectAccount(state, me)?.url : undefined, @@ -40,7 +36,7 @@ const getAuthBaseURL = createSelector([ return baseURL !== window.location.origin ? baseURL : ''; }); -export const getFetch = (accessToken?: string | null, baseURL: string = '') => +const getFetch = (accessToken?: string | null, baseURL: string = '') => ( input: URL | RequestInfo, init?: RequestInit & { params?: Record; onUploadProgress?: (e: ProgressEvent) => void } | undefined, @@ -112,7 +108,7 @@ export const getFetch = (accessToken?: string | null, baseURL: string = '') => * It uses FE_SUBDIRECTORY and parses JSON if possible. * No authorization is needed. */ -export const staticFetch = (input: URL | RequestInfo, init?: RequestInit | undefined) => { +const staticFetch = (input: URL | RequestInfo, init?: RequestInit | undefined) => { const fullPath = buildFullPath(input.toString(), BuildConfig.FE_SUBDIRECTORY); return fetch(fullPath, init).then(async (response) => { @@ -135,7 +131,7 @@ export const staticFetch = (input: URL | RequestInfo, init?: RequestInit | undef * @param {string} authType - Either 'user' or 'app' * @returns {object} Axios instance */ -export const api = (getState: () => RootState, authType: string = 'user') => { +const api = (getState: () => RootState, authType: string = 'user') => { const state = getState(); const accessToken = getToken(state, authType); const me = state.me; @@ -144,4 +140,12 @@ export const api = (getState: () => RootState, authType: string = 'user') => { return getFetch(accessToken, baseURL); }; -export default api; \ No newline at end of file +export { + getLinks, + getNextLink, + getPrevLink, + getFetch, + staticFetch, + api, + api as default, +}; diff --git a/src/build-config-compiletime.ts b/src/build-config-compiletime.ts index e4ccfb943..0a197d16f 100644 --- a/src/build-config-compiletime.ts +++ b/src/build-config-compiletime.ts @@ -24,9 +24,7 @@ const sanitizeURL = (url: string | undefined = ''): string => { } }; -const sanitizeBasename = (path: string | undefined = ''): string => { - return `/${trim(path, '/')}`; -}; +const sanitizeBasename = (path: string | undefined = ''): string => `/${trim(path, '/')}`; const env = { NODE_ENV: NODE_ENV || 'development', diff --git a/src/components/account-search.tsx b/src/components/account-search.tsx index dec244674..98cb596dd 100644 --- a/src/components/account-search.tsx +++ b/src/components/account-search.tsx @@ -23,9 +23,7 @@ const AccountSearch: React.FC = ({ onSelected, ...rest }) => { const [value, setValue] = useState(''); - const isEmpty = (): boolean => { - return !(value.length > 0); - }; + const isEmpty = (): boolean => !(value.length > 0); const clearState = () => { setValue(''); diff --git a/src/components/account.tsx b/src/components/account.tsx index 89350420f..df7aa9d0d 100644 --- a/src/components/account.tsx +++ b/src/components/account.tsx @@ -62,13 +62,11 @@ interface IProfilePopper { children: React.ReactNode; } -const ProfilePopper: React.FC = ({ condition, wrapper, children }) => { - return ( - <> - {condition ? wrapper(children) : children} - - ); -}; +const ProfilePopper: React.FC = ({ condition, wrapper, children }) => ( + <> + {condition ? wrapper(children) : children} + +); export interface IAccount { account: AccountSchema; diff --git a/src/components/authorize-reject-buttons.tsx b/src/components/authorize-reject-buttons.tsx index aa1bd9d74..ac2d8ff2a 100644 --- a/src/components/authorize-reject-buttons.tsx +++ b/src/components/authorize-reject-buttons.tsx @@ -32,11 +32,11 @@ const AuthorizeRejectButtons: React.FC = ({ onAuthorize }, (countdown as number) / 100); }; - function handleAction( + const handleAction = ( present: 'authorizing' | 'rejecting', past: 'authorized' | 'rejected', action: () => Promise | unknown, - ): void { + ): void => { if (state === present) { if (interval.current) { clearInterval(interval.current); @@ -62,7 +62,7 @@ const AuthorizeRejectButtons: React.FC = ({ onAuthorize doAction(); } } - } + }; const handleAuthorize = async () => handleAction('authorizing', 'authorized', onAuthorize); const handleReject = async () => handleAction('rejecting', 'rejected', onReject); @@ -81,15 +81,13 @@ const AuthorizeRejectButtons: React.FC = ({ onAuthorize return {}; }; - useEffect(() => { - return () => { - if (timeout.current) { - clearTimeout(timeout.current); - } - if (interval.current) { - clearInterval(interval.current); - } - }; + useEffect(() => () => { + if (timeout.current) { + clearTimeout(timeout.current); + } + if (interval.current) { + clearInterval(interval.current); + } }, []); switch (state) { @@ -129,15 +127,13 @@ interface IActionEmblem { text: React.ReactNode; } -const ActionEmblem: React.FC = ({ text }) => { - return ( -
- - {text} - -
- ); -}; +const ActionEmblem: React.FC = ({ text }) => ( +
+ + {text} + +
+); interface IAuthorizeRejectButton { theme: 'primary' | 'danger'; @@ -148,33 +144,31 @@ interface IAuthorizeRejectButton { style: React.CSSProperties; } -const AuthorizeRejectButton: React.FC = ({ theme, icon, action, isLoading, style, disabled }) => { - return ( -
-
- -
+const AuthorizeRejectButton: React.FC = ({ theme, icon, action, isLoading, style, disabled }) => ( +
+
+
- ); -}; +
+); export { AuthorizeRejectButtons }; \ No newline at end of file diff --git a/src/components/autosuggest-input.tsx b/src/components/autosuggest-input.tsx index 94e613d36..8956b6b08 100644 --- a/src/components/autosuggest-input.tsx +++ b/src/components/autosuggest-input.tsx @@ -43,9 +43,7 @@ export default class AutosuggestInput extends ImmutablePureComponent { - return this.props.autoSelect ? 0 : -1; - }; + getFirstIndex = () => this.props.autoSelect ? 0 : -1; state = { suggestionsHidden: true, @@ -217,11 +215,9 @@ export default class AutosuggestInput extends ImmutablePureComponent { - return e => { - e.preventDefault(); - this.handleMenuItemAction(item, e); - }; + handleMenuItemClick = (item: MenuItem | null): React.MouseEventHandler => e => { + e.preventDefault(); + this.handleMenuItemAction(item, e); }; renderMenu = () => { diff --git a/src/components/autosuggest-location.tsx b/src/components/autosuggest-location.tsx index ce6575dd6..01ee28a13 100644 --- a/src/components/autosuggest-location.tsx +++ b/src/components/autosuggest-location.tsx @@ -9,7 +9,7 @@ const homeIcon = require('@tabler/icons/outline/home-2.svg'); const mapPinIcon = require('@tabler/icons/outline/map-pin.svg'); const roadIcon = require('@tabler/icons/outline/road.svg'); -export const ADDRESS_ICONS: Record = { +const ADDRESS_ICONS: Record = { house: homeIcon, street: roadIcon, secondary: roadIcon, @@ -38,4 +38,7 @@ const AutosuggestLocation: React.FC = ({ id }) => { ); }; -export default AutosuggestLocation; +export { + ADDRESS_ICONS, + AutosuggestLocation as default, +}; diff --git a/src/components/big-card.tsx b/src/components/big-card.tsx index f71c86480..d6dfd1201 100644 --- a/src/components/big-card.tsx +++ b/src/components/big-card.tsx @@ -8,25 +8,23 @@ interface IBigCard { children: React.ReactNode; } -const BigCard: React.FC = ({ title, subtitle, children }) => { - return ( - - -
- - {title} - {subtitle && {subtitle}} - -
- - -
- {children} -
+const BigCard: React.FC = ({ title, subtitle, children }) => ( + + +
+ + {title} + {subtitle && {subtitle}} - - - ); -}; +
+ + +
+ {children} +
+
+
+
+); export { BigCard }; \ No newline at end of file diff --git a/src/components/birthday-input.tsx b/src/components/birthday-input.tsx index 53fbed409..677eac933 100644 --- a/src/components/birthday-input.tsx +++ b/src/components/birthday-input.tsx @@ -64,50 +64,48 @@ const BirthdayInput: React.FC = ({ value, onChange, required }) prevYearButtonDisabled: boolean; nextYearButtonDisabled: boolean; date: Date; - }) => { - return ( -
-
- - {intl.formatDate(date, { month: 'long' })} - -
-
- - {intl.formatDate(date, { year: 'numeric' })} - -
+ }) => ( +
+
+ + {intl.formatDate(date, { month: 'long' })} +
- ); - }; +
+ + {intl.formatDate(date, { year: 'numeric' })} + +
+
+ ); const handleChange = (date: Date) => onChange(date ? new Date(date.getTime() - (date.getTimezoneOffset() * 60000)).toISOString().slice(0, 10) : ''); diff --git a/src/components/dropdown-menu/dropdown-menu.tsx b/src/components/dropdown-menu/dropdown-menu.tsx index 1fe9b0dca..3c7d02a4c 100644 --- a/src/components/dropdown-menu/dropdown-menu.tsx +++ b/src/components/dropdown-menu/dropdown-menu.tsx @@ -236,10 +236,8 @@ const DropdownMenu = (props: IDropdownMenu) => { return {}; }, [middlewareData.arrow, placement]); - useEffect(() => { - return () => { - closeDropdownMenu(); - }; + useEffect(() => () => { + closeDropdownMenu(); }, []); useEffect(() => { diff --git a/src/components/extended-video-player.tsx b/src/components/extended-video-player.tsx index e0512588c..2b4ad8b0e 100644 --- a/src/components/extended-video-player.tsx +++ b/src/components/extended-video-player.tsx @@ -10,7 +10,7 @@ interface IExtendedVideoPlayer { time?: number; controls?: boolean; muted?: boolean; - onClick?: () => void; + onClick?: () => void; } const ExtendedVideoPlayer: React.FC = ({ src, alt, time, controls, muted, onClick }) => { diff --git a/src/components/gameboy.tsx b/src/components/gameboy.tsx deleted file mode 100644 index fca9ab16b..000000000 --- a/src/components/gameboy.tsx +++ /dev/null @@ -1,192 +0,0 @@ -// @ts-ignore No types available -import { WasmBoy } from '@soapbox.pub/wasmboy'; -import clsx from 'clsx'; -import React, { useCallback, useEffect, useRef, useState } from 'react'; - -import { exitFullscreen, isFullscreen, requestFullscreen } from 'soapbox/features/ui/util/fullscreen'; - -import { HStack, IconButton } from './ui'; - -let gainNode: GainNode | undefined; - -interface IGameboy extends Pick, 'onFocus' | 'onBlur'> { - /** Classname of the outer `
`. */ - className?: string; - /** URL to the ROM. */ - src: string; - /** Aspect ratio of the canvas. */ - aspect?: 'normal' | 'stretched'; -} - -/** Component to display a playable Gameboy emulator. */ -const Gameboy: React.FC = ({ className, src, aspect = 'normal', onFocus, onBlur, ...rest }) => { - const node = useRef(null); - const canvas = useRef(null); - - const [paused, setPaused] = useState(false); - const [muted, setMuted] = useState(true); - const [fullscreen, setFullscreen] = useState(false); - const [showControls, setShowControls] = useState(true); - - async function init() { - await WasmBoy.config(WasmBoyOptions, canvas.current!); - await WasmBoy.loadROM(src); - await play(); - - if (document.activeElement === canvas.current) { - await WasmBoy.enableDefaultJoypad(); - } else { - await WasmBoy.disableDefaultJoypad(); - } - } - - const handleFocus: React.FocusEventHandler = useCallback(() => { - WasmBoy.enableDefaultJoypad(); - }, []); - - const handleBlur: React.FocusEventHandler = useCallback(() => { - WasmBoy.disableDefaultJoypad(); - }, []); - - const handleFullscreenChange = useCallback(() => { - setFullscreen(isFullscreen()); - }, []); - - const handleCanvasClick = useCallback(() => { - setShowControls(!showControls); - }, [showControls]); - - const pause = async () => { - await WasmBoy.pause(); - setPaused(true); - }; - - const play = async () => { - await WasmBoy.play(); - setPaused(false); - }; - - const togglePaused = () => paused ? play() : pause(); - const toggleMuted = () => setMuted(!muted); - - const toggleFullscreen = () => { - if (isFullscreen()) { - exitFullscreen(); - } else if (node.current) { - requestFullscreen(node.current); - } - }; - - const handleDownload = () => { - window.open(src); - }; - - useEffect(() => { - init(); - - return () => { - WasmBoy.pause(); - WasmBoy.disableDefaultJoypad(); - }; - }, []); - - useEffect(() => { - document.addEventListener('fullscreenchange', handleFullscreenChange, true); - return () => { - document.removeEventListener('fullscreenchange', handleFullscreenChange, true); - }; - }, []); - - useEffect(() => { - if (fullscreen) { - node.current?.focus(); - } - }, [fullscreen]); - - useEffect(() => { - if (gainNode) { - gainNode.gain.value = muted ? 0 : 1; - } - }, [gainNode, muted]); - - return ( -
- - - - - - - - - - - - - -
- ); -}; - -const WasmBoyOptions = { - headless: false, - useGbcWhenOptional: true, - isAudioEnabled: true, - frameSkip: 1, - audioBatchProcessing: true, - timersBatchProcessing: false, - audioAccumulateSamples: true, - graphicsBatchProcessing: false, - graphicsDisableScanlineRendering: false, - tileRendering: true, - tileCaching: true, - gameboyFPSCap: 60, - updateGraphicsCallback: false, - updateAudioCallback: (audioContext: AudioContext, audioBufferSourceNode: AudioBufferSourceNode) => { - gainNode = gainNode ?? audioContext.createGain(); - audioBufferSourceNode.connect(gainNode); - return gainNode; - }, - saveStateCallback: false, -}; - -export default Gameboy; \ No newline at end of file diff --git a/src/components/group-card.tsx b/src/components/group-card.tsx index 08df1a45f..5ecc7e56e 100644 --- a/src/components/group-card.tsx +++ b/src/components/group-card.tsx @@ -14,43 +14,41 @@ interface IGroupCard { group: GroupEntity; } -const GroupCard: React.FC = ({ group }) => { - return ( - - {/* Group Cover Image */} - - - - - {/* Group Avatar */} -
- -
- - {/* Group Info */} - - - - - {group.relationship?.pending_requests && ( -
- )} - - - - - - - - +const GroupCard: React.FC = ({ group }) => ( + + {/* Group Cover Image */} + + - ); -}; + + {/* Group Avatar */} +
+ +
+ + {/* Group Info */} + + + + + {group.relationship?.pending_requests && ( +
+ )} + + + + + + + + + +); export default GroupCard; diff --git a/src/components/helmet.tsx b/src/components/helmet.tsx index 131e4c470..b50dcb2e4 100644 --- a/src/components/helmet.tsx +++ b/src/components/helmet.tsx @@ -27,9 +27,7 @@ const Helmet: React.FC = ({ children }) => { const hasUnreadNotifications = React.useMemo(() => !(unreadCount < 1 || demetricator), [unreadCount, demetricator]); - const addCounter = (string: string) => { - return hasUnreadNotifications ? `(${unreadCount}) ${string}` : string; - }; + const addCounter = (string: string) => hasUnreadNotifications ? `(${unreadCount}) ${string}` : string; const updateFaviconBadge = () => { if (hasUnreadNotifications) { diff --git a/src/components/icon-button.tsx b/src/components/icon-button.tsx index 47cb41b69..a209aa73c 100644 --- a/src/components/icon-button.tsx +++ b/src/components/icon-button.tsx @@ -34,7 +34,7 @@ const IconButton: React.FC = ({ title, }) => { - const handleClick: React.MouseEventHandler = (e) => { + const handleClick: React.MouseEventHandler = (e) => { e.preventDefault(); if (!disabled && onClick) { diff --git a/src/components/icon-with-counter.tsx b/src/components/icon-with-counter.tsx index 5cac95290..5e268c473 100644 --- a/src/components/icon-with-counter.tsx +++ b/src/components/icon-with-counter.tsx @@ -10,18 +10,16 @@ interface IIconWithCounter extends React.HTMLAttributes { src?: string; } -const IconWithCounter: React.FC = ({ icon, count, countMax, ...rest }) => { - return ( -
- +const IconWithCounter: React.FC = ({ icon, count, countMax, ...rest }) => ( +
+ - {count > 0 && ( - - - - )} -
- ); -}; + {count > 0 && ( + + + + )} +
+); export default IconWithCounter; diff --git a/src/components/icon.tsx b/src/components/icon.tsx index 1f1536ef9..b197424b7 100644 --- a/src/components/icon.tsx +++ b/src/components/icon.tsx @@ -17,15 +17,13 @@ export interface IIcon extends React.HTMLAttributes { /** * @deprecated Use the UI Icon component directly. */ -const Icon: React.FC = ({ src, alt, className, ...rest }) => { - return ( -
- } /> -
- ); -}; +const Icon: React.FC = ({ src, alt, className, ...rest }) => ( +
+ } /> +
+); export default Icon; diff --git a/src/components/list.tsx b/src/components/list.tsx index b26eea116..65be4cef4 100644 --- a/src/components/list.tsx +++ b/src/components/list.tsx @@ -37,23 +37,21 @@ const ListItem: React.FC = ({ label, hint, children, to, onClick, onS const LabelComp = to || onClick || onSelect ? 'span' : 'label'; - const renderChildren = React.useCallback(() => { - return React.Children.map(children, (child) => { - if (React.isValidElement(child)) { - const isSelect = child.type === SelectDropdown || child.type === Select; + const renderChildren = React.useCallback(() => React.Children.map(children, (child) => { + if (React.isValidElement(child)) { + const isSelect = child.type === SelectDropdown || child.type === Select; - return React.cloneElement(child, { - // @ts-ignore - id: domId, - className: clsx({ - 'w-auto': isSelect, - }, child.props.className), - }); - } + return React.cloneElement(child, { + // @ts-ignore + id: domId, + className: clsx({ + 'w-auto': isSelect, + }, child.props.className), + }); + } - return null; - }); - }, [children, domId]); + return null; + }), [children, domId]); const className = clsx('flex items-center justify-between overflow-hidden bg-gradient-to-r from-gradient-start/20 to-gradient-end/20 px-4 py-2 first:rounded-t-lg last:rounded-b-lg dark:from-gradient-start/10 dark:to-gradient-end/10', { 'cursor-pointer hover:from-gradient-start/30 hover:to-gradient-end/30 dark:hover:from-gradient-start/5 dark:hover:to-gradient-end/5': typeof to !== 'undefined' || typeof onClick !== 'undefined' || typeof onSelect !== 'undefined', diff --git a/src/components/loading-screen.tsx b/src/components/loading-screen.tsx index 3b86fd2e0..9717f1c3a 100644 --- a/src/components/loading-screen.tsx +++ b/src/components/loading-screen.tsx @@ -4,18 +4,16 @@ import LandingGradient from 'soapbox/components/landing-gradient'; import { Spinner } from 'soapbox/components/ui'; /** Fullscreen loading indicator. */ -const LoadingScreen: React.FC = () => { - return ( -
- +const LoadingScreen: React.FC = () => ( +
+ -
-
- -
+
+
+
- ); -}; +
+); export default LoadingScreen; diff --git a/src/components/markup.tsx b/src/components/markup.tsx index e20dcb3a2..a1b006393 100644 --- a/src/components/markup.tsx +++ b/src/components/markup.tsx @@ -7,10 +7,6 @@ interface IMarkup extends IText { } /** Styles HTML markup returned by the API, such as in account bios and statuses. */ -const Markup = React.forwardRef((props, ref) => { - return ( - - ); -}); +const Markup = React.forwardRef((props, ref) => ); export default Markup; \ No newline at end of file diff --git a/src/components/media-gallery.tsx b/src/components/media-gallery.tsx index fca1addd1..aa831e7e2 100644 --- a/src/components/media-gallery.tsx +++ b/src/components/media-gallery.tsx @@ -1,5 +1,5 @@ import clsx from 'clsx'; -import React, { useState, useRef, useLayoutEffect, Suspense } from 'react'; +import React, { useState, useRef, useLayoutEffect } from 'react'; import Blurhash from 'soapbox/components/blurhash'; import Icon from 'soapbox/components/icon'; @@ -15,8 +15,6 @@ import { isPanoramic, isPortrait, isNonConformingRatio, minimumAspectRatio, maxi import type { Property } from 'csstype'; import type { List as ImmutableList } from 'immutable'; -const Gameboy = React.lazy(() => import('./gameboy')); - const ATTACHMENT_LIMIT = 4; const MAX_FILENAME_LENGTH = 45; @@ -38,9 +36,8 @@ interface SizeData { width: number; } -const withinLimits = (aspectRatio: number) => { - return aspectRatio >= minimumAspectRatio && aspectRatio <= maximumAspectRatio; -}; +const withinLimits = (aspectRatio: number) => + aspectRatio >= minimumAspectRatio && aspectRatio <= maximumAspectRatio; const shouldLetterbox = (attachment: Attachment): boolean => { const aspectRatio = attachment.getIn(['meta', 'original', 'aspect']) as number | undefined; @@ -88,9 +85,7 @@ const Item: React.FC = ({ } }; - const hoverToPlay = () => { - return !autoPlayGif && attachment.type === 'gifv'; - }; + const hoverToPlay = () => !autoPlayGif && attachment.type === 'gifv'; // FIXME: wtf? const handleClick: React.MouseEventHandler = (e: any) => { @@ -144,22 +139,7 @@ const Item: React.FC = ({ let thumbnail: React.ReactNode = ''; const ext = attachment.url.split('.').pop()?.toLowerCase(); - if (attachment.type === 'unknown' && ['gb', 'gbc'].includes(ext!)) { - return ( -
1, - })} - key={attachment.id} - style={{ position, float, left, top, right, bottom, height, width: `${width}%` }} - > - }> - - -
- ); - } else if (attachment.type === 'unknown') { + if (attachment.type === 'unknown') { const filename = truncateFilename(attachment.url, MAX_FILENAME_LENGTH); const attachmentIcon = ( ) => { - return !!compose && [ +const checkComposeContent = (compose?: ReturnType) => + !!compose && [ compose.editorState && compose.editorState.length > 0, compose.spoiler_text.length > 0, compose.media_attachments.size > 0, compose.poll !== null, ].some(check => check === true); -}; -export const checkEventComposeContent = (compose?: ReturnType) => { - return !!compose && [ +const checkEventComposeContent = (compose?: ReturnType) => + !!compose && [ compose.name.length > 0, compose.status.length > 0, compose.location !== null, compose.banner !== null, ].some(check => check === true); -}; interface IModalRoot { onCancel?: () => void; @@ -177,11 +175,9 @@ const ModalRoot: React.FC = ({ children, onCancel, onClose, type }) } }; - const getSiblings = () => { - return Array(...(ref.current!.parentElement!.childNodes as any as ChildNode[])) - .filter(node => (node as HTMLDivElement).id !== 'toaster') - .filter(node => node !== ref.current); - }; + const getSiblings = () => Array(...(ref.current!.parentElement!.childNodes as any as ChildNode[])) + .filter(node => (node as HTMLDivElement).id !== 'toaster') + .filter(node => node !== ref.current); useEffect(() => { if (!visible) return; @@ -258,4 +254,8 @@ const ModalRoot: React.FC = ({ children, onCancel, onClose, type }) ); }; -export default ModalRoot; +export { + checkComposeContent, + checkEventComposeContent, + ModalRoot as default, +}; diff --git a/src/components/outline-box.tsx b/src/components/outline-box.tsx index 0f56c21ae..a46262a5b 100644 --- a/src/components/outline-box.tsx +++ b/src/components/outline-box.tsx @@ -7,15 +7,13 @@ interface IOutlineBox extends React.HTMLAttributes { } /** Wraps children in a container with an outline. */ -const OutlineBox: React.FC = ({ children, className, ...rest }) => { - return ( -
- {children} -
- ); -}; +const OutlineBox: React.FC = ({ children, className, ...rest }) => ( +
+ {children} +
+); export default OutlineBox; diff --git a/src/components/pending-items-row.tsx b/src/components/pending-items-row.tsx index e37714b76..9393ed8db 100644 --- a/src/components/pending-items-row.tsx +++ b/src/components/pending-items-row.tsx @@ -14,41 +14,39 @@ interface IPendingItemsRow { size?: 'md' | 'lg'; } -const PendingItemsRow: React.FC = ({ to, count, size = 'md' }) => { - return ( - - - -
- -
+const PendingItemsRow: React.FC = ({ to, count, size = 'md' }) => ( + + + +
+ +
- - - -
- - + + +
- - ); -}; + + +
+ +); export { PendingItemsRow }; \ No newline at end of file diff --git a/src/components/polls/poll-option.tsx b/src/components/polls/poll-option.tsx index 83b12a1e3..f0a5520fc 100644 --- a/src/components/polls/poll-option.tsx +++ b/src/components/polls/poll-option.tsx @@ -15,18 +15,16 @@ const messages = defineMessages({ votes: { id: 'poll.votes', defaultMessage: '{votes, plural, one {# vote} other {# votes}}' }, }); -const PollPercentageBar: React.FC<{ percent: number; leading: boolean }> = ({ percent, leading }): JSX.Element => { - return ( - - {({ width }) => ( - - )} - - ); -}; +const PollPercentageBar: React.FC<{ percent: number; leading: boolean }> = ({ percent, leading }): JSX.Element => ( + + {({ width }) => ( + + )} + +); interface IPollOptionText extends IPollOption { percent: number; diff --git a/src/components/preview-card.tsx b/src/components/preview-card.tsx index 9fbbb70b8..80ebc8993 100644 --- a/src/components/preview-card.tsx +++ b/src/components/preview-card.tsx @@ -249,7 +249,7 @@ const PreviewCard: React.FC = ({ }; /** Trim the text, adding ellipses if it's too long. */ -function trim(text: string, len: number): string { +const trim = (text: string, len: number): string => { const cut = text.indexOf(' ', len); if (cut === -1) { @@ -257,6 +257,6 @@ function trim(text: string, len: number): string { } return text.substring(0, cut) + (text.length > len ? '…' : ''); -} +}; export default PreviewCard; diff --git a/src/components/profile-hover-card.tsx b/src/components/profile-hover-card.tsx index 55b15f14e..d11bdecab 100644 --- a/src/components/profile-hover-card.tsx +++ b/src/components/profile-hover-card.tsx @@ -9,7 +9,7 @@ import { closeProfileHoverCard, updateProfileHoverCard, } from 'soapbox/actions/profile-hover-card'; -import { useAccount, usePatronUser } from 'soapbox/api/hooks'; +import { useAccount } from 'soapbox/api/hooks'; import Badge from 'soapbox/components/badge'; import ActionButton from 'soapbox/features/ui/components/action-button'; import { UserPanel } from 'soapbox/features/ui/util/async-components'; @@ -19,12 +19,11 @@ import { showProfileHoverCard } from './hover-ref-wrapper'; import { dateFormatOptions } from './relative-timestamp'; import { Card, CardBody, HStack, Icon, Stack, Text } from './ui'; -import type { Account, PatronUser } from 'soapbox/schemas'; +import type { Account } from 'soapbox/schemas'; import type { AppDispatch } from 'soapbox/store'; const getBadges = ( account?: Pick, - patronUser?: Pick, ): JSX.Element[] => { const badges = []; @@ -34,23 +33,15 @@ const getBadges = ( badges.push(} />); } - if (patronUser?.is_patron) { - badges.push(} />); - } - return badges; }; -const handleMouseEnter = (dispatch: AppDispatch): React.MouseEventHandler => { - return () => { - dispatch(updateProfileHoverCard()); - }; +const handleMouseEnter = (dispatch: AppDispatch): React.MouseEventHandler => () => { + dispatch(updateProfileHoverCard()); }; -const handleMouseLeave = (dispatch: AppDispatch): React.MouseEventHandler => { - return () => { - dispatch(closeProfileHoverCard(true)); - }; +const handleMouseLeave = (dispatch: AppDispatch): React.MouseEventHandler => () => { + dispatch(closeProfileHoverCard(true)); }; interface IProfileHoverCard { @@ -68,9 +59,8 @@ export const ProfileHoverCard: React.FC = ({ visible = true } const me = useAppSelector(state => state.me); const accountId: string | undefined = useAppSelector(state => state.profile_hover_card.accountId || undefined); const { account } = useAccount(accountId, { withRelationship: true }); - const { patronUser } = usePatronUser(account?.url); const targetRef = useAppSelector(state => state.profile_hover_card.ref?.current); - const badges = getBadges(account, patronUser); + const badges = getBadges(account); useEffect(() => { if (accountId) dispatch(fetchRelationships([accountId])); diff --git a/src/components/radio.tsx b/src/components/radio.tsx index 2104b9985..384994eba 100644 --- a/src/components/radio.tsx +++ b/src/components/radio.tsx @@ -23,19 +23,17 @@ interface IRadioItem { onChange?: React.ChangeEventHandler; } -const RadioItem: React.FC = ({ label, hint, checked = false, onChange, value }) => { - return ( - - - - ); -}; +const RadioItem: React.FC = ({ label, hint, checked = false, onChange, value }) => ( + + + +); export { RadioGroup, diff --git a/src/components/scroll-top-button.tsx b/src/components/scroll-top-button.tsx index 9e2dfafe4..1418edc38 100644 --- a/src/components/scroll-top-button.tsx +++ b/src/components/scroll-top-button.tsx @@ -37,9 +37,7 @@ const ScrollTopButton: React.FC = ({ const visible = count > 0 && scrolled; /** Number of pixels scrolled down from the top of the page. */ - const getScrollTop = (): number => { - return (document.scrollingElement || document.documentElement).scrollTop; - }; + const getScrollTop = (): number => (document.scrollingElement || document.documentElement).scrollTop; /** Unload feed items if scrolled to the top. */ const maybeUnload = useCallback(() => { diff --git a/src/components/scrollable-list.tsx b/src/components/scrollable-list.tsx index 172cb6e5b..30f794992 100644 --- a/src/components/scrollable-list.tsx +++ b/src/components/scrollable-list.tsx @@ -158,25 +158,23 @@ const ScrollableList = React.forwardRef(({ }, []); /* Render an empty state instead of the scrollable list. */ - const renderEmpty = (): JSX.Element => { - return ( -
- {alwaysPrepend && prepend} + const renderEmpty = (): JSX.Element => ( +
+ {alwaysPrepend && prepend} - {isLoading ? ( - - ) : ( - <> - {emptyMessageCard ? ( - - {emptyMessage} - - ) : emptyMessage} - - )} -
- ); - }; + {isLoading ? ( + + ) : ( + <> + {emptyMessageCard ? ( + + {emptyMessage} + + ) : emptyMessage} + + )} +
+ ); /** Render a single item. */ const renderItem = (_i: number, element: JSX.Element): JSX.Element => { diff --git a/src/components/sidebar-menu.tsx b/src/components/sidebar-menu.tsx index 13011dfec..16ffe9d95 100644 --- a/src/components/sidebar-menu.tsx +++ b/src/components/sidebar-menu.tsx @@ -93,11 +93,9 @@ const SidebarMenu: React.FC = (): JSX.Element | null => { onClose(); }; - const handleSwitchAccount = (account: AccountEntity): React.MouseEventHandler => { - return (e) => { - e.preventDefault(); - dispatch(switchAccount(account.id)); - }; + const handleSwitchAccount = (account: AccountEntity): React.MouseEventHandler => (e) => { + e.preventDefault(); + dispatch(switchAccount(account.id)); }; const onClickLogOut: React.MouseEventHandler = (e) => { diff --git a/src/components/site-error-boundary.tsx b/src/components/site-error-boundary.tsx index 189554278..54d707f8b 100644 --- a/src/components/site-error-boundary.tsx +++ b/src/components/site-error-boundary.tsx @@ -51,7 +51,7 @@ const SiteErrorBoundary: React.FC = ({ children }) => { document.execCommand('copy'); }; - function handleError(error: Error, info: ErrorInfo) { + const handleError = (error: Error, info: ErrorInfo) => { setError(error); setComponentStack(info.componentStack); @@ -67,11 +67,11 @@ const SiteErrorBoundary: React.FC = ({ children }) => { import('bowser') .then(({ default: Bowser }) => setBrowser(Bowser.getParser(window.navigator.userAgent))) .catch(() => {}); - } + }; - function goHome() { + const goHome = () => { location.href = '/'; - } + }; const fallback = (
@@ -185,15 +185,13 @@ interface ISiteErrorBoundaryLink { children: React.ReactNode; } -function SiteErrorBoundaryLink({ href, children }: ISiteErrorBoundaryLink) { - return ( - <> -