mirror of
https://github.com/lux-tel/session-desktop.git
synced 2026-10-30 20:33:24 +00:00
67 lines
2.1 KiB
TypeScript
67 lines
2.1 KiB
TypeScript
import { noop } from 'lodash';
|
|
import { getAppDispatch } from '../../../../state/dispatch';
|
|
import { tr } from '../../../../localization/localeTools';
|
|
import {
|
|
ConversationSettingsModalPage,
|
|
ConversationSettingsModalState,
|
|
updateConversationSettingsModal,
|
|
} from '../../../../state/ducks/modalDialog';
|
|
import { assertUnreachable } from '../../../../types/sqlSharedTypes';
|
|
import { useShowConversationSettingsFor } from '../../../menuAndSettingsHooks/useShowConversationSettingsFor';
|
|
|
|
export function useTitleFromPage(page: ConversationSettingsModalPage | undefined) {
|
|
switch (page) {
|
|
case 'disappearing_message':
|
|
return tr('disappearingMessages');
|
|
case 'notifications':
|
|
return tr('sessionNotifications');
|
|
case 'default':
|
|
case undefined:
|
|
return tr('sessionSettings');
|
|
default:
|
|
assertUnreachable(page, "useTitleFromPage doesn't support this page");
|
|
throw new Error('useTitleFromPage does not support this page');
|
|
}
|
|
}
|
|
|
|
export function useCloseActionFromPage(props: ConversationSettingsModalState) {
|
|
const dispatch = getAppDispatch();
|
|
const showConvoSettingsCb = useShowConversationSettingsFor(props?.conversationId);
|
|
if (!props?.conversationId || !showConvoSettingsCb) {
|
|
return noop;
|
|
}
|
|
switch (props.settingsModalPage) {
|
|
case 'disappearing_message':
|
|
case 'notifications':
|
|
return props.standalonePage
|
|
? () => dispatch(updateConversationSettingsModal(null))
|
|
: () =>
|
|
showConvoSettingsCb?.({
|
|
settingsModalPage: 'default',
|
|
});
|
|
|
|
default:
|
|
return () => dispatch(updateConversationSettingsModal(null));
|
|
}
|
|
}
|
|
|
|
export function useBackActionForPage(modalState: ConversationSettingsModalState) {
|
|
const showConvoSettingsCb = useShowConversationSettingsFor(modalState?.conversationId);
|
|
|
|
if (
|
|
!modalState?.settingsModalPage ||
|
|
modalState?.settingsModalPage === 'default' ||
|
|
modalState?.standalonePage ||
|
|
!showConvoSettingsCb
|
|
) {
|
|
// no back button if we are on the default page or if the page is standalone
|
|
return undefined;
|
|
}
|
|
|
|
return () => {
|
|
showConvoSettingsCb({
|
|
settingsModalPage: 'default',
|
|
});
|
|
};
|
|
}
|