Skip to content

Commit

Permalink
feat: general optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
KestasVenslauskas committed May 13, 2024
1 parent 5eed1da commit 3ac440d
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 54 deletions.
2 changes: 1 addition & 1 deletion app/api/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export type VideoDataLiveStream = {
data: {
content: string;
content2?: string;
content3?: string;
audio?: string;
};
};
};
Expand Down
4 changes: 4 additions & 0 deletions app/car/category/useCarCategoryTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion app/components/articleParagraphs/embeded/ArticleEmbed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ const ArticleEmbed: React.FC<React.PropsWithChildren<Props>> = ({embedArray, ite
);
}
case 'timeline': {
return <EmbedTimeline data={e as ArticleEmbedTimelineType[]} />;
return (
<EmbedTimeline key={`embed-timeline-${index}`} data={e as ArticleEmbedTimelineType[]} />
);
}
case 'photoalbum': {
return (
Expand Down
47 changes: 3 additions & 44 deletions app/screens/article/liveFeed/ArticleLiveFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,7 +21,6 @@ interface Props {
const ITEM_COUNT_INCREMENT = 5;

const ArticleLiveFeed: React.FC<React.PropsWithChildren<Props>> = ({id}) => {
const [countDown, setCountDown] = useState(60);
const [itemCount, setItemCount] = useState(ITEM_COUNT_INCREMENT);
const {state, reload} = useLiveFeedState(id);

Expand All @@ -29,29 +29,7 @@ const ArticleLiveFeed: React.FC<React.PropsWithChildren<Props>> = ({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) => {
Expand All @@ -70,12 +48,12 @@ const ArticleLiveFeed: React.FC<React.PropsWithChildren<Props>> = ({id}) => {
return `Prieš ${minutes} min.`;
}
}, []);

const renderItem = useCallback(
({item}: ListRenderItemInfo<LiveFeedItem>) => {
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 (
Expand Down Expand Up @@ -133,12 +111,7 @@ const ArticleLiveFeed: React.FC<React.PropsWithChildren<Props>> = ({id}) => {

return (
<View style={styles.container}>
<View style={styles.refreshTimeContainer}>
<TextComponent style={styles.refreshTime}>
<TextComponent style={{...styles.refreshTime, fontWeight: 'bold'}}>{'TIESIOGIAI'}</TextComponent>
{` ${countDown} sek.`}
</TextComponent>
</View>
<LiveFeedCountdown onDeadline={() => reload()} />
{state.feed ? (
<FlatList
style={{marginTop: 16}}
Expand All @@ -164,20 +137,6 @@ const styles = StyleSheet.create({
marginTop: 12,
marginBottom: 8,
},
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,
},
itemContainer: {
marginBottom: 8,
marginTop: 16,
Expand Down
65 changes: 65 additions & 0 deletions app/screens/article/liveFeed/LiveFeedCountdown.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import {useEffect, useState} from 'react';
import {StyleSheet, View} from 'react-native';
import TextComponent from '../../../components/text/Text';

interface Props {
onDeadline: () => void;
}

const COUNTDOWN_DURATION = 60;

const LiveFeedCountdown: React.FC<React.PropsWithChildren<Props>> = (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 (
<View style={styles.refreshTimeContainer}>
<TextComponent style={styles.refreshTime}>
<TextComponent style={{...styles.refreshTime, fontWeight: 'bold'}}>{'TIESIOGIAI'}</TextComponent>
{` ${countDown} sek.`}
</TextComponent>
</View>
);
};

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,
},
});
4 changes: 2 additions & 2 deletions app/screens/channel/context/ChannelContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ const ChannelProvider: React.FC<React.PropsWithChildren<{}>> = ({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)),
};
}
Expand Down
20 changes: 16 additions & 4 deletions app/util/useFirebaseTopicSubscription.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -9,8 +9,16 @@ const useFirebaseTopicSubscription = () => {
const [subscriptions, setSubscriptions] = useState<string[]>([]);

useEffect(() => {
const subscribeToTestTopic = async () => {
try {
await messaging().subscribeToTopic('test');
} catch (e) {
// ignore emulator issues
}
};

if (__DEV__) {
messaging().subscribeToTopic('test');
subscribeToTestTopic();
}
}, []);

Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions ios/lrtApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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";
Expand Down

0 comments on commit 3ac440d

Please sign in to comment.