From 3ac440d79b054f52fc4313d52caa1246ab0a0611 Mon Sep 17 00:00:00 2001 From: Kestas Venslauskas Date: Mon, 13 May 2024 13:09:03 +0300 Subject: [PATCH] feat: general optimizations --- app/api/Types.ts | 2 +- app/car/category/useCarCategoryTemplate.ts | 4 ++ .../embeded/ArticleEmbed.tsx | 4 +- .../article/liveFeed/ArticleLiveFeed.tsx | 47 +------------- .../article/liveFeed/LiveFeedCountdown.tsx | 65 +++++++++++++++++++ .../context/ChannelContextProvider.tsx | 4 +- app/util/useFirebaseTopicSubscription.ts | 20 ++++-- ios/lrtApp.xcodeproj/project.pbxproj | 4 +- 8 files changed, 96 insertions(+), 54 deletions(-) create mode 100644 app/screens/article/liveFeed/LiveFeedCountdown.tsx diff --git a/app/api/Types.ts b/app/api/Types.ts index a21cea5..07641fe 100644 --- a/app/api/Types.ts +++ b/app/api/Types.ts @@ -226,7 +226,7 @@ export type VideoDataLiveStream = { data: { content: string; content2?: string; - content3?: string; + audio?: string; }; }; }; diff --git a/app/car/category/useCarCategoryTemplate.ts b/app/car/category/useCarCategoryTemplate.ts index 6ff1bf5..4b7b857 100644 --- a/app/car/category/useCarCategoryTemplate.ts +++ b/app/car/category/useCarCategoryTemplate.ts @@ -26,6 +26,10 @@ const useCarCategoryTemplate = (podcast?: CarPlayPodcastItem) => { const {setPlaylist} = useMediaPlayer(); useEffect(() => { + if (!podcast) { + return; + } + const t = new ListTemplate({ title: podcast?.title, id: 'lrt-list-template-podcast-' + podcast?.id, diff --git a/app/components/articleParagraphs/embeded/ArticleEmbed.tsx b/app/components/articleParagraphs/embeded/ArticleEmbed.tsx index cb81777..77da762 100644 --- a/app/components/articleParagraphs/embeded/ArticleEmbed.tsx +++ b/app/components/articleParagraphs/embeded/ArticleEmbed.tsx @@ -93,7 +93,9 @@ const ArticleEmbed: React.FC> = ({embedArray, ite ); } case 'timeline': { - return ; + return ( + + ); } case 'photoalbum': { return ( diff --git a/app/screens/article/liveFeed/ArticleLiveFeed.tsx b/app/screens/article/liveFeed/ArticleLiveFeed.tsx index 6e437c1..406916f 100644 --- a/app/screens/article/liveFeed/ArticleLiveFeed.tsx +++ b/app/screens/article/liveFeed/ArticleLiveFeed.tsx @@ -12,6 +12,7 @@ import LiveFeedArticleItem from './LiveFeedArticleItem'; import {useNavigation} from '@react-navigation/native'; import {StackNavigationProp} from '@react-navigation/stack'; import {MainStackParamList} from '../../../navigation/MainStack'; +import LiveFeedCountdown from './LiveFeedCountdown'; interface Props { id: string; @@ -20,7 +21,6 @@ interface Props { const ITEM_COUNT_INCREMENT = 5; const ArticleLiveFeed: React.FC> = ({id}) => { - const [countDown, setCountDown] = useState(60); const [itemCount, setItemCount] = useState(ITEM_COUNT_INCREMENT); const {state, reload} = useLiveFeedState(id); @@ -29,29 +29,7 @@ const ArticleLiveFeed: React.FC> = ({id}) => { const theme = useTheme(); useEffect(() => { - // Fetch articles data reload(); - - // Refresh data every 60 seconds - const interval = setInterval(() => { - setCountDown(60); - reload(); - }, 60000); - - return () => { - clearInterval(interval); - }; - }, []); - - useEffect(() => { - // Update countdown every 1 seconds - const interval = setInterval(() => { - setCountDown((countDown) => Math.max(countDown - 1, 0)); - }, 1000); - - return () => { - clearInterval(interval); - }; }, []); const getTimeDifference = useCallback((minutesAgo: number) => { @@ -70,12 +48,12 @@ const ArticleLiveFeed: React.FC> = ({id}) => { return `Prieš ${minutes} min.`; } }, []); + const renderItem = useCallback( ({item}: ListRenderItemInfo) => { let imgUri: string | undefined; if (item.img_path_prefix && item.img_path_postfix) { imgUri = buildImageUri(IMG_SIZE_M, item.img_path_prefix, item.img_path_postfix); - console.log(imgUri); } return ( @@ -133,12 +111,7 @@ const ArticleLiveFeed: React.FC> = ({id}) => { return ( - - - {'TIESIOGIAI'} - {` ${countDown} sek.`} - - + reload()} /> {state.feed ? ( void; +} + +const COUNTDOWN_DURATION = 60; + +const LiveFeedCountdown: React.FC> = (props) => { + const [countDown, setCountDown] = useState(COUNTDOWN_DURATION); + + useEffect(() => { + const deadlineInterval = setInterval(() => { + setCountDown(COUNTDOWN_DURATION); + + if (props.onDeadline) { + props.onDeadline(); + } + }, COUNTDOWN_DURATION * 1000); + + return () => { + clearInterval(deadlineInterval); + }; + }, []); + + useEffect(() => { + const countdownUpdateInterval = setInterval(() => { + setCountDown((countDown) => Math.max(countDown - 1, 0)); + }, 1000); + + return () => { + clearInterval(countdownUpdateInterval); + }; + }, []); + + return ( + + + {'TIESIOGIAI'} + {` ${countDown} sek.`} + + + ); +}; + +export default LiveFeedCountdown; + +const styles = StyleSheet.create({ + refreshTimeContainer: { + height: 80, + alignContent: 'center', + justifyContent: 'center', + backgroundColor: 'rgba(238,0,14,.05)', + borderRadius: 6, + overflow: 'hidden', + }, + refreshTime: { + color: 'rgb(238, 0, 14)', + textAlign: 'center', + fontSize: 14, + letterSpacing: 0.8, + }, +}); diff --git a/app/screens/channel/context/ChannelContextProvider.tsx b/app/screens/channel/context/ChannelContextProvider.tsx index 1c16051..1acced8 100644 --- a/app/screens/channel/context/ChannelContextProvider.tsx +++ b/app/screens/channel/context/ChannelContextProvider.tsx @@ -46,10 +46,10 @@ const ChannelProvider: React.FC> = ({children}) => { }; let audioStreamData: StreamData | undefined; - if (data.content2) { + if (data.audio) { audioStreamData = { ...streamData, - streamUri: data.content2.trim(), + streamUri: data.audio.trim(), poster: getPosterByChannelId(String(channelId)), }; } diff --git a/app/util/useFirebaseTopicSubscription.ts b/app/util/useFirebaseTopicSubscription.ts index ebbfeda..d652e5d 100644 --- a/app/util/useFirebaseTopicSubscription.ts +++ b/app/util/useFirebaseTopicSubscription.ts @@ -1,5 +1,5 @@ import {useCallback, useEffect, useState} from 'react'; -import messaging from '@react-native-firebase/messaging'; +import messaging, {firebase} from '@react-native-firebase/messaging'; import AsyncStorage from '@react-native-async-storage/async-storage'; const TOPICS_STORAGE_KEY = 'initialTopicSubscription'; @@ -9,8 +9,16 @@ const useFirebaseTopicSubscription = () => { const [subscriptions, setSubscriptions] = useState([]); useEffect(() => { + const subscribeToTestTopic = async () => { + try { + await messaging().subscribeToTopic('test'); + } catch (e) { + // ignore emulator issues + } + }; + if (__DEV__) { - messaging().subscribeToTopic('test'); + subscribeToTestTopic(); } }, []); @@ -62,10 +70,14 @@ const useFirebaseTopicSubscription = () => { activeSubscriptions = JSON.parse(topicsJson); } - data.forEach((topic) => { + data.forEach(async (topic) => { const shouldSubscribe = isFirstRun || topic.hidden === 1; if (shouldSubscribe) { - messaging().subscribeToTopic(topic.slug); + try { + await messaging().subscribeToTopic(topic.slug); + } catch (e) { + // ignore emulator issues + } if (activeSubscriptions.indexOf(topic.slug) === -1) { activeSubscriptions.push(topic.slug); } diff --git a/ios/lrtApp.xcodeproj/project.pbxproj b/ios/lrtApp.xcodeproj/project.pbxproj index 39d631b..9ad70f3 100644 --- a/ios/lrtApp.xcodeproj/project.pbxproj +++ b/ios/lrtApp.xcodeproj/project.pbxproj @@ -783,7 +783,7 @@ CODE_SIGN_ENTITLEMENTS = lrtApp/lrtApp.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 97; + CURRENT_PROJECT_VERSION = 98; DEVELOPMENT_TEAM = TGMUP98888; ENABLE_BITCODE = NO; "EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "i386 arm64"; @@ -817,7 +817,7 @@ CODE_SIGN_ENTITLEMENTS = lrtApp/lrtAppRelease.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 97; + CURRENT_PROJECT_VERSION = 98; DEVELOPMENT_TEAM = TGMUP98888; INFOPLIST_FILE = lrtApp/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";