diff --git a/src/components/left/settings/SettingsPrivacyVisibilityExceptionList.tsx b/src/components/left/settings/SettingsPrivacyVisibilityExceptionList.tsx index 746585fe7..d9369e7d1 100644 --- a/src/components/left/settings/SettingsPrivacyVisibilityExceptionList.tsx +++ b/src/components/left/settings/SettingsPrivacyVisibilityExceptionList.tsx @@ -64,7 +64,7 @@ const SettingsPrivacyVisibilityExceptionList: FC = ({ // No need for expensive global updates on chats, so we avoid them const chatsById = getGlobal().chats.byId; - const chatIds = unique([...folderAllOrderedIds, ...folderArchivedOrderedIds]) + const chatIds = unique([...folderAllOrderedIds || [], ...folderArchivedOrderedIds || []]) .filter((chatId) => { const chat = chatsById[chatId]; return chat && ((isUserId(chat.id) && chat.id !== currentUserId) || isChatGroup(chat)); diff --git a/src/components/left/settings/folders/SettingsFoldersChatFilters.tsx b/src/components/left/settings/folders/SettingsFoldersChatFilters.tsx index b454532a8..8212ae971 100644 --- a/src/components/left/settings/folders/SettingsFoldersChatFilters.tsx +++ b/src/components/left/settings/folders/SettingsFoldersChatFilters.tsx @@ -52,7 +52,7 @@ const SettingsFoldersChatFilters: FC = ({ // No need for expensive global updates on chats, so we avoid them const chatsById = getGlobal().chats.byId; - const chatIds = [...folderAllOrderedIds, ...folderArchivedOrderedIds]; + const chatIds = [...folderAllOrderedIds || [], ...folderArchivedOrderedIds || []]; return unique([ ...selectedChatIds, ...filterChatsByName(lang, chatIds, chatsById, chatFilter), diff --git a/src/components/right/management/ManageGroup.tsx b/src/components/right/management/ManageGroup.tsx index 398290b63..9065caff8 100644 --- a/src/components/right/management/ManageGroup.tsx +++ b/src/components/right/management/ManageGroup.tsx @@ -87,7 +87,7 @@ const ManageGroup: FC = ({ const currentAbout = chat.fullInfo ? (chat.fullInfo.about || '') : ''; const [isProfileFieldsTouched, setIsProfileFieldsTouched] = useState(false); - const [title, setTitle] = useState(currentTitle); + const [title, setTitle] = useState(currentTitle || ''); const [about, setAbout] = useState(currentAbout); const [photo, setPhoto] = useState(); const [error, setError] = useState(); diff --git a/src/components/right/management/ManageGroupAdminRights.tsx b/src/components/right/management/ManageGroupAdminRights.tsx index 714a6c720..cc83b7eff 100644 --- a/src/components/right/management/ManageGroupAdminRights.tsx +++ b/src/components/right/management/ManageGroupAdminRights.tsx @@ -57,7 +57,7 @@ const ManageGroupAdminRights: FC = ({ const { updateChatAdmin } = getDispatch(); const [permissions, setPermissions] = useState({}); - const [isTouched, setIsTouched] = useState(isNewAdmin); + const [isTouched, setIsTouched] = useState(Boolean(isNewAdmin)); const [isLoading, setIsLoading] = useState(false); const [isDismissConfirmationDialogOpen, openDismissConfirmationDialog, closeDismissConfirmationDialog] = useFlag(); const [customTitle, setCustomTitle] = useState(''); diff --git a/src/components/right/management/ManageReactions.tsx b/src/components/right/management/ManageReactions.tsx index 2071c9cd2..9ec4953fe 100644 --- a/src/components/right/management/ManageReactions.tsx +++ b/src/components/right/management/ManageReactions.tsx @@ -38,7 +38,7 @@ const ManageReactions: FC = ({ const lang = useLang(); const [isTouched, setIsTouched] = useState(false); const [isLoading, setIsLoading] = useState(false); - const [localEnabledReactions, setLocalEnabledReactions] = useState(enabledReactions); + const [localEnabledReactions, setLocalEnabledReactions] = useState(enabledReactions || []); useHistoryBack(isActive, onClose); @@ -53,9 +53,11 @@ const ManageReactions: FC = ({ }, [chat, localEnabledReactions, setChatEnabledReactions]); useEffect(() => { - setIsLoading(false); - setIsTouched(false); - setLocalEnabledReactions(enabledReactions || []); + if (enabledReactions) { + setIsLoading(false); + setIsTouched(false); + setLocalEnabledReactions(enabledReactions); + } }, [enabledReactions]); const handleReactionChange = useCallback((e: React.ChangeEvent) => { diff --git a/src/lib/teact/teact.ts b/src/lib/teact/teact.ts index 465bc8659..7224dcd51 100644 --- a/src/lib/teact/teact.ts +++ b/src/lib/teact/teact.ts @@ -463,6 +463,8 @@ export function setTarget($element: VirtualElement, target: Node) { } } +export function useState(): [T, StateHookSetter]; +export function useState(initial: T): [T, StateHookSetter]; export function useState(initial?: T): [T, StateHookSetter] { const { cursor, byCursor } = renderingInstance.hooks.state; diff --git a/src/util/folderManager.ts b/src/util/folderManager.ts index 1710ac428..5634a42e0 100644 --- a/src/util/folderManager.ts +++ b/src/util/folderManager.ts @@ -79,12 +79,12 @@ const prepared: { }; const results: { - orderedIdsByFolderId: Record; - chatsCountByFolderId: Record; + orderedIdsByFolderId: Record; + chatsCountByFolderId: Record; unreadCountersByFolderId: Record; + } | undefined>; } = { orderedIdsByFolderId: {}, chatsCountByFolderId: {}, @@ -596,7 +596,7 @@ function buildFolderUnreadCounters(folderId: number) { orderedIdsByFolderId: { [folderId]: orderedIds }, } = results; - return orderedIds.reduce((newUnreadCounters, chatId) => { + return orderedIds!.reduce((newUnreadCounters, chatId) => { const chatSummary = chatSummariesById.get(chatId); if (!chatSummary) { return newUnreadCounters;