From 356161cf459ef7169be353f3303cbb2d8fd615f9 Mon Sep 17 00:00:00 2001 From: topAmity <112688936+topAmity@users.noreply.github.com> Date: Wed, 2 Oct 2024 18:48:16 +0700 Subject: [PATCH 1/4] fix category cannot load --- src/screens/CategorytList/index.tsx | 40 +++++++++-------------------- src/screens/Explore/index.tsx | 1 - 2 files changed, 12 insertions(+), 29 deletions(-) diff --git a/src/screens/CategorytList/index.tsx b/src/screens/CategorytList/index.tsx index 9d025f11..55ee31ae 100644 --- a/src/screens/CategorytList/index.tsx +++ b/src/screens/CategorytList/index.tsx @@ -14,13 +14,12 @@ import useAuth from '../../hooks/useAuth'; export default function CategoryList({ navigation }: any) { const { apiRegion } = useAuth(); - const [categories, setCategories] = useState([]); const [loading, setLoading] = useState(false); - const [hasNextPage, setHasNextPage] = useState(false); - + const [categoryObject, setCategoryObject] = useState>(); + const { data: categoryArr = [], onNextPage } = categoryObject ?? {}; const styles = useStyles(); - const onNextPageRef = useRef<(() => void) | null>(null); - const isFetchingRef = useRef(false); + + const onEndReachedCalledDuringMomentumRef = useRef(true); React.useLayoutEffect(() => { // Set the headerRight component to a TouchableOpacity @@ -33,24 +32,18 @@ export default function CategoryList({ navigation }: any) { setLoading(true); try { const unsubscribe = CategoryRepository.getCategories( - { sortBy: 'name' }, - ({ data, onNextPage, hasNextPage, loading }) => { + { sortBy: 'name', limit: 10 }, + (data) => { if (!loading) { if (data) { - const oldData = [...categories, ...data]; - oldData.sort((a, b) => b.name.localeCompare(a.name)); - setCategories(oldData); + setCategoryObject(data); } - setHasNextPage(hasNextPage); - onNextPageRef.current = onNextPage; - isFetchingRef.current = false; - unsubscribe(); } } ); + unsubscribe(); } catch (error) { console.error('Failed to load categories:', error); - isFetchingRef.current = false; } finally { setLoading(false); } @@ -94,26 +87,17 @@ export default function CategoryList({ navigation }: any) { ); }; - const handleEndReached = useCallback(() => { - if ( - !isFetchingRef.current && - hasNextPage && - !onEndReachedCalledDuringMomentumRef.current - ) { - isFetchingRef.current = true; - onEndReachedCalledDuringMomentumRef.current = true; - onNextPageRef.current && onNextPageRef.current(); - } - }, [hasNextPage]); + const handleEndReached=()=>{ + onNextPage && onNextPage() + } return ( item.categoryId.toString()} ListFooterComponent={renderFooter} - // onEndReached={handleEndReached} onEndReached={handleEndReached} onMomentumScrollBegin={() => (onEndReachedCalledDuringMomentumRef.current = false) diff --git a/src/screens/Explore/index.tsx b/src/screens/Explore/index.tsx index 6db53a30..a6eb5279 100644 --- a/src/screens/Explore/index.tsx +++ b/src/screens/Explore/index.tsx @@ -51,7 +51,6 @@ export default function Explore() { { sortBy: 'name', limit: 8 }, ({ data }) => { if (data) { - data.sort((a, b) => b.name.localeCompare(a.name)); setCategoryList(data); } } From 3045fff027c347740cd3b530549bb2bfc93ffbe1 Mon Sep 17 00:00:00 2001 From: topAmity <112688936+topAmity@users.noreply.github.com> Date: Thu, 3 Oct 2024 15:34:25 +0700 Subject: [PATCH 2/4] remove loading --- src/screens/CategorytList/index.tsx | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/src/screens/CategorytList/index.tsx b/src/screens/CategorytList/index.tsx index 55ee31ae..28c78dc0 100644 --- a/src/screens/CategorytList/index.tsx +++ b/src/screens/CategorytList/index.tsx @@ -1,10 +1,9 @@ import { CategoryRepository } from '@amityco/ts-sdk-react-native'; -import React, { useEffect, useState, useCallback, useRef } from 'react'; +import React, { useEffect, useState, useRef } from 'react'; import { FlatList, View, Text, - ActivityIndicator, Image, TouchableOpacity, } from 'react-native'; @@ -14,7 +13,7 @@ import useAuth from '../../hooks/useAuth'; export default function CategoryList({ navigation }: any) { const { apiRegion } = useAuth(); - const [loading, setLoading] = useState(false); + const [categoryObject, setCategoryObject] = useState>(); const { data: categoryArr = [], onNextPage } = categoryObject ?? {}; const styles = useStyles(); @@ -22,19 +21,17 @@ export default function CategoryList({ navigation }: any) { const onEndReachedCalledDuringMomentumRef = useRef(true); React.useLayoutEffect(() => { - // Set the headerRight component to a TouchableOpacity navigation.setOptions({ headerLeft: () => , }); }, [navigation]); useEffect(() => { const loadCategories = async () => { - setLoading(true); try { const unsubscribe = CategoryRepository.getCategories( - { sortBy: 'name', limit: 10 }, + { sortBy: 'name', limit: 12 }, (data) => { - if (!loading) { + if (!data.loading) { if (data) { setCategoryObject(data); } @@ -44,13 +41,9 @@ export default function CategoryList({ navigation }: any) { unsubscribe(); } catch (error) { console.error('Failed to load categories:', error); - } finally { - setLoading(false); - } + } }; - loadCategories(); - // eslint-disable-next-line react-hooks/exhaustive-deps }, []); const handleCategoryClick = (categoryId: string, categoryName: string) => { setTimeout(() => { @@ -78,14 +71,6 @@ export default function CategoryList({ navigation }: any) { ); }; - const renderFooter = () => { - if (!loading) return null; - return ( - - - - ); - }; const handleEndReached=()=>{ onNextPage && onNextPage() @@ -97,7 +82,6 @@ export default function CategoryList({ navigation }: any) { data={categoryArr} renderItem={renderCategory} keyExtractor={(item) => item.categoryId.toString()} - ListFooterComponent={renderFooter} onEndReached={handleEndReached} onMomentumScrollBegin={() => (onEndReachedCalledDuringMomentumRef.current = false) From 29c367320932c33edbc3ef81933246db1e599fed Mon Sep 17 00:00:00 2001 From: ptchaya_p Date: Mon, 7 Oct 2024 10:12:15 +0700 Subject: [PATCH 3/4] chore: upgrade sdk version --- example/ios/Podfile.lock | 4 ++-- package.json | 2 +- yarn.lock | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index f923527f..51a4a555 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -1,5 +1,5 @@ PODS: - - amity-react-native-social-ui-kit (4.0.0-beta-13): + - amity-react-native-social-ui-kit (4.0.0-beta-14): - RCT-Folly (= 2021.07.22.00) - React-Core - ApiVideoLiveStream (1.4.1): @@ -877,7 +877,7 @@ EXTERNAL SOURCES: :path: "../node_modules/react-native/ReactCommon/yoga" SPEC CHECKSUMS: - amity-react-native-social-ui-kit: fb1f7b715ce5649d0389b5000c2e03aa13c565d0 + amity-react-native-social-ui-kit: 50704b159c7e9c098bda05571317a765e909d36c ApiVideoLiveStream: 8f9dce7f6d15d5e4bb3c7a25e406bf2a36337a5a boost: 57d2868c099736d80fcd648bf211b4431e51a558 CocoaAsyncSocket: 065fd1e645c7abab64f7a6a2007a48038fdc6a99 diff --git a/package.json b/package.json index 14415f6b..7cc111d6 100644 --- a/package.json +++ b/package.json @@ -209,7 +209,7 @@ ] }, "dependencies": { - "@amityco/ts-sdk-react-native": "^6.30.0", + "@amityco/ts-sdk-react-native": "^6.30.4", "@amityco/video-broadcaster-react-native": "^1.0.0", "@amityco/video-player-react-native": "^1.0.0", "@devvie/bottom-sheet": "^0.3.0", diff --git a/yarn.lock b/yarn.lock index 16a3280e..d80fe6df 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,10 +2,10 @@ # yarn lockfile v1 -"@amityco/ts-sdk-react-native@^6.30.0": - version "6.30.2" - resolved "https://registry.yarnpkg.com/@amityco/ts-sdk-react-native/-/ts-sdk-react-native-6.30.2.tgz#c82c8f3c80549db4fb9f607901c388d20cd9dafb" - integrity sha512-QRmaeuY/m3zgwrT07TgYpuCEvxobvEorEdsT8XdV8aqgcOBn/3G4o+v7j4HmW98NIPfaM7qlnT6hVUn18dj7XA== +"@amityco/ts-sdk-react-native@^6.30.4": + version "6.30.4" + resolved "https://registry.yarnpkg.com/@amityco/ts-sdk-react-native/-/ts-sdk-react-native-6.30.4.tgz#d260ae73ffc10c88ae1b86719be5e711e5b801ed" + integrity sha512-5P0/VcyvH9AaSII6Pk/ZRQUTzDG+uJDRuKRNV3CMYOjlotkYWLcoOwgik94oSoVZoTyKYwjvLBwTSiSlyXEByg== dependencies: "@react-native-async-storage/async-storage" "^1.17.7" "@react-native-community/netinfo" "^9.4.1" From 54195154259d38553b7785afb51843e673f8466b Mon Sep 17 00:00:00 2001 From: ptchaya_p Date: Mon, 7 Oct 2024 10:14:54 +0700 Subject: [PATCH 4/4] chore: v4.0.0-beta-15 --- example/ios/Podfile.lock | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 51a4a555..da6bfb8d 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -1,5 +1,5 @@ PODS: - - amity-react-native-social-ui-kit (4.0.0-beta-14): + - amity-react-native-social-ui-kit (4.0.0-beta-15): - RCT-Folly (= 2021.07.22.00) - React-Core - ApiVideoLiveStream (1.4.1): @@ -877,7 +877,7 @@ EXTERNAL SOURCES: :path: "../node_modules/react-native/ReactCommon/yoga" SPEC CHECKSUMS: - amity-react-native-social-ui-kit: 50704b159c7e9c098bda05571317a765e909d36c + amity-react-native-social-ui-kit: 8459a53363296105a59f9fcd844f264e199e26f3 ApiVideoLiveStream: 8f9dce7f6d15d5e4bb3c7a25e406bf2a36337a5a boost: 57d2868c099736d80fcd648bf211b4431e51a558 CocoaAsyncSocket: 065fd1e645c7abab64f7a6a2007a48038fdc6a99 diff --git a/package.json b/package.json index 7cc111d6..d006e81e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "amity-react-native-social-ui-kit", - "version": "4.0.0-beta-14", + "version": "4.0.0-beta-15", "description": "Social UIKit", "main": "lib/commonjs/index", "module": "lib/module/index",