From 4589bde6720acff22a0e6bad31f8e7c26ee065b5 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Wed, 24 Apr 2024 17:12:34 +1000 Subject: [PATCH] chore: moved more types to ReduxTypes.d.ts --- ts/components/basic/SessionInput.tsx | 3 +-- .../composition/CompositionButtons.tsx | 9 ++++---- .../dialog/EditProfilePictureModal.tsx | 6 +---- .../dialog/SessionPasswordDialog.tsx | 3 +-- .../leftpane/LeftPaneSettingSection.tsx | 2 +- ts/components/registration/SignUpTab.tsx | 5 ++-- .../settings/SessionSettingListItem.tsx | 4 ++-- ts/components/settings/SessionSettings.tsx | 3 +-- ts/node/menu.ts | 3 +-- ts/state/ducks/modalDialog.tsx | 6 ++--- ts/state/ducks/section.tsx | 2 +- ts/state/ducks/sogsRoomInfo.tsx | 10 -------- ts/state/reducer.ts | 6 ++--- ts/state/selectors/section.ts | 2 +- ts/types/ReduxTypes.d.ts | 23 +++++++++++++++++++ ts/types/SessionSettingCategory.d.ts | 10 -------- ts/types/Util.ts | 2 -- 17 files changed, 44 insertions(+), 55 deletions(-) create mode 100644 ts/types/ReduxTypes.d.ts delete mode 100644 ts/types/SessionSettingCategory.d.ts diff --git a/ts/components/basic/SessionInput.tsx b/ts/components/basic/SessionInput.tsx index 0c33a22b0..a34de03cc 100644 --- a/ts/components/basic/SessionInput.tsx +++ b/ts/components/basic/SessionInput.tsx @@ -2,7 +2,6 @@ import React, { useState } from 'react'; import classNames from 'classnames'; import { SessionIconButton } from '../icon'; -import { Noop } from '../../types/Util'; import { useHTMLDirection } from '../../util/i18n'; type Props = { @@ -46,7 +45,7 @@ const ErrorItem = (props: { error: string | undefined }) => { ); }; -const ShowHideButton = (props: { toggleForceShow: Noop }) => { +const ShowHideButton = (props: { toggleForceShow: () => void }) => { const htmlDirection = useHTMLDirection(); const position = htmlDirection === 'ltr' ? { right: '0px' } : { left: '0px' }; diff --git a/ts/components/conversation/composition/CompositionButtons.tsx b/ts/components/conversation/composition/CompositionButtons.tsx index 8a2a4d665..3b145e297 100644 --- a/ts/components/conversation/composition/CompositionButtons.tsx +++ b/ts/components/conversation/composition/CompositionButtons.tsx @@ -1,6 +1,5 @@ import React from 'react'; import styled from 'styled-components'; -import { Noop } from '../../../types/Util'; import { SessionIconButton } from '../../icon'; const StyledChatButtonContainer = styled.div` @@ -15,7 +14,7 @@ const StyledChatButtonContainer = styled.div` } `; -export const AddStagedAttachmentButton = (props: { onClick: Noop }) => { +export const AddStagedAttachmentButton = (props: { onClick: () => void }) => { return ( { ); }; -export const StartRecordingButton = (props: { onClick: Noop }) => { +export const StartRecordingButton = (props: { onClick: () => void }) => { return ( { }; // eslint-disable-next-line react/display-name -export const ToggleEmojiButton = React.forwardRef( +export const ToggleEmojiButton = React.forwardRef void }>( (props, ref) => { return ( @@ -70,7 +69,7 @@ export const ToggleEmojiButton = React.forwardRef { +export const SendMessageButton = (props: { onClick: () => void }) => { return ( { } }; -export type EditProfilePictureModalProps = { - avatarPath: string | null; - profileName: string | undefined; - ourId: string; -}; export const EditProfilePictureModal = (props: EditProfilePictureModalProps) => { const dispatch = useDispatch(); diff --git a/ts/components/dialog/SessionPasswordDialog.tsx b/ts/components/dialog/SessionPasswordDialog.tsx index 98d736902..7de8b4435 100644 --- a/ts/components/dialog/SessionPasswordDialog.tsx +++ b/ts/components/dialog/SessionPasswordDialog.tsx @@ -11,8 +11,7 @@ import { SessionButton, SessionButtonColor, SessionButtonType } from '../basic/S import { SessionWrapperModal } from '../SessionWrapperModal'; import { matchesHash, validatePassword } from '../../util/passwordUtils'; import { assertUnreachable } from '../../types/sqlSharedTypes'; - -export type PasswordAction = 'set' | 'change' | 'remove' | 'enter'; +import type { PasswordAction } from '../../types/ReduxTypes'; interface Props { passwordAction: PasswordAction; diff --git a/ts/components/leftpane/LeftPaneSettingSection.tsx b/ts/components/leftpane/LeftPaneSettingSection.tsx index 9efe37ba7..a05912a78 100644 --- a/ts/components/leftpane/LeftPaneSettingSection.tsx +++ b/ts/components/leftpane/LeftPaneSettingSection.tsx @@ -13,7 +13,7 @@ import { import { getFocusedSettingsSection } from '../../state/selectors/section'; import { SessionIcon } from '../icon'; import { LeftPaneSectionHeader } from './LeftPaneSectionHeader'; -import type { SessionSettingCategory } from '../../types/SessionSettingCategory'; +import type { SessionSettingCategory } from '../../types/ReduxTypes'; const StyledSettingsSectionTitle = styled.strong` font-family: var(--font-accent), var(--font-default); diff --git a/ts/components/registration/SignUpTab.tsx b/ts/components/registration/SignUpTab.tsx index a54d0a01c..9a5f27ab8 100644 --- a/ts/components/registration/SignUpTab.tsx +++ b/ts/components/registration/SignUpTab.tsx @@ -7,7 +7,6 @@ import { RegistrationContext, RegistrationPhase, signUp } from './RegistrationSt import { RegistrationUserDetails } from './RegistrationUserDetails'; import { sanitizeDisplayNameOrToast, SignInMode } from './SignInTab'; import { TermsAndConditions } from './TermsAndConditions'; -import { Noop } from '../../types/Util'; export enum SignUpMode { Default, @@ -23,7 +22,7 @@ const ContinueSignUpButton = ({ continueSignUp }: { continueSignUp: any }) => { return ; }; -const SignUpDefault = (props: { createSessionID: Noop }) => { +const SignUpDefault = (props: { createSessionID: () => void }) => { return (
@@ -47,7 +46,7 @@ export const GoBackMainMenuButton = () => { ); }; -const SignUpSessionIDShown = (props: { continueSignUp: Noop }) => { +const SignUpSessionIDShown = (props: { continueSignUp: () => void }) => { return (
diff --git a/ts/components/settings/SessionSettingListItem.tsx b/ts/components/settings/SessionSettingListItem.tsx index 20311ff22..ca99d3a31 100644 --- a/ts/components/settings/SessionSettingListItem.tsx +++ b/ts/components/settings/SessionSettingListItem.tsx @@ -10,7 +10,7 @@ import { import { SessionToggle } from '../basic/SessionToggle'; import { SessionConfirmDialogProps } from '../dialog/SessionConfirm'; import { SessionIconButton } from '../icon'; -import { Noop } from '../../types/Util'; + type ButtonSettingsProps = { title?: string; @@ -113,7 +113,7 @@ export const SessionSettingsItemWrapper = (props: { ); }; -export const SessionSettingsTitleWithLink = (props: { title: string; onClick: Noop }) => { +export const SessionSettingsTitleWithLink = (props: { title: string; onClick: () => void }) => { const { onClick, title } = props; return ( diff --git a/ts/components/settings/SessionSettings.tsx b/ts/components/settings/SessionSettings.tsx index 5a2b919f2..27fa5dced 100644 --- a/ts/components/settings/SessionSettings.tsx +++ b/ts/components/settings/SessionSettings.tsx @@ -13,13 +13,12 @@ import { SessionNotificationGroupSettings } from './SessionNotificationGroupSett import { Data } from '../../data/data'; import { sessionPassword } from '../../state/ducks/modalDialog'; import { SectionType, showLeftPaneSection } from '../../state/ducks/section'; -import { PasswordAction } from '../dialog/SessionPasswordDialog'; import { SettingsCategoryAppearance } from './section/CategoryAppearance'; import { CategoryConversations } from './section/CategoryConversations'; import { SettingsCategoryHelp } from './section/CategoryHelp'; import { SettingsCategoryPermissions } from './section/CategoryPermissions'; import { SettingsCategoryPrivacy } from './section/CategoryPrivacy'; -import type { SessionSettingCategory } from '../../types/SessionSettingCategory'; +import type { SessionSettingCategory, PasswordAction } from '../../types/ReduxTypes'; export function displayPasswordModal( passwordAction: PasswordAction, diff --git a/ts/node/menu.ts b/ts/node/menu.ts index fb4541850..f75b661ca 100644 --- a/ts/node/menu.ts +++ b/ts/node/menu.ts @@ -1,6 +1,5 @@ import { isString } from 'lodash'; import { LocaleMessagesType } from './locale'; -import { Noop } from '../types/Util'; export const createTemplate = ( options: { @@ -157,7 +156,7 @@ export const createTemplate = ( function updateForMac( template: any, messages: LocaleMessagesType, - options: { showAbout: Noop; showWindow: Noop } + options: { showAbout: () => void; showWindow: () => void } ) { const { showAbout, showWindow } = options; diff --git a/ts/state/ducks/modalDialog.tsx b/ts/state/ducks/modalDialog.tsx index 187d5fe2b..715c8c5c0 100644 --- a/ts/state/ducks/modalDialog.tsx +++ b/ts/state/ducks/modalDialog.tsx @@ -1,8 +1,6 @@ import { createSlice, PayloadAction } from '@reduxjs/toolkit'; -import { EditProfilePictureModalProps } from '../../components/dialog/EditProfilePictureModal'; import { SessionConfirmDialogProps } from '../../components/dialog/SessionConfirm'; -import { PasswordAction } from '../../components/dialog/SessionPasswordDialog'; -import { Noop } from '../../types/Util'; +import type { EditProfilePictureModalProps, PasswordAction } from '../../types/ReduxTypes'; export type BanType = 'ban' | 'unban'; @@ -23,7 +21,7 @@ export type OnionPathModalState = EditProfileModalState; export type RecoveryPhraseModalState = EditProfileModalState; export type DeleteAccountModalState = EditProfileModalState; -export type SessionPasswordModalState = { passwordAction: PasswordAction; onOk: Noop } | null; +export type SessionPasswordModalState = { passwordAction: PasswordAction; onOk: () => void } | null; export type UserDetailsModalState = { conversationId: string; diff --git a/ts/state/ducks/section.tsx b/ts/state/ducks/section.tsx index a07d4a6f6..27cbe1cb7 100644 --- a/ts/state/ducks/section.tsx +++ b/ts/state/ducks/section.tsx @@ -1,6 +1,6 @@ // TODO move into redux slice -import type { SessionSettingCategory } from '../../types/SessionSettingCategory'; +import type { SessionSettingCategory } from '../../types/ReduxTypes'; export const FOCUS_SECTION = 'FOCUS_SECTION'; export const FOCUS_SETTINGS_SECTION = 'FOCUS_SETTINGS_SECTION'; diff --git a/ts/state/ducks/sogsRoomInfo.tsx b/ts/state/ducks/sogsRoomInfo.tsx index 6ebe3c6ce..df8821d38 100644 --- a/ts/state/ducks/sogsRoomInfo.tsx +++ b/ts/state/ducks/sogsRoomInfo.tsx @@ -1,9 +1,5 @@ import { createSlice, PayloadAction } from '@reduxjs/toolkit'; import { isFinite, sortBy, uniq, xor } from 'lodash'; -import { - getCanWriteOutsideRedux, - getCurrentSubscriberCountOutsideRedux, -} from '../selectors/sogsRoomInfo'; type RoomInfo = { canWrite: boolean; @@ -79,16 +75,10 @@ export const ReduxSogsRoomInfos = { }; function setSubscriberCountOutsideRedux(convoId: string, subscriberCount: number) { - if (subscriberCount === getCurrentSubscriberCountOutsideRedux(convoId)) { - return; - } window.inboxStore?.dispatch(setSubscriberCount({ convoId, subscriberCount })); } function setCanWriteOutsideRedux(convoId: string, canWrite: boolean) { - if (getCanWriteOutsideRedux(convoId) === canWrite) { - return; - } window.inboxStore?.dispatch(setCanWrite({ convoId, canWrite })); } diff --git a/ts/state/reducer.ts b/ts/state/reducer.ts index da8148b46..7d77e6611 100644 --- a/ts/state/reducer.ts +++ b/ts/state/reducer.ts @@ -6,14 +6,14 @@ import { defaultRoomReducer as defaultRooms, DefaultRoomsState } from './ducks/d import { reducer as primaryColor } from './ducks/primaryColor'; // ok: importing only Constants.tsx which is not importing anything else import { reducer as search, SearchStateType } from './ducks/search'; // todo import { reducer as section, SectionStateType } from './ducks/section'; // ok: importing only SessionSettingsCategory which is not importing anything else -import { ReduxSogsRoomInfos, SogsRoomInfoState } from './ducks/sogsRoomInfo'; // todo +import { ReduxSogsRoomInfos, SogsRoomInfoState } from './ducks/sogsRoomInfo'; // ok: importing nothing else import { reducer as theme } from './ducks/theme'; // ok: importing only Constants.tsx which is not importing anything else import { reducer as user, UserStateType } from './ducks/user'; // ok: not importing anything else import { PrimaryColorStateType, ThemeStateType } from '../themes/constants/colors'; // ok: not importing anything else -import { modalReducer as modals, ModalState } from './ducks/modalDialog'; +import { modalReducer as modals, ModalState } from './ducks/modalDialog'; // todo import { defaultOnionReducer as onionPaths, OnionState } from './ducks/onion'; // ok: not importing anything else -import { settingsReducer, SettingsState } from './ducks/settings'; +import { settingsReducer, SettingsState } from './ducks/settings'; // ok: just importing settings-key.tsx which is not importing anything else import { reducer as stagedAttachments, StagedAttachmentsStateType, diff --git a/ts/state/selectors/section.ts b/ts/state/selectors/section.ts index 7640dde93..39992174e 100644 --- a/ts/state/selectors/section.ts +++ b/ts/state/selectors/section.ts @@ -2,7 +2,7 @@ import { createSelector } from '@reduxjs/toolkit'; import { LeftOverlayMode, SectionStateType, SectionType } from '../ducks/section'; import { StateType } from '../reducer'; -import type { SessionSettingCategory } from '../../types/SessionSettingCategory'; +import type { SessionSettingCategory } from '../../types/ReduxTypes'; export const getSection = (state: StateType): SectionStateType => state.section; diff --git a/ts/types/ReduxTypes.d.ts b/ts/types/ReduxTypes.d.ts new file mode 100644 index 000000000..41195a658 --- /dev/null +++ b/ts/types/ReduxTypes.d.ts @@ -0,0 +1,23 @@ +/** + * Note: The types defined in this file have to be self contained. + * We must not import anything in this file, especially not something relying on the window object (even indirectly, through an import chain). + */ + +export type SessionSettingCategory = + | 'privacy' + | 'notifications' + | 'conversations' + | 'messageRequests' + | 'appearance' + | 'permissions' + | 'help' + | 'recoveryPhrase' + | 'ClearData'; + +export type PasswordAction = 'set' | 'change' | 'remove' | 'enter'; + +export type EditProfilePictureModalProps = { + avatarPath: string | null; + profileName: string | undefined; + ourId: string; +}; diff --git a/ts/types/SessionSettingCategory.d.ts b/ts/types/SessionSettingCategory.d.ts deleted file mode 100644 index 21ffad665..000000000 --- a/ts/types/SessionSettingCategory.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -export type SessionSettingCategory = - | 'privacy' - | 'notifications' - | 'conversations' - | 'messageRequests' - | 'appearance' - | 'permissions' - | 'help' - | 'recoveryPhrase' - | 'ClearData'; diff --git a/ts/types/Util.ts b/ts/types/Util.ts index 76f1d6800..ccea6b792 100644 --- a/ts/types/Util.ts +++ b/ts/types/Util.ts @@ -7,5 +7,3 @@ export type RenderTextCallbackType = (options: { }) => JSX.Element; export type LocalizerType = (key: LocalizerKeys, values?: Array) => string; - -export type Noop = () => void;