[Dev] Teact: Fix useState typing

This commit is contained in:
Alexander Zinchuk 2022-02-02 22:49:06 +01:00
parent e7026aa16c
commit 5f6040b82c
7 changed files with 16 additions and 12 deletions

View File

@ -64,7 +64,7 @@ const SettingsPrivacyVisibilityExceptionList: FC<OwnProps & StateProps> = ({
// 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));

View File

@ -52,7 +52,7 @@ const SettingsFoldersChatFilters: FC<OwnProps> = ({
// 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),

View File

@ -87,7 +87,7 @@ const ManageGroup: FC<OwnProps & StateProps> = ({
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<File | undefined>();
const [error, setError] = useState<string | undefined>();

View File

@ -57,7 +57,7 @@ const ManageGroupAdminRights: FC<OwnProps & StateProps> = ({
const { updateChatAdmin } = getDispatch();
const [permissions, setPermissions] = useState<ApiChatAdminRights>({});
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('');

View File

@ -38,7 +38,7 @@ const ManageReactions: FC<OwnProps & StateProps> = ({
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<OwnProps & StateProps> = ({
}, [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<HTMLInputElement>) => {

View File

@ -463,6 +463,8 @@ export function setTarget($element: VirtualElement, target: Node) {
}
}
export function useState<T>(): [T, StateHookSetter<T>];
export function useState<T>(initial: T): [T, StateHookSetter<T>];
export function useState<T>(initial?: T): [T, StateHookSetter<T>] {
const { cursor, byCursor } = renderingInstance.hooks.state;

View File

@ -79,12 +79,12 @@ const prepared: {
};
const results: {
orderedIdsByFolderId: Record<string, string[]>;
chatsCountByFolderId: Record<string, number>;
orderedIdsByFolderId: Record<string, string[] | undefined>;
chatsCountByFolderId: Record<string, number | undefined>;
unreadCountersByFolderId: Record<string, {
chatsCount: number;
notificationsCount: number;
}>;
} | 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;