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){
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) 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,6 +596,8 @@ class NewsScreen extends Component {
} }
}} }}
> >
{
this.state.user_project_id ?
<View style={[styles.row]}> <View style={[styles.row]}>
<FlatList <FlatList
data={this.state.news_head} data={this.state.news_head}
@ -611,7 +615,9 @@ class NewsScreen extends Component {
: <View></View> : <View></View>
} }
</View> </View>
</View> </View> : <View></View>
}
{ {
this.state.auth !== null && this.state.auth !== null &&
( (
@ -817,6 +823,9 @@ class NewsScreen extends Component {
)) ))
} }
{
this.state.user_project_id ?
<View style={{ padding: 10 }}> <View style={{ padding: 10 }}>
<FlatList <FlatList
extraData={this.state} extraData={this.state}
@ -841,7 +850,9 @@ class NewsScreen extends Component {
/>) />)
}} }}
/> />
</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'){