缺陷优化
This commit is contained in:
@@ -78,7 +78,7 @@ export const UserInfoCard: React.FC<UserInfoCardProps> = ({
|
||||
useState(false);
|
||||
|
||||
// 表单状态
|
||||
const [form_data, setFormData] = useState<Partial<UserInfoType>>({
|
||||
const [form_data] = useState<Partial<UserInfoType>>({
|
||||
...user_info,
|
||||
});
|
||||
|
||||
@@ -143,12 +143,14 @@ export const UserInfoCard: React.FC<UserInfoCardProps> = ({
|
||||
const update_data = { [editing_field]: value };
|
||||
await UserService.update_user_info(update_data);
|
||||
|
||||
await updateUserInfo({ [editing_field]: value });
|
||||
|
||||
// 更新本地状态
|
||||
setFormData((prev) => {
|
||||
const updated = { ...prev, [editing_field]: value };
|
||||
typeof set_user_info === "function" && set_user_info(updated);
|
||||
return updated;
|
||||
});
|
||||
// setFormData((prev) => {
|
||||
// const updated = { ...prev, [editing_field]: value };
|
||||
// typeof set_user_info === "function" && set_user_info(updated);
|
||||
// return updated;
|
||||
// });
|
||||
|
||||
// 关闭弹窗
|
||||
setEditModalVisible(false);
|
||||
@@ -180,14 +182,14 @@ export const UserInfoCard: React.FC<UserInfoCardProps> = ({
|
||||
) {
|
||||
await updateUserInfo({ ...field });
|
||||
// 更新本地状态
|
||||
setFormData((prev) => ({ ...prev, ...field }));
|
||||
// setFormData((prev) => ({ ...prev, ...field }));
|
||||
// setUserInfo((prev) => ({ ...prev, ...field }));
|
||||
} else {
|
||||
// 调用更新用户信息接口,只传递修改的字段
|
||||
const update_data = { [field as string]: value };
|
||||
await updateUserInfo(update_data);
|
||||
// 更新本地状态
|
||||
setFormData((prev) => ({ ...prev, [field as string]: value }));
|
||||
// setFormData((prev) => ({ ...prev, [field as string]: value }));
|
||||
// setUserInfo((prev) => ({ ...prev, [field as string]: value }));
|
||||
}
|
||||
|
||||
@@ -259,6 +261,22 @@ export const UserInfoCard: React.FC<UserInfoCardProps> = ({
|
||||
// 主办和参加暂时不处理,可以后续扩展
|
||||
};
|
||||
|
||||
const getDefaultOption = (options) => {
|
||||
if (!Array.isArray(options) || options.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const defaultOptions: string[] = [];
|
||||
let current = options[0];
|
||||
|
||||
while (current) {
|
||||
defaultOptions.push(current.text);
|
||||
current = current.children?.[0];
|
||||
}
|
||||
|
||||
return defaultOptions;
|
||||
}
|
||||
|
||||
return (
|
||||
<View className="user_info_card">
|
||||
{/* 头像和基本信息 */}
|
||||
@@ -385,7 +403,7 @@ export const UserInfoCard: React.FC<UserInfoCardProps> = ({
|
||||
<Text>选择性别</Text>
|
||||
</View>
|
||||
) : null}
|
||||
{user_info.ntrp_level ? (
|
||||
{user_info.ntrp_level !== "0" ? (
|
||||
<View className="tag_item">
|
||||
<Text className="tag_text">{`NTRP ${user_info.ntrp_level}`}</Text>
|
||||
</View>
|
||||
@@ -472,7 +490,7 @@ export const UserInfoCard: React.FC<UserInfoCardProps> = ({
|
||||
]}
|
||||
visible={gender_picker_visible}
|
||||
setvisible={setGenderPickerVisible}
|
||||
value={[form_data.gender || ""]}
|
||||
value={form_data.gender === "" ? ["0"] : [form_data.gender]}
|
||||
onChange={handle_gender_change}
|
||||
/>
|
||||
)}
|
||||
@@ -484,11 +502,7 @@ export const UserInfoCard: React.FC<UserInfoCardProps> = ({
|
||||
options={cities}
|
||||
visible={location_picker_visible}
|
||||
setvisible={setLocationPickerVisible}
|
||||
value={[
|
||||
form_data.country || "",
|
||||
form_data.province || "",
|
||||
form_data.city || "",
|
||||
]}
|
||||
value={form_data.country ? [form_data.country, form_data.province, form_data.city] : getDefaultOption(cities)}
|
||||
onChange={handle_location_change}
|
||||
/>
|
||||
)}
|
||||
@@ -512,7 +526,7 @@ export const UserInfoCard: React.FC<UserInfoCardProps> = ({
|
||||
img={user_info.avatar_url || ""}
|
||||
visible={ntrp_picker_visible}
|
||||
setvisible={setNtrpPickerVisible}
|
||||
value={[form_data.ntrp_level || ""]}
|
||||
value={form_data.ntrp_level === "0" ? ["3.0"] : [form_data.ntrp_level]}
|
||||
onChange={handle_ntrp_level_change}
|
||||
/>
|
||||
)}
|
||||
@@ -524,7 +538,7 @@ export const UserInfoCard: React.FC<UserInfoCardProps> = ({
|
||||
options={professions}
|
||||
visible={occupation_picker_visible}
|
||||
setvisible={setOccupationPickerVisible}
|
||||
value={[...(form_data.occupation || "").split(" ")]}
|
||||
value={form_data.occupation ? [...form_data.occupation.split(" ")] : getDefaultOption(professions)}
|
||||
onChange={handle_occupation_change}
|
||||
/>
|
||||
)}
|
||||
@@ -665,9 +679,8 @@ export const GameTabs: React.FC<GameTabsProps> = ({
|
||||
<Text className="tab_text">{hosted_text}</Text>
|
||||
</View>
|
||||
<View
|
||||
className={`tab_item ${
|
||||
active_tab === "participated" ? "active" : ""
|
||||
}`}
|
||||
className={`tab_item ${active_tab === "participated" ? "active" : ""
|
||||
}`}
|
||||
onClick={() => on_tab_change("participated")}
|
||||
>
|
||||
<Text className="tab_text">{participated_text}</Text>
|
||||
|
||||
Reference in New Issue
Block a user