fix :komentar diskusi
Deskripsi: - list komentar bisa di lihat lebih banyak >> diskusi umum dan diskusi divisi - loading disable saat menambah komentar >> diskusi umum No Issues
This commit is contained in:
@@ -20,6 +20,7 @@ import { useHeaderHeight } from '@react-navigation/elements';
|
|||||||
import { router, Stack, useLocalSearchParams } from "expo-router";
|
import { router, Stack, useLocalSearchParams } from "expo-router";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { KeyboardAvoidingView, Platform, Pressable, ScrollView, View } from "react-native";
|
import { KeyboardAvoidingView, Platform, Pressable, ScrollView, View } from "react-native";
|
||||||
|
import Toast from "react-native-toast-message";
|
||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
@@ -54,6 +55,9 @@ export default function DetailDiscussionGeneral() {
|
|||||||
const arrSkeleton = Array.from({ length: 3 }, (_, index) => index)
|
const arrSkeleton = Array.from({ length: 3 }, (_, index) => index)
|
||||||
const reference = ref(getDB(), `/discussion-general/${id}`);
|
const reference = ref(getDB(), `/discussion-general/${id}`);
|
||||||
const headerHeight = useHeaderHeight();
|
const headerHeight = useHeaderHeight();
|
||||||
|
const [detailMore, setDetailMore] = useState<any>([])
|
||||||
|
const [loadingSendKomentar, setLoadingSendKomentar] = useState(false)
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const onValueChange = reference.on('value', snapshot => {
|
const onValueChange = reference.on('value', snapshot => {
|
||||||
@@ -116,16 +120,21 @@ export default function DetailDiscussionGeneral() {
|
|||||||
|
|
||||||
async function handleKomentar() {
|
async function handleKomentar() {
|
||||||
try {
|
try {
|
||||||
|
setLoadingSendKomentar(true)
|
||||||
if (komentar != '') {
|
if (komentar != '') {
|
||||||
const hasil = await decryptToken(String(token?.current))
|
const hasil = await decryptToken(String(token?.current))
|
||||||
const response = await apiSendDiscussionGeneralCommentar({ id: id, data: { desc: komentar, user: hasil } })
|
const response = await apiSendDiscussionGeneralCommentar({ id: id, data: { desc: komentar, user: hasil } })
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
setKomentar('')
|
setKomentar('')
|
||||||
updateTrigger()
|
updateTrigger()
|
||||||
|
} else {
|
||||||
|
Toast.show({ type: 'small', text1: 'Gagal menambahkan komentar' })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
|
} finally {
|
||||||
|
setLoadingSendKomentar(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,6 +204,16 @@ export default function DetailDiscussionGeneral() {
|
|||||||
title={item.username}
|
title={item.username}
|
||||||
rightTopInfo={item.createdAt}
|
rightTopInfo={item.createdAt}
|
||||||
desc={item.comment}
|
desc={item.comment}
|
||||||
|
descEllipsize={detailMore.includes(item.id) ? false : true}
|
||||||
|
onPress={() => {
|
||||||
|
setDetailMore((prev: any) => {
|
||||||
|
if (prev.includes(item.id)) {
|
||||||
|
return prev.filter((id: string) => id !== item.id)
|
||||||
|
} else {
|
||||||
|
return [...prev, item.id]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@@ -225,14 +244,14 @@ export default function DetailDiscussionGeneral() {
|
|||||||
multiline
|
multiline
|
||||||
itemRight={
|
itemRight={
|
||||||
<Pressable onPress={() => {
|
<Pressable onPress={() => {
|
||||||
(komentar != '' && !regexOnlySpacesOrEnter.test(komentar) && data?.status === 1 && data?.isActive && (memberDiscussion || (entityUser.role != "user" && entityUser.role != "coadmin")))
|
(!loadingSendKomentar && komentar != '' && !regexOnlySpacesOrEnter.test(komentar) && data?.status === 1 && data?.isActive && (memberDiscussion || (entityUser.role != "user" && entityUser.role != "coadmin")))
|
||||||
&& handleKomentar()
|
&& handleKomentar()
|
||||||
}}
|
}}
|
||||||
style={[
|
style={[
|
||||||
Platform.OS == 'android' && Styles.mb12,
|
Platform.OS == 'android' && Styles.mb12,
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
<MaterialIcons name="send" size={25} style={(komentar == '' || regexOnlySpacesOrEnter.test(komentar) || data?.status === 2 || !data?.isActive || (!memberDiscussion && (entityUser.role == "user" || entityUser.role == "coadmin"))) ? Styles.cGray : Styles.cDefault} />
|
<MaterialIcons name="send" size={25} style={(loadingSendKomentar || komentar == '' || regexOnlySpacesOrEnter.test(komentar) || data?.status === 2 || !data?.isActive || (!memberDiscussion && (entityUser.role == "user" || entityUser.role == "coadmin"))) ? Styles.cGray : Styles.cDefault} />
|
||||||
</Pressable>
|
</Pressable>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ export default function DiscussionDetail() {
|
|||||||
const reference = ref(getDB(), `/discussion-division/${detail}`);
|
const reference = ref(getDB(), `/discussion-division/${detail}`);
|
||||||
const [refreshing, setRefreshing] = useState(false)
|
const [refreshing, setRefreshing] = useState(false)
|
||||||
const headerHeight = useHeaderHeight();
|
const headerHeight = useHeaderHeight();
|
||||||
|
const [detailMore, setDetailMore] = useState<any>([])
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -276,7 +277,16 @@ export default function DiscussionDetail() {
|
|||||||
title={item.username}
|
title={item.username}
|
||||||
rightTopInfo={item.createdAt}
|
rightTopInfo={item.createdAt}
|
||||||
desc={item.comment}
|
desc={item.comment}
|
||||||
descEllipsize={false}
|
descEllipsize={detailMore.includes(item.id) ? false : true}
|
||||||
|
onPress={() => {
|
||||||
|
setDetailMore((prev: any) => {
|
||||||
|
if (prev.includes(item.id)) {
|
||||||
|
return prev.filter((id: string) => id !== item.id)
|
||||||
|
} else {
|
||||||
|
return [...prev, item.id]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user