fix don't get news list when user don't have project id

This commit is contained in:
Boonkarit 2025-08-26 15:47:41 +07:00
parent 0faf2abefd
commit e26581d425
4 changed files with 80 additions and 73 deletions

View File

@ -334,14 +334,9 @@ const MainTitle = connect(state => ({
userText = `${name[0]}`; userText = `${name[0]}`;
projectName = props.user.project_name projectName = props.user.project_name
} }
return <View style={{display: 'flex', flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', width: '89%'}}> return <View>
<View> <Text style={{ fontSize: 16, color: '#FFFFFF', marginLeft: 10, marginTop: 3, marginBottom: 5 }}>{t('charoensin_asset')} {projectName}</Text>
<Text style={{ fontSize: 16, color: '#FFFFFF', marginLeft: 10, marginTop: 3, marginBottom: 5 }}>{t('charoensin_asset')} {projectName}</Text> </View>
</View>
<View>
<Text style={{color: 'white'}}>2.0</Text>
</View>
</View>
}) })
const MainHeader = ({ navigation }) => { const MainHeader = ({ navigation }) => {
@ -368,7 +363,7 @@ const MainHeader = ({ navigation }) => {
}, []) }, [])
return <View style={[{ flex: 1, alignItems: 'center', flexDirection: 'row', marginTop: 0, paddingLeft: 10, backgroundColor: server_mode === 'develop' ? '#ff0000' : 'transparent' }]}> return <View style={[{ flex: 1, alignItems: 'center', flexDirection: 'row', marginTop: 0, paddingLeft: 10, backgroundColor: server_mode === 'develop' ? '#ff0000' : 'transparent' }]}>
<TouchableOpacity <TouchableOpacity
onPress={openSecretChamber} // onPress={openSecretChamber}
activeOpacity={1}> activeOpacity={1}>
<Image <Image
style={{ width: 35, height: 35, }} style={{ width: 35, height: 35, }}
@ -457,6 +452,7 @@ const AppStack = createStackNavigator({
}, },
headerRight: ( headerRight: (
<View style={{marginRight: 0, justifyContent: 'center', alignItems: 'center', flexDirection: 'row'}}> <View style={{marginRight: 0, justifyContent: 'center', alignItems: 'center', flexDirection: 'row'}}>
<Text style={{color: 'white', marginRight: 3}}>2.0</Text>
<TouchableOpacity onPress={() => navigation.navigate('LanguageSelect')} style={{marginRight: 8}}> <TouchableOpacity onPress={() => navigation.navigate('LanguageSelect')} style={{marginRight: 8}}>
<View style={{width: 30, height: 30, alignItems: 'center', justifyContent: 'center'}}> <View style={{width: 30, height: 30, alignItems: 'center', justifyContent: 'center'}}>
<Image style={{width: 25, height: 25}} source={langIcon}/></View> <Image style={{width: 25, height: 25}} source={langIcon}/></View>
@ -467,7 +463,7 @@ const AppStack = createStackNavigator({
</View> </View>
), ),
headerLeftContainerStyle: { headerLeftContainerStyle: {
width: '80%', width: '75%',
alignItems: 'center', alignItems: 'center',
justifyContent: 'center', justifyContent: 'center',
}, },

View File

@ -1,4 +1,4 @@
import { createSwitchNavigator, createAppContainer } from 'react-navigation' import { createSwitchNavigator, createAppContainer, SafeAreaView } from 'react-navigation'
import AuthStack from './AuthStack' import AuthStack from './AuthStack'
import AppStack from './AppStack' import AppStack from './AppStack'
import React from 'react' import React from 'react'
@ -19,9 +19,9 @@ export class AppNavContainer extends React.Component {
} }
render () { render () {
return <View style={{ flex: 1 }}> return <SafeAreaView style={{ flex: 1 }}>
<MainNav ref={navigatorRef => {NavigationService.setTopLevelNavigator(navigatorRef)}}/> <MainNav ref={navigatorRef => {NavigationService.setTopLevelNavigator(navigatorRef)}}/>
</View> </SafeAreaView>
} }
} }

View File

