Explore / Programming import { MessageType, RoomType, TodoOptionType } from "@openchat/types" import {… Save Share Download ▾ Reportimport { MessageType, RoomType, TodoOptionType } from "@openchat/types"
import { RandomUtils } from "@openchat/core"
import { useEffect, useState } from "react"
import { Pressable, View, TouchableOpacity } from "react-native"
import { StyledText } from "../../../ui-components/styled-text/styled-text"
import {
NestableDraggableFlatList,
NestableScrollContainer,
RenderItemParams,
} from "react-native-draggable-flatlist"
import Modal from "react-native-modal"
import { Button } from "../../../ui-components/button/button.component"
import { Checkbox } from "../../../ui-components/checkbox/checkbox.component"
import { Input } from "../../../ui-components/input/input"
import { MenuOpener } from "../../../ui-components/menu/menu-opener.provider"
import { EditDeleteTodos } from "./edit-delete-todos.component"
import { styles } from "./message-board-card-info-modal-todos.styles.module"
import { SvgXml } from "react-native-svg"
import {
bgHeaderModal,
bgSVG,
bigVerticalLienForTodoEdit,
pencilIcon,
} from "../../../ui-components/svgIcons/svgIcons"
import { ConfirmationModalize } from "../../../ui-components/confirmation-modalize/confirmation-modalize.component"
import { Icon } from "../../../ui-components/icon/icon.component"
import { useRoomMetadata } from "@openchat/ui"
import { AppColors } from "../../../app/app.colors"
import { MessageBoardCardInfoPopup } from "./message-board-card-info-popup"
import { useModal } from "../../../ui-components/modal/modal.hook"
export const MessageBoardCardInfoModalTodos = ({
message,
todoOptions,
setTodoOptions,
room,
testID,
setIsDisableScrollInDrag,
}: {
message: MessageType
todoOptions: TodoOptionType[]
setTodoOptions: (todoOptions: TodoOptionType[]) => void
room: RoomType
testID?: string
setIsDisableScrollInDrag: (arg: boolean) => void
}) => {
// ---------------------------------------------------------------------------
// variables
// ---------------------------------------------------------------------------
const modal = useModal()
const [name, setName] = useState("")
const [isModalOpened, setModalOpened] = useState(false)
const [updateTodo, setUpdateTodo] = useState()
const [contentType, setContentType] = useState<"create" | "delete">("create")
const [deleteTodoId, setDeleteTodoId] = useState("")
const { community, channel, group, user } = useRoomMetadata(room.id)
console.log("====================================")
console.log("todo options: ", todoOptions)
console.log("====================================")
// ---------------------------------------------------------------------------
// effects
// ---------------------------------------------------------------------------
useEffect(() => {
setTodoOptions(todoOptions.sort((a, b) => a.order - b.order))
}, [todoOptions])
useEffect(() => {
if (updateTodo && updateTodo.name) setName(updateTodo.name)
}, [updateTodo && updateTodo.name])
// ---------------------------------------------------------------------------
// functions
// ---------------------------------------------------------------------------
Show full message · 534 lines AssistantCopy response
The issue being described refers to a common problem in React where an input becomes "uncontrolled." This usually happens when the input's value is null or undefined at some point after initialization, which can make the input lose its controlled state.
In the provided code snippet, you're using the state to control the value of the component. Therefore, to ensure it remains a controlled component, you must ensure that the state is never undefined or null. Initially, you've correctly set it up as an empty string in your hook. However, there might be scenarios or lifecycle events that could inadvertently set it to undefined or null, thereby causing the input to become uncontrolled.
Copy first prompt
Details
Provider openai
Model provenance As recorded by source dataset
Turns 1 (2 messages)
Language —
Added to archive Nov 21, 2026
ID 01m7y2ke8fvg8z555n2kvhvw0qSource & license Imported from Suzhen/CodeChat (source ). Imported records earn no Research Points.
Upstream record: 4d8463f4a6d03c910e6ae425868b1a87
Suzhen/CodeChat, revision 1681793a6cfb27b68c1f285bd1e78588132bc1c1.
License: ODC-BY-1.0
Dataset releases Not yet included in a published release.
async function saveTodo() {
if (!name || !message.board || !community) return
setTodoOptions([
...todoOptions,
{
id: RandomUtils.uuid(),
name: name,
isChecked: false,
order: todoOptions.length,
},
])
// setModalOpened(false)
setName("")
}
async function remoteUpdateTodo(updatedTodo: any, isChecked: boolean) {
if (!message.board || !todoOptions || !community) return
setTodoOptions([
...todoOptions.map((option) => {
if (updatedTodo.id !== option.id) return option
return {
...option,
isChecked: isChecked,
}
}),
])
}
async function remoteUpdateNameTodo(updatedId: string, name: string) {
if (!message.board || !todoOptions || !community) return
setTodoOptions([
...todoOptions.map((option) => {
if (updatedId !== option.id) return option
return {
...option,
name: name,
}
}),
])
setName("")
}
async function removeTodo(optionId: string) {
if (!message.board || !todoOptions || !community) return
setTodoOptions([...todoOptions.filter((option) => option.id !== optionId)])
}
// ---------------------------------------------------------------------------
// render functions
// ---------------------------------------------------------------------------
function openTodoPopup(currentTodo: TodoOptionType) {
return (
<EditDeleteTodos
option={currentTodo}
removeTodo={removeTodo}
setUpdateTodo={setUpdateTodo}
setContentType={setContentType}
/>
)
}
// function onDragEnd(reorderTodoOptions: TodoOptionType[]) {
// const reordered = reorderTodoOptions.map((reorderOption, index) => {
// const reorder = todoOptions.find((it) => it.id === reorderOption.id)!
// reorder.order = index + 1
// return reorder
// })
// setTodoOptions(reordered)
// }
function onDragEnd(reorderTodoOptions: TodoOptionType[]) {
const reordered = reorderTodoOptions.map((reorderOption, index) => {
const existingTodoOption = todoOptions.find(
(it) => it.id === reorderOption.id,
)!
const updatedTodoOption = {
...existingTodoOption,
order: index + 1,
}
return updatedTodoOption
})
setTodoOptions(reordered)
}
// const renderItem = ({
// item: todoOption,
// isActive,
// drag,
// }: RenderItemParams) => {
// return (
//
// <View style={{ flexDirection: "row", gap: 20 }}>
// <TouchableOpacity
// onLongPress={() => {
// drag()
// }}
// >
// {isActive ? (
//
// ) : (
//
// )}
//
// <Checkbox
// checked={todoOption.isChecked}
// onClick={(isChecked) => remoteUpdateTodo(todoOption, isChecked)}
// />
//
// <View
// style={{
// flexDirection: "row",
// justifyContent: "space-between",
// flexGrow: 1,
// paddingLeft: 20,
// flex: 1,
// }}
// >
// <StyledText
// testID={${testID}.todo.${todoOption.order}}
// onLongPress={drag}
// style={{
// fontSize: 16,
// fontWeight: "400",
// color: "#000",
// fontFamily: "Source Sans Pro",
// width: "95%",
// }}
// >
// {todoOption.name}
//
// <View style={{ position: "relative", right: -5 }}>
// <Pressable testID={${testID}.${todoOption.order}.editIcon}>
// <MenuOpener
// content={openTodoPopup(todoOption)}
// style={{ marginLeft: -20 }}
// >
//
//
//
//
//
//
// )
// }
const renderItem = ({
item,
drag,
isActive,
}: RenderItemParams) => {
return (
<View
style={{
flex: 1,
flexDirection: "row",
gap: 10,
alignItems: "center",
}}
>
<TouchableOpacity
onLongPress={() => {
console.log("====================================")
console.log("123333333", todoOptions)
console.log("====================================")
drag()
}}
>
{isActive ? (
<Icon
name="fa-solid fa-grid-round"
bald={true}
size={16}
fill={AppColors.textSecondaryGray}
/>
) : (
<Icon
bald={true}
name="fa-sharp fa-light fa-grip-lines"
size={16}
fill={AppColors.textSecondaryGray}
/>
)}
<StyledText
numberOfLines={1}
ellipsizeMode="tail"
style={styles.folderName}
>
{item.name}
<MenuOpener
position="bottom-left"
// content={}
content={openTodoPopup(item)}
>
<Icon
name="fa-regular fa-ellipsis-vertical"
size={18}
fill={AppColors.textSecondaryGray}
/>
)
}
function addTodoItem() {
modal.open({
component: (
<View style={{ backgroundColor: AppColors.light }}>
<View style={{ position: "relative" }}>
{/* /}
<StyledText
style={{
position: "absolute",
fontFamily: "Source Sans Pro",
fontSize: 24,
fontStyle: "normal",
fontWeight: "600",
left: 20,
top: 29,
}}
>
Todos
<View
style={{
backgroundColor: AppColors.light,
paddingBottom: 20,
paddingHorizontal: 20,
}}
>
{todoOptions.length > 0 && (
<NestableDraggableFlatList
contentContainerStyle={{ gap: 10 }}
data={todoOptions}
renderItem={renderItem}
onDragBegin={() => {
setIsDisableScrollInDrag(false)
}}
keyExtractor={(item) => item.id}
onDragEnd={({ data }) => {
onDragEnd(data)
setIsDisableScrollInDrag(true)
}}
/>
)}
<View
style={{
backgroundColor: updateTodo?.name
? AppColors.backgroundLight
: "transparent",
marginHorizontal: -20,
paddingHorizontal: 20,
paddingVertical: 10,
}}
>
<View
style={{
flexDirection: "row",
marginBottom: 10,
gap: 10,
display: updateTodo?.name ? "flex" : "none",
justifyContent: "space-between",
width: "100%",
}}
>
<View
style={{
flexDirection: "row",
gap: 10,
}}
>
<View
style={{
flexDirection: "row",
gap: 15,
alignItems: "center",
}}
>
<View
style={{
justifyContent: "space-between",
}}
>
<StyledText
style={{ color: AppColors.iconDefault, fontSize: 16 }}
>
Edit
<StyledText
style={{
color: "#000",
fontSize: 14,
fontWeight: "400",
flexWrap: "wrap",
}}
>
{updateTodo?.name}
<Pressable
onPress={() => {
setUpdateTodo({
id: "",
name: "",
isChecked: false,
order: 0,
})
setName("")
}}
style={{ justifyContent: "center" }}
>
<Input
testID={${testID}.addTodoItemInput}
placeholder="Write a title"
value={name}
onChangeText={setName}
autoFocus={true}
wrapperStyle={{ backgroundColor: AppColors.light }}
/>
<Button
containerStyle={{ width: 91 }}
onPress={() => {
if (!updateTodo?.name) {
saveTodo()
} else {
remoteUpdateNameTodo(updateTodo.id, name)
setUpdateTodo({
id: "",
name: "",
isChecked: false,
order: 0,
})
}
}}
>
{updateTodo?.name ? "Save" : "Add"}
{/ <SvgXml
xml={bgSVG}
style={{
position: "absolute",
left: 0,
bottom: 0,
zIndex: -1,
}}
/> */}
),
footer: "rgb",
keyboard: 220,
})
}
// ---------------------------------------------------------------------------
return (
<View
style={{
flexDirection: "row",
justifyContent: "space-between",
alignItems: "center",
marginBottom: 20,
}}
>
Todos
<Pressable
style={{
display: todoOptions.length > 0 ? "flex" : "none",
}}
onPress={() => addTodoItem()}
>
{todoOptions.length > 0 ? (
<View style={[styles.todoList, { gap: 5 }]}>
{todoOptions.map((todo) => (
<View style={{ flexDirection: "row", gap: 20 }}>
<Checkbox
checked={todo.isChecked}
onClick={(isChecked) => remoteUpdateTodo(todo, isChecked)}
/>
<View
style={{
flexDirection: "row",
justifyContent: "space-between",
flexGrow: 1,
paddingLeft: 20,
flex: 1,
}}
>
<StyledText
testID={${testID}.todo.${todo.order}}
style={{
fontSize: 16,
fontWeight: "400",
color: "#000",
fontFamily: "Source Sans Pro",
width: "95%",
}}
>
{todo.name}
))}
) : (
<Button
onPress={() => addTodoItem()}
type="outline-small"
containerStyle={{ width: 150 }}
icon="plus"
>
Add todo item
)}
)
}
why this <Input
testID={${testID}.addTodoItemInput}
placeholder="Write a title"
value={name}
onChangeText={setName}
autoFocus={true}
wrapperStyle={{ backgroundColor: AppColors.light }}
/> is uncontrolled ? Please fix it ?
name
<Input>
name
useState
Given the current code, it looks correct regarding initializing and setting the name state. If it's behaving as an uncontrolled component, it's possible that the issue might be within the Input component itself or how the setName function is being executed.
To debug and attempt a fix, ensure the following:
Ensure setName Always Receives a String : Wherever you call setName, ensure you're passing a string value. If there's a chance it could receive undefined or null (from an API response or conditional logic), explicitly handle these cases.
Input Component Prop Types : Ensure the <Input> component is designed to handle its props correctly, especially the value and onChangeText props. If the component or one of its dependencies mistakenly changes the value prop to undefined or null, it could lead to this issue.
Here's a simple fix you can try by ensuring the name is always a string when setName is called:
javascript Copy code
<Input
testID={`${testID}.addTodoItemInput`}
placeholder="Write a title"
value={name || ''} // Ensure value is always a string
onChangeText={(text) => setName(text || '')} // Handle potential null/undefined values
autoFocus={true}
wrapperStyle={{ backgroundColor: AppColors.light }}
/>
By adding || '' you're falling back to an empty string if name or text is ever undefined or null, which ensures the Input remains controlled.
Lastly, inspect any other part of your code that might interact with the name state to ensure it's not inadvertently set to an undefined or null value after initialization.
Copy first response