Skip to content

Commit

Permalink
cleaned up front-end log ooutput:
Browse files Browse the repository at this point in the history
  • Loading branch information
p4p1 committed Feb 6, 2021
1 parent 3a90969 commit 293923c
Show file tree
Hide file tree
Showing 10 changed files with 212 additions and 16 deletions.
2 changes: 0 additions & 2 deletions app/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export default class App extends React.Component
const value = await AsyncStorage.getItem('@xss_bomb:server');
if (value !== null) {
this.setState({ url: value });
console.log(value);
}
} catch (error) {
console.log(error);
Expand All @@ -41,7 +40,6 @@ export default class App extends React.Component
const value = await AsyncStorage.getItem('@xss_bomb:token');
if (value !== null) {
this.setState({ token: value });
console.log(value);
}
} catch (error) {
console.log(error);
Expand Down
60 changes: 60 additions & 0 deletions app/components/FavNotif.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import React from 'react';
import { StyleSheet, View, Text } from 'react-native';

import PropTypes from 'prop-types';

export default class FavNotif extends React.Component
{
constructor(props) {
super(props);
}

render() {
return (
<View style={styles.container}>
<Text style={styles.header}>{this.props.data.link}</Text>
<Text style={styles.date}>{this.props.data.date}</Text>
<Text style={styles.para}>{this.props.data.userAgent}</Text>
<Text style={styles.para}>{this.props.data.ipAddress}</Text>
</View>
);
}
}

FavNotif.propTypes = {
data: PropTypes.object,
}

const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#333333',
justifyContent: 'center',
paddingTop: 10,
paddingLeft: 10,
marginBottom: 10,
marginTop: 10,
},
header: {
fontSize: 25,
fontWeight: 'bold',
color: '#fff',
paddingLeft: 5,
paddingRight: 10,
marginBottom: 15,
},
para: {
fontSize: 15,
color: '#fff',
paddingLeft: 5,
paddingRight: 10,
marginBottom: 15,
},
date: {
fontSize: 13,
color: '#aaaaaa',
paddingLeft: 5,
paddingRight: 10,
marginBottom: 5,
},
});
11 changes: 6 additions & 5 deletions app/components/Notif.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { StyleSheet, View, Text } from 'react-native';
import Swipeout from 'react-native-swipeout';
import { FontAwesomeIcon } from '@fortawesome/react-native-fontawesome'
import { /*faQuestion, faHeart,*/ faTrash } from '@fortawesome/free-solid-svg-icons'
import { /*faQuestion,*/ faHeart, faTrash } from '@fortawesome/free-solid-svg-icons'

import PropTypes from 'prop-types';