@ -242,8 +242,24 @@ class NewsScreen extends Component {
console.log('project id >>>> ', res.data.project_id) console.log('project id >>>> ', res.data.project_id)
this.checkNotifiedPopup() this.checkNotifiedPopup()
if(res.data.project_id){ if(res.data.project_id){
await this.getAllNewsByProject(res.data.project_id) this.setState({
loadPage: 1,
last_page: 1,
news_head: [{
title: t('loading_news'),
content: t('loading_news'),
date: t('loading_news'),
is_new: false
}],
new_all: [{
title: t('loading_news'),
content: t('loading_news'),
date: t('loading_news'),
is_new: false
}],
},async () => {
await this.getAllNewsByProject(res.data.project_id)
})
} }
this.setState({ this.setState({
noti_count: res.data.count_noti, noti_count: res.data.count_noti,
@ -328,20 +344,6 @@ class NewsScreen extends Component {
console.log('initData >>> ') console.log('initData >>> ')
this.setState({ this.setState({
isLoading: true, isLoading: true,
loadPage: 1,
last_page: 1,
news_head: [{
title: t('loading_news'),
content: t('loading_news'),
date: t('loading_news'),
is_new: false
}],
new_all: [{
title: t('loading_news'),
content: t('loading_news'),
date: t('loading_news'),
is_new: false
}],
}, () => { }, () => {
Promise.all([ Promise.all([
this.getUser(), this.getUser(),
@ -594,24 +596,28 @@ class NewsScreen extends Component {
} }
}} }}
> >
<View style={[styles.row]}> {
<FlatList this.state.user_project_id ?
data={this.state.news_head} <View style={[styles.row]}>
renderItem={({ item }) => this.renderNativeItemImages(item)} <FlatList
horizontal={true} data={this.state.news_head}
showsHorizontalScrollIndicator={false} renderItem={({ item }) => this.renderNativeItemImages(item)}
pagingEnabled={true} horizontal={true}
keyExtractor={this._keyExtractorNewHead} showsHorizontalScrollIndicator={false}
onScroll={this._onCarouselScroll} pagingEnabled={true}
/> keyExtractor={this._keyExtractorNewHead}
<View style={{ position: 'absolute', bottom: 10, width: '100%', justifyContent: 'center', flexDirection: 'row' }}> onScroll={this._onCarouselScroll}
{ />
this.state.news_head ? <View style={{ position: 'absolute', bottom: 10, width: '100%', justifyContent: 'center', flexDirection: 'row' }}>
(this.state.news_head).map((item, i) => <View key={'news_heade_' + i} style={[{ width: 10, height: 10, borderRadius: 5, backgroundColor: this.state.position == i ? '#269A21' : 'rgba(255,255,255,0.3)', marginHorizontal: 4 }]}></View>) {
: <View></View> this.state.news_head ?
} (this.state.news_head).map((item, i) => <View key={'news_heade_' + i} style={[{ width: 10, height: 10, borderRadius: 5, backgroundColor: this.state.position == i ? '#269A21' : 'rgba(255,255,255,0.3)', marginHorizontal: 4 }]}></View>)
</View> : <View></View>
</View> }
</View>
</View> : <View></View>
}
{ {
this.state.auth !== null && this.state.auth !== null &&
( (
@ -817,31 +823,36 @@ class NewsScreen extends Component {
)) ))
} }
<View style={{ padding: 10 }}>
<FlatList {
extraData={this.state} this.state.user_project_id ?
contentContainerStyle={{ <View style={{ padding: 10 }}>
height: '100%', <FlatList
width: '100%' extraData={this.state}
}} contentContainerStyle={{
// scrollEnabled={false} height: '100%',
data={this.state.new_all} width: '100%'
renderItem={this.renderNativeItem} }}
keyExtractor={this._keyExtractorNewAll} // scrollEnabled={false}
// onEndReachedThreshold={0.01} data={this.state.new_all}
// onEndReached={this.loadMoreData.bind(this)} renderItem={this.renderNativeItem}
ItemSeparatorComponent={() => { keyExtractor={this._keyExtractorNewAll}
return <View style={{ width: '100%', height: 8 }}></View> // onEndReachedThreshold={0.01}
}} // onEndReached={this.loadMoreData.bind(this)}
ListFooterComponent={() => { ItemSeparatorComponent={() => {
if (!this.state.isLoadmore) return null return <View style={{ width: '100%', height: 8 }}></View>
return (<ActivityIndicator }}
size="large" ListFooterComponent={() => {
color={'white'} if (!this.state.isLoadmore) return null
/>) return (<ActivityIndicator
}} size="large"
/> color={'white'}
</View> />)
}}
/>
</View> : <View></View>
}
</ScrollView> </ScrollView>
</BackgroundImage> </BackgroundImage>
<IndicatorLoading loadingVisible={this.state.isLoading}/> <IndicatorLoading loadingVisible={this.state.isLoading}/>

View File

@ -97,7 +97,7 @@ export default class NewsDetailScreen extends Component {
source_webview = { source_webview = {
baseUrl: '', baseUrl: '',
// uri: `${Config.API_BASE_URL_POWER_CONDO_PROD}/news/${this.state.news_id}/detail`, // uri: `${Config.API_BASE_URL_POWER_CONDO_PROD}/news/${this.state.news_id}/detail`,
uri: `${Config.API_BASE_URL_POWER_CONDO_DEV}/news/${this.state.news_id}/detail` uri: `${Config.API_BASE_URL_POWER_CONDO_PROD}/news/${this.state.news_id}/detail`
} }
// if(Platform.OS === 'android'){ // if(Platform.OS === 'android'){