From 985a5d92bc7e64d6b367d36e7caf657fa1e99fa3 Mon Sep 17 00:00:00 2001 From: audric Date: Thu, 26 Aug 2021 16:44:58 +1000 Subject: [PATCH] do not show search input if we only got a single conversation --- _locales/en/messages.json | 14 ++- .../session/LeftPaneSectionHeader.tsx | 8 ++ .../session/SessionClosableOverlay.tsx | 21 +---- ts/components/session/SessionSearchInput.tsx | 71 ++++----------- ts/components/session/UserSearchDropdown.tsx | 86 ------------------- ts/state/createStore.ts | 10 ++- ts/state/selectors/conversations.ts | 4 + 7 files changed, 52 insertions(+), 162 deletions(-) delete mode 100644 ts/components/session/UserSearchDropdown.tsx diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 8b6f98fe1..30ab8ce20 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -131,7 +131,7 @@ "deleteForEveryone": "Delete for Everyone", "deleteConversationConfirmation": "Permanently delete the messages in this conversation?", "clearAllData": "Clear All Data", - "deleteAccountWarning": "This will permanently delete your messages, sessions, and contacts.", + "deleteAccountWarning": "This will permanently delete your messages and contacts.", "deleteContactConfirmation": "Are you sure you want to delete this conversation?", "quoteThumbnailAlt": "Thumbnail of image from quoted message", "imageAttachmentAlt": "Image attached to message", @@ -337,6 +337,8 @@ "onlyAdminCanRemoveMembersDesc": "Only the creator of the group can remove users", "createAccount": "Create account", "signIn": "Sign In", + "startInTrayTitle": "Start in Tray", + "startInTrayDescription": "Start Session as a minified app ", "yourUniqueSessionID": "Say hello to your Session ID", "allUsersAreRandomly...": "Your Session ID is the unique address people can use to contact you on Session. With no connection to your real identity, your Session ID is totally anonymous and private by design.", "getStarted": "Get started", @@ -419,5 +421,15 @@ "latestUnreadIsAbove": "First unread message is above", "sendRecoveryPhraseTitle": "Sending Recovery Phrase", "sendRecoveryPhraseMessage": "You are attempting to send your recovery phrase which can be used to access your account. Are you sure you want to send this message?", + "dialogClearAllDataDeletionFailedTitle": "Data not deleted", + "dialogClearAllDataDeletionFailedDesc": "Data not deleted with an unknown error. Do you want to delete data from just this device?", + "dialogClearAllDataDeletionFailedTitleQuestion": "Do you want to delete data from just this device?", + "dialogClearAllDataDeletionFailedMultiple": "Data not deleted by those Service Nodes: $snodes$", + "dialogClearAllDataDeletionQuestion": "Would you like to clear only this device, or delete your entire account?", + "deviceOnly": "Device Only", + "entireAccount": "Entire Account", + "recoveryPhraseSecureTitle": "You're almost finished!", + "recoveryPhraseRevealMessage": "Secure your account by saving your recovery phrase. Reveal your recovery phrase then store it safely to secure it.", + "recoveryPhraseRevealButtonText": "Reveal Recovery Phrase", "notificationSubtitle": "Notifications - $setting$" } diff --git a/ts/components/session/LeftPaneSectionHeader.tsx b/ts/components/session/LeftPaneSectionHeader.tsx index fcff680a3..11ca37109 100644 --- a/ts/components/session/LeftPaneSectionHeader.tsx +++ b/ts/components/session/LeftPaneSectionHeader.tsx @@ -8,6 +8,8 @@ import { disableRecoveryPhrasePrompt } from '../../state/ducks/userConfig'; import { getShowRecoveryPhrasePrompt } from '../../state/selectors/userConfig'; import { recoveryPhraseModal } from '../../state/ducks/modalDialog'; import { Flex } from '../basic/Flex'; +import { getFocusedSection } from '../../state/selectors/section'; +import { SectionType } from '../../state/ducks/section'; const Tab = ({ isSelected, @@ -71,6 +73,8 @@ export const LeftPaneSectionHeader = (props: Props) => { export const LeftPaneBanner = () => { const dispatch = useDispatch(); + const section = useSelector(getFocusedSection); + const showRecoveryPhraseModal = () => { dispatch( recoveryPhraseModal({ @@ -81,6 +85,10 @@ export const LeftPaneBanner = () => { ); }; + if (section !== SectionType.Message) { + return null; + } + const BannerInner = () => { return ( diff --git a/ts/components/session/SessionClosableOverlay.tsx b/ts/components/session/SessionClosableOverlay.tsx index 51511bb10..9d103a219 100644 --- a/ts/components/session/SessionClosableOverlay.tsx +++ b/ts/components/session/SessionClosableOverlay.tsx @@ -2,7 +2,6 @@ import React from 'react'; import { SessionIconButton, SessionIconSize, SessionIconType } from './icon'; import { SessionIdEditable } from './SessionIdEditable'; -import { UserSearchDropdown } from './UserSearchDropdown'; import { ContactType, SessionMemberListItem } from './SessionMemberListItem'; import { ReduxConversationType } from '../../state/ducks/conversations'; import { SessionButton, SessionButtonColor, SessionButtonType } from './SessionButton'; @@ -100,16 +99,7 @@ export class SessionClosableOverlay extends React.Component { // tslint:disable-next-line max-func-body-length cyclomatic-complexity */ public render(): JSX.Element { - const { - overlayMode, - onCloseClick, - onChangeSessionID, - showSpinner, - searchTerm, - updateSearch, - searchResults, - onButtonClick, - } = this.props; + const { overlayMode, onCloseClick, onChangeSessionID, showSpinner, onButtonClick } = this.props; const { groupName, selectedMembers } = this.state; @@ -218,16 +208,7 @@ export class SessionClosableOverlay extends React.Component { {descriptionLong &&
{descriptionLong}
} {isMessageView && false &&

{window.i18n('or')}

} - {/* FIXME enable back those two items when they are working */} {isOpenGroupView && } - {isMessageView && false && ( - - )} { - public constructor(props: Props) { - super(props); - this.handleKeyDown = this.handleKeyDown.bind(this); - } +export const SessionSearchInput = (props: Props) => { + const { searchString, onChange, placeholder } = props; - public render() { - const { searchString } = this.props; - const triggerId = 'session-search-input-context'; + const convoCount = useSelector(getConversationsCount); - return ( - <> -
{ - contextMenu.show({ - id: triggerId, - event: e, - }); - }} - > - - this.props.onChange(e.target.value)} - onKeyDown={this.handleKeyDown} - placeholder={this.props.placeholder} - /> -
- - document.execCommand('undo')}>{window.i18n('editMenuUndo')} - document.execCommand('redo')}>{window.i18n('editMenuRedo')} -
- document.execCommand('cut')}>{window.i18n('editMenuCut')} - document.execCommand('copy')}>{window.i18n('editMenuCopy')} - document.execCommand('paste')}>{window.i18n('editMenuPaste')} - document.execCommand('selectAll')}> - {window.i18n('editMenuSelectAll')} - -
- - ); + // just after onboard we only have a conversation with ourself + if (convoCount <= 1) { + return null; } - public handleKeyDown(e: any) { - if (e.keyCode === 38 || e.keyCode === 40 || e.key === 'Enter') { - // Up or Bottom arrow pressed - if (this.props.handleNavigation) { - e.stopPropagation(); - this.props.handleNavigation(e); - } - } - } -} + return ( +
+ + onChange(e.target.value)} + placeholder={placeholder} + /> +
+ ); +}; diff --git a/ts/components/session/UserSearchDropdown.tsx b/ts/components/session/UserSearchDropdown.tsx deleted file mode 100644 index 5898cdaf9..000000000 --- a/ts/components/session/UserSearchDropdown.tsx +++ /dev/null @@ -1,86 +0,0 @@ -import React from 'react'; - -import { UserSearchResults } from '../UserSearchResults'; -import { SessionSearchInput } from './SessionSearchInput'; - -import { SearchResultsProps } from '../SearchResults'; -import autoBind from 'auto-bind'; - -export interface Props { - searchTerm: string; - placeholder: string; - searchResults?: SearchResultsProps; - updateSearch: (searchTerm: string) => void; -} - -interface State { - selectedContact: number; -} - -export class UserSearchDropdown extends React.Component { - public constructor(props: Props) { - super(props); - autoBind(this); - this.state = { - selectedContact: -1, - }; - } - - public handleNavigation(e: any) { - const { selectedContact } = this.state; - const { searchResults } = this.props; - // arrow up/down button should select next/previous list element - if ( - e.keyCode === 38 && - selectedContact > 0 && - searchResults && - searchResults.contacts.length > 0 - ) { - this.setState(prevState => ({ - selectedContact: +prevState.selectedContact - 1, - })); - } else if ( - e.keyCode === 40 && - searchResults && - selectedContact < searchResults.contacts.length - 1 - ) { - this.setState(prevState => ({ - selectedContact: +prevState.selectedContact + 1, - })); - } else if (e.key === 'Enter' && searchResults && searchResults.contacts.length > 0) { - this.handleContactSelected(searchResults.contacts[selectedContact].phoneNumber); - } - } - - public render() { - const { searchResults, placeholder } = this.props; - const { selectedContact } = this.state; - - return ( -
- - {searchResults && ( - - )} -
- ); - } - - public updateSearch(data: string) { - this.setState({ selectedContact: -1 }); - this.props.updateSearch(data); - } - - public handleContactSelected(key: string) { - this.updateSearch(key); - } -} diff --git a/ts/state/createStore.ts b/ts/state/createStore.ts index 6415d096e..56f187006 100644 --- a/ts/state/createStore.ts +++ b/ts/state/createStore.ts @@ -33,12 +33,16 @@ export const persistConfig = { const persistedReducer = persistReducer(persistConfig, rootReducer); // Exclude logger if we're in production mode -const disableLogging = env === 'production' || true; // ALWAYS TURNED OFF -const middlewareList = disableLogging ? [promise] : [promise, logger]; +const disableLogging = true; //; env === 'production' || true; // ALWAYS TURNED OFF +const middlewareList = disableLogging ? [] : [logger]; export const createStore = (initialState: any) => configureStore({ reducer: persistedReducer, preloadedState: initialState, - middleware: (getDefaultMiddleware: any) => getDefaultMiddleware().concat(middlewareList), + middleware: (getDefaultMiddleware: any) => + getDefaultMiddleware({ + serializableCheck: false, + immutableCheck: false, + }).concat(middlewareList), }); diff --git a/ts/state/selectors/conversations.ts b/ts/state/selectors/conversations.ts index aa06744cd..25026cfa0 100644 --- a/ts/state/selectors/conversations.ts +++ b/ts/state/selectors/conversations.ts @@ -46,6 +46,10 @@ export const getConversationLookup = createSelector( } ); +export const getConversationsCount = createSelector(getConversationLookup, (state): number => { + return Object.values(state).length; +}); + export const getSelectedConversationKey = createSelector( getConversations, (state: ConversationsStateType): string | undefined => {