Expand All @@ -11,12 +11,12 @@ export default class Notif extends React.Component
constructor(props) {
super(props);
this.swipeData = [
/*{ // TODO: add a favorite method to save them in a different tab
{
text: <FontAwesomeIcon color={'white'} icon={faHeart} size={25} />,
backgroundColor: 'green',
onPress: () => { this.props.delete(this.props.data._id) }
onPress: () => { this.props.save(this.props.data) }
},
{ // TODO: add a more information feature to the notifications
/*{ // TODO: add a more information feature to the notifications
text: <FontAwesomeIcon color={'white'} icon={faQuestion} size={25} />,
backgroundColor: 'blue',
onPress: () => { this.props.delete(this.props.data._id) }
Expand Down Expand Up @@ -46,7 +46,8 @@ export default class Notif extends React.Component

Notif.propTypes = {
data: PropTypes.object,
delete: PropTypes.function
delete: PropTypes.function,
save: PropTypes.function
}

const styles = StyleSheet.create({
Expand Down
5 changes: 5 additions & 0 deletions app/navigation/MainNavigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { createDrawerNavigator } from '@react-navigation/drawer';
import PropTypes from 'prop-types';

import UserScreen from '../screens/UserScreen.js';
import FavoritesScreen from '../screens/FavoritesScreen.js';
import NotificationScreen from '../screens/NotificationScreen.js';
import HelpScreen from '../screens/HelpScreen.js';

Expand All @@ -26,6 +27,10 @@ export default class MainNavigator extends React.Component
{props => <NotificationScreen {...props} logout={() => this.props.logout()}
token={this.props.token} url={this.props.url} />}
</Drawer.Screen>
<Drawer.Screen name="Favorites">
{props => <FavoritesScreen {...props} logout={() => this.props.logout()}
token={this.props.token} url={this.props.url} />}
</Drawer.Screen>
<Drawer.Screen name="Account">
{props => <UserScreen {...props} logout={() => this.props.logout()}
token={this.props.token} url={this.props.url} />}
Expand Down
109 changes: 109 additions & 0 deletions app/screens/FavoritesScreen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import React from 'react';
import { Text, RefreshControl, StyleSheet, ScrollView, View } from 'react-native';
import AsyncStorage from '@react-native-community/async-storage';

import FavNotif from '../components/FavNotif.js';

import PropTypes from 'prop-types';

export default class FavoritesScreen extends React.Component
{
constructor(props) {
super(props);
this.state = {
refreshing: false,
data: [],
}

this.onRefresh = this.onRefresh.bind(this);
}

async onRefresh() {
this.setState({refreshing: true});
try {
const value = await AsyncStorage.getItem('@xss_bomb:notification');
if (value !== null) {
this.setState({ data: JSON.parse(value) });
}
} catch (error) {
console.log(error);
}
this.setState({refreshing: false});
}


componentDidMount() {
this.onRefresh();
}

render () {
return (
<View style={styles.container}>
<ScrollView style={{width:'90%', height:'80%' }}
refreshControl={<RefreshControl refreshing={this.state.refreshing}
onRefresh={this.onRefresh}/>}>
{
this.state.data.length == 0 ?
<View>
<Text style={styles.header}>You do not have any favorites!</Text>
</View>
:
this.state.data.reverse().map(
(notifData,i) => <FavNotif data={notifData} key={i}
delete={(data) => this.remove(data)}
save={(data) => this.save(data)}/>
)
}
</ScrollView>
</View>
);
}
}

FavoritesScreen.propTypes = {
url: PropTypes.string,
token: PropTypes.string,
logout: PropTypes.function,
}

const styles = StyleSheet.create({
container: {
flex: 1,
width: '100%',
height: '100%',
backgroundColor: '#444333',
alignItems: 'center',
justifyContent: 'center',
paddingTop: 30,
paddingBottom: 5,
},
save_clip:{
justifyContent: 'center',
flexDirection: 'row'
},
header: {
fontSize: 25,
fontWeight: 'bold',
color: '#fff',
paddingLeft: 5,
paddingRight: 10,
marginBottom: 15,
marginTop: 100,
textAlign: 'center',
width: '100%',
},
para: {
fontSize: 15,
color: '#aaaaaa',
paddingLeft: 5,
paddingRight: 10,
marginBottom: 15,
textAlign: 'center',
},
logo: {
width: 150,
height: 150,
marginBottom: 50,
borderRadius: 30,
}
});
1 change: 0 additions & 1 deletion app/screens/HelpScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export default class HelpScreen extends React.Component
'authorization': `Bearer ${this.props.token}`
}
}).then((response) => response.json()).then((json) => {
console.log(json);
this.setState({ api_id: json.token });
}).catch((err) => {
console.error(err);
Expand Down
1 change: 0 additions & 1 deletion app/screens/LoginScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ export default class CredsScreen extends React.Component
password: this.state.pass
}),
}).then((response) => response.json()).then((json) => {
console.log(json);
alert(json.msg);
}).catch((err) => {
console.error(err);
Expand Down
37 changes: 32 additions & 5 deletions app/screens/NotificationScreen.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { Text, RefreshControl, StyleSheet, ScrollView, View, Clipboard, TouchableOpacity } from 'react-native';
import AsyncStorage from '@react-native-community/async-storage';
import { FontAwesomeIcon } from '@fortawesome/react-native-fontawesome'
import { faCopy } from '@fortawesome/free-solid-svg-icons'

Expand All @@ -15,12 +16,12 @@ export default class HomeScreen extends React.Component
this.state = {
refreshing: false,
data: [],
bugdata: [],
api_id: undefined,
}

this.onRefresh = this.onRefresh.bind(this);
this.remove = this.remove.bind(this);
this.save = this.save.bind(this);
}

onRefresh() {
Expand All @@ -33,7 +34,6 @@ export default class HomeScreen extends React.Component
'authorization': `Bearer ${this.props.token}`
}
}).then((response) => response.json()).then((json) => {
console.log(json);
this.setState({ data: json });
this.setState({refreshing: false});
}).catch((err) => {
Expand All @@ -44,6 +44,34 @@ export default class HomeScreen extends React.Component
});
}

async save(notification_data) {
try {
const value = await AsyncStorage.getItem('@xss_bomb:notification');
if (value !== null) {
const new_value = JSON.parse(value);
try {
await AsyncStorage.setItem(
'@xss_bomb:notification',
JSON.stringify([ ...new_value, notification_data ])
);
} catch (error) {
console.error(error);
}
} else {
try {
await AsyncStorage.setItem(
'@xss_bomb:notification',
JSON.stringify([ notification_data ])
);
} catch (error) {
console.error(error);
}
}
} catch (error) {
console.log(error);
}
}

remove(notification_id) {
fetch(`${this.props.url}user/notification`, {
method: 'DELETE',
Expand All @@ -57,7 +85,6 @@ export default class HomeScreen extends React.Component
}),
}).then((response) => response.json()).then((json) => {
this.onRefresh();
console.log(json);
}).catch((err) => {
console.error(err);
alert("Error: Could not connect");
Expand All @@ -75,7 +102,6 @@ export default class HomeScreen extends React.Component
'authorization': `Bearer ${this.props.token}`
}
}).then((response) => response.json()).then((json) => {
console.log(json);
this.setState({ api_id: json.token });
}).catch((err) => {
console.error(err);
Expand Down Expand Up @@ -106,7 +132,8 @@ export default class HomeScreen extends React.Component
:
this.state.data.reverse().map(
(notifData,i) => <Notif data={notifData} key={i}
delete={(data) => this.remove(data)} />
delete={(data) => this.remove(data)}
save={(data) => this.save(data)}/>
)
}
</ScrollView>
Expand Down
1 change: 0 additions & 1 deletion app/screens/PickServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export default class PickServer extends React.Component
if (this.state.instances == undefined || this.state.instances.length < 1) {
return (<SplashScreen />);
}
console.log(this.state.instances);
return (
<View style={styles.container}>
<Modal animationType={"slide"} transparent={true}
Expand Down
1 change: 0 additions & 1 deletion app/screens/UserScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export default class UserScreen extends React.Component
'authorization': `Bearer ${this.props.token}`
}
}).then((response) => response.json()).then((json) => {
console.log(json);
this.setState({ data: json });
}).catch((err) => {
console.error(err);
Expand Down

0 comments on commit 293923c

Please sign in to comment.