diff --git a/components/global/MoreMenu.tsx b/components/global/MoreMenu.tsx index 60da838..618c40d 100644 --- a/components/global/MoreMenu.tsx +++ b/components/global/MoreMenu.tsx @@ -15,6 +15,7 @@ import {Portal} from '@gorhom/portal' import {sentLike} from '@pn/components/global/Like' import Spinner from './Spinner' import useSelector from '@pn/provider/actions' +import Authentication from '@pn/module/Authentication' const MoreIcon=(props?: Partial)=> const FeedbackIcon=(props?: Partial)=> @@ -147,7 +148,7 @@ const MenuCont=({menu,visible,onClose,onClosed,share,type,item_id}: MenuContaine },[type,item_id,PNpost]) const handleLike=React.useCallback(async(like: LikeMenuType)=>{ - if(!user) return setNotif(true,"Error","Login to continue!"); + if(!user) return Authentication.startAuthActivity(); setLoading(true) try { const res = await sentLike(PNpost,type,item_id); diff --git a/screens/UrlShortener.js b/screens/UrlShortener.js index 1e49df9..2925b83 100644 --- a/screens/UrlShortener.js +++ b/screens/UrlShortener.js @@ -28,6 +28,7 @@ import Backdrop from '@pn/components/global/Backdrop'; import {Portal} from '@gorhom/portal' import ShareModule from '@pn/module/Share'; import useSelector from '@pn/provider/actions' +import Authentication from '@pn/module/Authentication' const {width,height} = Dimensions.get('window') @@ -71,8 +72,8 @@ const URLshortenerForm=React.memo(({initialData="",setNotif,user,ads,handleOpenQ } const handleCustomFocus=()=>{ - if(user===false) { - setNotif(true,"Under Maintenance","Only for registered users"); + if(!user) { + Authentication.startAuthActivity(); customRef.current?.blur() } } diff --git a/screens/User/Follow.js b/screens/User/Follow.js index b13ad06..8983b11 100644 --- a/screens/User/Follow.js +++ b/screens/User/Follow.js @@ -17,6 +17,7 @@ import Backdrop from '@pn/components/global/Backdrop' import { AuthContext } from '@pn/provider/Context' import useAPI from '@pn/utils/API' import useSelector from '@pn/provider/actions' +import Authentication from '@pn/module/Authentication' const winHeight = Dimensions.get('window').height; const OptionIcon=React.memo((props)=>) @@ -49,6 +50,7 @@ const RenderUser=React.memo(({item,index,onOpen})=>{ accessoryLeft={()=>} accessoryRight={()=>} onPress={()=>navigation.push("User",{username:item?.username})} + onLongPress={()=>onOpen(item)} /> ) }) @@ -111,27 +113,39 @@ class RenderFollowClass extends React.PureComponent{ } handleFollow(menu){ - const {PNpost,setNotif,mutate} = this.props; - this.setState({loading:true}) - console.log(menu) - PNpost(`/backend/follow`,{token:menu?.token_follow}).then((res)=>{ - if(!res.error){ - setNotif(false,"Success!",res?.msg); - mutate(); - } - }) - .finally(()=>{ - this.setState({loading:false}) - }) + const {PNpost,setNotif,mutate,user} = this.props; + if(user) { + this.setState({loading:true}) + PNpost(`/backend/follow`,{token:menu?.token_follow}).then((res)=>{ + if(!res.error){ + setNotif(false,"Success!",res?.msg); + mutate(); + } + }) + .finally(()=>{ + this.setState({loading:false}) + }) + } else { + Authentication.startAuthActivity(); + } } renderFooter(){ - const {isReachingEnd,isLoadingMore}=this.props; + const {isReachingEnd,isLoadingMore,dt}=this.props; + if(dt?.length == 0) return null; if(isReachingEnd) return You have reach the bottom of the page if(isLoadingMore) return return null } + renderEmpty() { + return ( + + No Data + + ) + } + render(){ const {menu,loading}=this.state; const {navigation,user,data,error,theme,dt,isValidating,isLoadingInitialData,onGetRef,scrollY,onMomentumScrollBegin,onMomentumScrollEnd,onScrollEndDrag}=this.props @@ -176,6 +190,7 @@ class RenderFollowClass extends React.PureComponent{ renderItem={(props)=> } ItemSeparatorComponent={Divider} ListFooterComponent={this.renderFooter()} + ListEmptyComponent={this.renderEmpty()} scrollToOverflowEnabled ref={onGetRef} onScroll={Animated.event( diff --git a/screens/User/Media.js b/screens/User/Media.js index 95473c5..07aa1c8 100644 --- a/screens/User/Media.js +++ b/screens/User/Media.js @@ -98,6 +98,14 @@ class RenderMediaClass extends React.PureComponent{ if(!isLoadingMore && !isReachingEnd && !isLoadingInitialData) setSize(size+1); } + renderEmpty() { + return ( + + No Data + + ) + } + componentDidUpdate(prevProps){ const {isValidating,onValidatingChange,dt,isLoadingMore}=this.props if(prevProps.isValidating != isValidating && dt?.length > 0 && !isLoadingMore) { @@ -116,7 +124,8 @@ class RenderMediaClass extends React.PureComponent{ } renderFooter(){ - const {isReachingEnd,isLoadingMore}=this.props; + const {isReachingEnd,isLoadingMore,dt}=this.props; + if(dt?.length == 0) return null; if(isReachingEnd) return You have reach the bottom of the page if(isLoadingMore) return return null @@ -166,6 +175,7 @@ class RenderMediaClass extends React.PureComponent{ renderItem={props=> } keyExtractor={(item)=>item?.title} ListFooterComponent={this.renderFooter()} + ListEmptyComponent={this.renderEmpty()} scrollToOverflowEnabled ref={(ref)=>onGetRef(ref)} onScroll={Animated.event( diff --git a/screens/User/User.js b/screens/User/User.js index 070624b..b2b3076 100644 --- a/screens/User/User.js +++ b/screens/User/User.js @@ -1,6 +1,6 @@ import React from 'react' -import {View,Dimensions,Animated,RefreshControl,Alert} from 'react-native' -import {Layout as Lay,Text,useTheme,TopNavigation,Icon,Divider,Menu,MenuItem} from '@ui-kitten/components' +import {View,Dimensions,Animated} from 'react-native' +import {Layout as Lay,Text,useTheme,TopNavigation,Icon} from '@ui-kitten/components' import {TabView,TabBar} from 'react-native-tab-view' import {useNavigationState} from '@react-navigation/native' import {Modalize} from 'react-native-modalize' @@ -20,6 +20,7 @@ import Avatar from '@pn/components/global/Avatar' import {TabBarHeight,HeaderHeight} from './utils' import Brightness from '@pn/module/Brightness' import TopNavigationAction from '@pn/components/navigation/TopAction' +import Authentication from '@pn/module/Authentication' import RenderFollow from './Follow' import RenderAbout from './About' @@ -193,24 +194,28 @@ export default function UserScreen({navigation,route}){ const handleFollow=()=>{ if(!loading) { - setLoading(true); - PNpost(`/backend/follow`,{token:data?.users?.token_follow}).then((res)=>{ - if(!res.error){ - setNotif(false,"Success!",res?.msg); - mutate({ - ...data, - users:{ - ...data.users, - isFollowing:res.follow, - isPending:res.pending, - token_follow:res.new_token - } - }) - } - }) - .finally(()=>{ - setLoading(false) - }) + if(user) { + setLoading(true); + PNpost(`/backend/follow`,{token:data?.users?.token_follow}).then((res)=>{ + if(!res.error){ + setNotif(false,"Success!",res?.msg); + mutate({ + ...data, + users:{ + ...data.users, + isFollowing:res.follow, + isPending:res.pending, + token_follow:res.new_token + } + }) + } + }) + .finally(()=>{ + setLoading(false) + }) + } else { + Authentication.startAuthActivity(); + } } } @@ -235,7 +240,12 @@ export default function UserScreen({navigation,route}){ return ( {data?.users?.username||""}} + title={(evaProps) => ( + + {data?.users?.username||""} + {data?.users?.verify && } + + )} accessoryLeft={()=>} alignment="center" accessoryRight={()=>{data && !data?.error && setOpenMenu(true)}} />} @@ -297,7 +307,11 @@ export default function UserScreen({navigation,route}){ {data?.users?.name||""} - {`@${data?.users?.username}`} + + {`@${data?.users?.username}`} + {data?.users?.verify && } + + )} { + const onBackPress=()=>{ + ShareModule.dismiss(); + return true; + } + BackHandler.addEventListener("hardwareBackPress",onBackPress); + return ()=>BackHandler.removeEventListener("hardwareBackPress",onBackPress); + },[]) + async function handleLogin(email,password) { let error=[]; if(email.trim().match(/\S/) === null) error.push(i18n.t('errors.form_validation',{type:`${i18n.t(`form.email`)}/${i18n.t(`form.username`)}`}))