Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add verified badge #39

Merged
merged 1 commit into from
Jul 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion components/global/MoreMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<ImageProps>)=><Icon {...props} name="more-vertical" />
const FeedbackIcon=(props?: Partial<ImageProps>)=><Icon {...props} name="feedback" pack="material" />
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions screens/UrlShortener.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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()
}
}
Expand Down
41 changes: 28 additions & 13 deletions screens/User/Follow.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)=><Icon {...props} name="more-vertical" />)
Expand Down Expand Up @@ -49,6 +50,7 @@ const RenderUser=React.memo(({item,index,onOpen})=>{
accessoryLeft={()=><MemoAvatar name={item?.name} image={item?.image} />}
accessoryRight={()=><RenderIcon item={item} onOpen={onOpen} />}
onPress={()=>navigation.push("User",{username:item?.username})}
onLongPress={()=>onOpen(item)}
/>
)
})
Expand Down Expand Up @@ -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 <Text style={{marginTop:10,marginBottom:10,textAlign:'center'}}>You have reach the bottom of the page</Text>
if(isLoadingMore) return <View paddingTop={20}><ListSkeleton height={250} number={3} image /></View>
return null
}

renderEmpty() {
return (
<View style={{justifyContent:"center",alignItems:"center",flexDirection:"row",height:56}}>
<Text>No Data</Text>
</View>
)
}

render(){
const {menu,loading}=this.state;
const {navigation,user,data,error,theme,dt,isValidating,isLoadingInitialData,onGetRef,scrollY,onMomentumScrollBegin,onMomentumScrollEnd,onScrollEndDrag}=this.props
Expand Down Expand Up @@ -176,6 +190,7 @@ class RenderFollowClass extends React.PureComponent{
renderItem={(props)=> <RenderUser {...props} onOpen={this.handleOpenMenu.bind(this)} />}
ItemSeparatorComponent={Divider}
ListFooterComponent={this.renderFooter()}
ListEmptyComponent={this.renderEmpty()}
scrollToOverflowEnabled
ref={onGetRef}
onScroll={Animated.event(
Expand Down
12 changes: 11 additions & 1 deletion screens/User/Media.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ class RenderMediaClass extends React.PureComponent{
if(!isLoadingMore && !isReachingEnd && !isLoadingInitialData) setSize(size+1);
}

renderEmpty() {
return (
<View style={{justifyContent:"center",alignItems:"center",flexDirection:"row",height:56}}>
<Text>No Data</Text>
</View>
)
}

componentDidUpdate(prevProps){
const {isValidating,onValidatingChange,dt,isLoadingMore}=this.props
if(prevProps.isValidating != isValidating && dt?.length > 0 && !isLoadingMore) {
Expand All @@ -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 <Text style={{marginTop:10,marginBottom:10,textAlign:'center'}}>You have reach the bottom of the page</Text>
if(isLoadingMore) return <View paddingTop={20}><GridSkeleton height={300} number={2} image /></View>
return null
Expand Down Expand Up @@ -166,6 +175,7 @@ class RenderMediaClass extends React.PureComponent{
renderItem={props=> <RenderNews {...props} data={dt} onOpen={this.handleOpenMenu} />}
keyExtractor={(item)=>item?.title}
ListFooterComponent={this.renderFooter()}
ListEmptyComponent={this.renderEmpty()}
scrollToOverflowEnabled
ref={(ref)=>onGetRef(ref)}
onScroll={Animated.event(
Expand Down
58 changes: 36 additions & 22 deletions screens/User/User.js
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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'
Expand Down Expand Up @@ -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();
}
}
}

Expand All @@ -235,7 +240,12 @@ export default function UserScreen({navigation,route}){
return (
<View style={{position:'absolute',top:0,width:'100%',zIndex:1}}>
<TopNavigation
title={(evaProps) => <AnimText {...evaProps} category="h1" style={{...evaProps?.style,marginHorizontal:50,opacity}} numberOfLines={1}>{data?.users?.username||""}</AnimText>}
title={(evaProps) => (
<Animated.View style={{opacity,flexDirection:'row',alignItems:"center",marginHorizontal:50}}>
<Text {...evaProps} category="h1" style={{...evaProps?.style,...(data?.users?.verify ? {marginRight:5} : {})}} numberOfLines={1}>{data?.users?.username||""}</Text>
{data?.users?.verify && <Icon style={{height:15,width:15,tintColor:theme['color-indicator-bar']}} name="verified" pack="material" />}
</Animated.View>
)}
accessoryLeft={()=><RenderBackButton navigation={navigation} />}
alignment="center"
accessoryRight={()=><MenuToggle onPress={()=>{data && !data?.error && setOpenMenu(true)}} />}
Expand Down Expand Up @@ -297,7 +307,11 @@ export default function UserScreen({navigation,route}){
</View>
</View>
<Text style={{fontSize:30,marginTop:10,fontFamily:"Inter_Bold"}}>{data?.users?.name||""}</Text>
<Text style={{fontSize:15}}>{`@${data?.users?.username}`}</Text>
<View style={{flexDirection:"row",alignItems:"center"}}>
<Text style={{fontSize:15,...(data?.users?.verify ? {marginRight:5} : {})}}>{`@${data?.users?.username}`}</Text>
{data?.users?.verify && <Icon style={{height:15,width:15,tintColor:theme['color-indicator-bar']}} name="verified" pack="material" />}
</View>

</Lay>
)}
<TabBar
Expand Down
11 changes: 10 additions & 1 deletion screens/auth/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import GoogleSignInButton from '@pn/components/global/GoogleSignInButton';
import {FIREBASE_CLIENT_ID,FIREBASE_WEB_CLIENT_ID} from '@env';
import Backdrop from '@pn/components/global/Backdrop';
import getInfo from '@pn/utils/Info';
import { useNavigationState } from '@react-navigation/native';
import { log, logError } from '@pn/utils/log';
import useSelector from '@pn/provider/actions'
import ShareModule from '@pn/module/Share';

const {width} = Dimensions.get('window')

Expand Down Expand Up @@ -56,6 +56,15 @@ export default function LoginScreen({ navigation,route }) {
return {location,request};
}

React.useEffect(()=>{
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`)}`}))
Expand Down