Forum Screens (User Phase 5 - 17 files):
- Migrate all forum list, detail, create, and report screens to OS_Wrapper.
- ViewBeranda, ViewBeranda2, ViewBeranda3: List screens with pull-to-refresh.
- DetailForum, DetailForum2: Comment sections with headers (apply disableFlexGrow fix).
- create, edit, report-*, other-report-*, preview-report-*: Forms with keyboard handling.
Admin Phase 9 (User Access - 2 files):
- index.tsx: List with search and pagination.
- [id]/index.tsx: Detail with status toggle footer.
Scroll Fixes (Critical Bugs):
- Fix "Ghost Scroll" in Android FlatList: Removed TouchableWithoutFeedback and KeyboardAvoidingView wrappers in List Mode.
- Fix Large Header Cut-off: Added optional disableFlexGrow={true} to OS_Wrapper for screens with complex ListHeaderComponents (e.g., Forum Detail).
- Fix Keyboard Dismiss: Changed keyboardShouldPersistTaps to "handled" so taps on empty areas dismiss the keyboard while allowing scroll.
Documentation:
- Update TASK-005 with complete Phase 5 details and new progress totals.
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
112 lines
2.5 KiB
TypeScript
112 lines
2.5 KiB
TypeScript
import {
|
|
BoxButtonOnFooter,
|
|
ButtonCustom,
|
|
LoaderCustom,
|
|
OS_Wrapper,
|
|
TextAreaCustom,
|
|
} from "@/components";
|
|
import AlertWarning from "@/components/Alert/AlertWarning";
|
|
import { apiForumGetOne, apiForumUpdate } from "@/service/api-client/api-forum";
|
|
import { isBadContent } from "@/utils/badWordsIndonesia";
|
|
import { router, useFocusEffect, useLocalSearchParams } from "expo-router";
|
|
import { useCallback, useState } from "react";
|
|
import { Alert } from "react-native";
|
|
import Toast from "react-native-toast-message";
|
|
|
|
export default function ForumEdit() {
|
|
const { id } = useLocalSearchParams();
|
|
const [text, setText] = useState("");
|
|
const [loadingGetData, setLoadingGetData] = useState(false);
|
|
const [isLoading, setIsLoading] = useState(false);
|
|
|
|
useFocusEffect(
|
|
useCallback(() => {
|
|
onLoadData(id as string);
|
|
}, [id])
|
|
);
|
|
|
|
const onLoadData = async (id: string) => {
|
|
try {
|
|
setLoadingGetData(true);
|
|
const response = await apiForumGetOne({ id });
|
|
|
|
setText(response.data.diskusi);
|
|
} catch (error) {
|
|
console.log("[ERROR]", error);
|
|
} finally {
|
|
setLoadingGetData(false);
|
|
}
|
|
};
|
|
|
|
const handlerUpdateData = async () => {
|
|
if (!text) {
|
|
Toast.show({
|
|
type: "error",
|
|
text1: "Harap masukkan diskusi",
|
|
});
|
|
return;
|
|
}
|
|
|
|
if (isBadContent(text)) {
|
|
AlertWarning({});
|
|
return;
|
|
}
|
|
|
|
try {
|
|
setIsLoading(true);
|
|
const response = await apiForumUpdate({
|
|
id: id as string,
|
|
data: text,
|
|
});
|
|
|
|
if (response.success) {
|
|
Toast.show({
|
|
type: "success",
|
|
text1: "Berhasil diupdate",
|
|
});
|
|
router.back();
|
|
}
|
|
} catch (error) {
|
|
console.log("[ERROR]", error);
|
|
} finally {
|
|
setIsLoading(false);
|
|
}
|
|
};
|
|
|
|
const buttonFooter = () => {
|
|
return (
|
|
<>
|
|
{!loadingGetData && (
|
|
<BoxButtonOnFooter>
|
|
<ButtonCustom isLoading={isLoading} onPress={handlerUpdateData}>
|
|
Update
|
|
</ButtonCustom>
|
|
</BoxButtonOnFooter>
|
|
)}
|
|
</>
|
|
);
|
|
};
|
|
|
|
return (
|
|
<OS_Wrapper
|
|
enableKeyboardHandling
|
|
contentPaddingBottom={250}
|
|
footerComponent={buttonFooter()}
|
|
>
|
|
{!loadingGetData ? (
|
|
<TextAreaCustom
|
|
placeholder="Ketik diskusi anda..."
|
|
maxLength={1000}
|
|
showCount
|
|
value={text}
|
|
onChangeText={(value) => {
|
|
setText(value);
|
|
}}
|
|
/>
|
|
) : (
|
|
<LoaderCustom />
|
|
)}
|
|
</OS_Wrapper>
|
|
);
|
|
}
|