diff --git a/components/Posts/PollPost.js b/components/Posts/PollPost.js
index 44bf5ac..478c0eb 100644
--- a/components/Posts/PollPost.js
+++ b/components/Posts/PollPost.js
@@ -140,39 +140,8 @@ class Poll extends Component {
navigateToFullScreen = () => {
this.props.navigation.navigate("ViewPollPostPage", {
- pollTitle: this.props.post.pollTitle,
- pollSubTitle: this.props.post.pollSubTitle,
- optionOne: this.props.post.optionOne,
- optionOnesColor: this.props.post.optionOnesColor,
- optionOnesVotes: this.props.post.optionOnesVotes,
- optionOnesBarLength: this.props.post.optionOnesBarLength,
- optionTwo: this.props.post.optionTwo,
- optionTwosColor: this.props.post.optionTwosColor,
- optionTwosVotes: this.props.post.optionTwosCotes,
- optionTwosBarLength: this.props.post.optionTwosBarLength,
- optionThree: this.props.post.optionThree,
- optionThreesColor: this.props.post.optionThreesColor,
- optionThreesVotes: this.props.post.optionThreesVotes,
- optionThreesBarLength: this.props.post.optionThreesBarLength,
- optionFour: this.props.post.optionFour,
- optionFoursColor: this.props.post.optionFoursColor,
- optionFoursVotes: this.props.post.optionFoursVotes,
- optionFoursBarLength: this.props.post.optionFoursBarLength,
- optionFive: this.props.post.optionFive,
- optionFivesColor: this.props.post.optionFivesColor,
- optionFivesVotes: this.props.post.optionFivesVotes,
- optionFivesBarLength: this.props.post.optionFivesBarLength,
- optionSix: this.props.post.optionSix,
- optionSixesColor: this.props.post.optionSixesColor,
- optionSixesVotes: this.props.post.optionSixesVotes,
- optionSixesBarLength: this.props.post.optionSixesBarLength,
- totalNumberOfOptions: this.props.post.totalNumberOfOptions,
- pollId: this.props.post.pollId,
- creatorPfpB64: this.props.post.pfpB64,
- creatorName: this.props.post.creatorName,
- creatorDisplayName: this.props.post.creatorDisplayName,
- datePosted: this.props.post.datePosted,
- votedFor: this.props.post.votedFor
+ post: this.props.post,
+ isOwner: this.props.post.isOwner
})
}
@@ -343,6 +312,8 @@ class Poll extends Component {
}
}
+export const PollClass = Poll;
+
export default function(props) {
const navigation = useNavigation();
const {serverUrl} = useContext(ServerUrlContext);
diff --git a/components/Posts/PollWithVotes.js b/components/Posts/PollWithVotes.js
new file mode 100644
index 0000000..207a53d
--- /dev/null
+++ b/components/Posts/PollWithVotes.js
@@ -0,0 +1,483 @@
+import React, { useContext } from 'react';
+import { PollClass } from './PollPost';
+import { ActivityIndicator, View } from 'react-native';
+import {
+ PostsIconFrame,
+ ViewScreenPollPostFrame,
+ PostsHorizontalView,
+ PostsVerticalView,
+ SubTitle,
+ PostCreatorIcon,
+ PollPostSubTitle,
+ ProfIcons,
+ PollPostHorizontalView,
+ AboveBarPollPostHorizontalView,
+ PollPostTitle,
+ PollKeysCircle,
+ PollKeyViewOne,
+ PollKeyViewTwo,
+ PollKeyViewThree,
+ PollKeyViewFour,
+ PollKeyViewFive,
+ PollKeyViewSix,
+ PostsIcons,
+ PollBarOutline,
+ PollBarItem,
+ PollHorizontalViewItem,
+ PollHorizontalViewItemCenter,
+ PostHorizontalView
+} from '../../screens/screenStylings/styling';
+import { getTimeFromUTCMS } from '../../libraries/Time';
+import { useNavigation } from '@react-navigation/native';
+import { ServerUrlContext } from '../ServerUrlContext';
+import { CredentialsContext } from '../CredentialsContext';
+import ParseErrorMessage from '../ParseErrorMessage';
+import Octicons from 'react-native-vector-icons/Octicons';
+import axios from 'axios';
+
+class PollWithVotes extends PollClass {
+ constructor(props) {
+ super(props);
+ }
+
+ openOptionOne = () => {
+ this.props.dispatch({type: 'openPollVoteMenu', openPollVoteMenu: "One", postIndex: this.props.index})
+ }
+
+ openOptionTwo = () => {
+ this.props.dispatch({type: 'openPollVoteMenu', openPollVoteMenu: "Two", postIndex: this.props.index})
+ }
+
+ openOptionThree = () => {
+ this.props.dispatch({type: 'openPollVoteMenu', openPollVoteMenu: "Three", postIndex: this.props.index})
+ }
+
+ openOptionFour = () => {
+ this.props.dispatch({type: 'openPollVoteMenu', openPollVoteMenu: "Four", postIndex: this.props.index})
+ }
+
+ openOptionFive = () => {
+ this.props.dispatch({type: 'openPollVoteMenu', openPollVoteMenu: "Five", postIndex: this.props.index})
+ }
+
+ openOptionSix = () => {
+ this.props.dispatch({type: 'openPollVoteMenu', openPollVoteMenu: "Six", postIndex: this.props.index})
+ }
+
+ optionOneInfoState = false; //Temporary
+ optionTwoInfoState = false; //Temporary
+ optionThreeInfoState = false; //Temporary
+ optionFourInfoState = false; //Temporary
+ optionFiveInfoState = false; //Temporary
+ optionSixInfoState = false; //Temporary
+
+ handleVoteOnPoll = (optionSelected, voteNumber) => {
+ if (this.props.storedCredentials) {
+ this.props.dispatch({type: 'startPollVoteChange', postIndex: this.props.index})
+ console.log(optionSelected)
+ const url = this.props.serverUrl + "/tempRoute/voteonpoll";
+
+ const toSend = {optionSelected: optionSelected, pollId: this.props.post._id}
+
+ console.log(toSend)
+
+ axios.post(url, toSend).then(() => {
+ this.props.dispatch({type: 'voteOnPoll', vote: voteNumber, postIndex: this.props.index})
+ }).catch(error => {
+ this.props.dispatch({type: 'stopPollVoteChange', postIndex: this.props.index})
+ console.error(error);
+ alert(ParseErrorMessage(error));
+ })
+ } else {
+ this.props.navigation.navigate('ModalLoginScreen', {modal: true})
+ }
+ }
+
+ handleRemoveVoteOnPoll = () => {
+ if (this.props.storedCredentials) {
+ this.props.dispatch({type: 'startPollVoteChange', postIndex: this.props.index})
+ const url = this.props.serverUrl + "/tempRoute/removevoteonpoll"
+ const toSend = {pollId: this.props.post._id}
+
+ console.log(toSend)
+
+ axios.post(url, toSend).then(() => {
+ this.props.dispatch({type: 'removeVoteOnPoll', postIndex: this.props.index})
+ }).catch(error => {
+ this.props.dispatch({type: 'stopPollVoteChange', postIndex: this.props.index})
+ console.error(error)
+ alert(ParseErrorMessage(error))
+ })
+ } else {
+ this.props.navigation.navigate('ModalLoginScreen', {modal: true})
+ }
+ }
+
+ shouldComponentUpdate(nextProps, nextState) {
+ const upvoteIsSame = nextProps.post.upvoted === this.props.post.upvoted;
+ const downvoteIsSame = nextProps.post.downvoted === this.props.post.downvoted;
+ const changingVoteIsSame = nextProps.post.changingVote === this.props.post.changingVote;
+ const colorsAreSame = nextProps.colorsIndexNum === this.props.colorsIndexNum;
+ const pollIdIsSame = nextProps.post.pollId === this.props.post.pollId;
+ const deletingIsSame = nextProps.post.deleting === this.props.post.deleting;
+ const profilePictureIsSame = nextProps.post.pfpB64 === this.props.post.pfpB64;
+ const changingPollVoteIsSame = nextProps.post.pollVoteChanging === this.props.post.pollVoteChanging;
+ const votedForIsSame = nextProps.post.votedFor === this.props.post.votedFor;
+ const openPollVoteMenuSame = nextProps.post.openPollVoteMenu === this.props.post.openPollVoteMenu;
+
+
+ if (upvoteIsSame && downvoteIsSame && changingVoteIsSame && colorsAreSame && pollIdIsSame && deletingIsSame && profilePictureIsSame && changingPollVoteIsSame && votedForIsSame && openPollVoteMenuSame) return false;
+
+ return true;
+ }
+
+ openThreeDotsMenu = () => {
+ if (this.props.post.isOwner !== true && this.props.post.isOwner !== false) {
+ alert("isOwner is not true or false. An error has occured.")
+ return
+ }
+
+ this.props.dispatch({
+ type: 'showMenu',
+ postId: this.props.post._id,
+ postFormat: 'Poll',
+ isOwner: this.props.post.isOwner,
+ postIndex: this.props.index
+ })
+ }
+
+ render() {
+ return (
+ <>
+ {this.props.post.deleting &&
+
+ Deleting...
+
+
+ }
+
+
+
+
+
+
+ {this.props.post.creatorDisplayName}
+ @{this.props.post.creatorName}
+
+
+
+ {this.props.post.pollTitle || "Couldn't recieve poll title"}
+
+
+ {this.props.post.pollSubTitle || "Couldn't recieve poll subtitle"}
+
+
+
+ 1
+
+
+ 2
+
+
+ 3
+
+
+ 4
+
+
+ 5
+
+
+ 6
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1. {this.props.post.optionOne || "Couldn't load option one"}
+
+
+
+
+
+
+
+
+ Votes
+
+ {this.props.post.optionOnesVotes}
+
+
+ {this.props.post.votedFor === "One" ? this.handleRemoveVoteOnPoll() : this.handleVoteOnPoll("optionOnesVotes", "One")}} disabled={this.props.post.pollVoteChanging}>
+ Option One
+
+ {this.props.post.pollVoteChanging ?
+
+ :
+ {this.props.post.votedFor === "One" ? "Voted" : "Vote"}
+ }
+
+
+
+ Percent
+
+ {this.props.post.optionOnesBarLength.toFixed(2)}%
+
+
+
+
+
+
+
+
+
+
+ 2. {this.props.post.optionTwo || "Couldn't load option two"}
+
+
+
+
+
+
+
+
+ Votes
+
+ {this.props.post.optionTwosVotes}
+
+
+ {this.props.post.votedFor === "Two" ? this.handleRemoveVoteOnPoll() : this.handleVoteOnPoll("optionTwosVotes", "Two")}}>
+ Option Two
+
+ {this.props.post.pollVoteChanging ?
+
+ :
+ {this.props.post.votedFor === "Two" ? "Voted" : "Vote"}
+ }
+
+
+
+ Percent
+
+ {this.props.post.optionTwosBarLength.toFixed(2)}%
+
+
+
+
+
+
+
+
+ 3. {this.props.post.optionThree || "Couldn't load option three"}
+
+
+
+
+
+
+
+
+ Votes
+
+ {this.props.post.optionThreesVotes}
+
+
+ {this.props.post.votedFor === "Three" ? this.handleRemoveVoteOnPoll() : this.handleVoteOnPoll("optionThreesVotes", "Three")}}>
+ Option Three
+
+ {this.props.post.pollVoteChanging ?
+
+ :
+ {this.props.post.votedFor === "Three" ? "Voted" : "Vote"}
+ }
+
+
+
+ Percent
+
+ {this.props.post.optionThreesBarLength.toFixed(2)}%
+
+
+
+
+
+
+
+
+ 4. {this.props.post.optionFour || "Couldn't load option four"}
+
+
+
+
+
+
+
+
+ Votes
+
+ {this.props.post.optionFoursVotes}
+
+
+ {this.props.post.votedFor === "Four" ? this.handleRemoveVoteOnPoll() : this.handleVoteOnPoll("optionFoursVotes", "Four")}}>
+ Option Four
+
+ {this.props.post.pollVoteChanging ?
+
+ :
+ {this.props.post.votedFor === "Four" ? "Voted" : "Vote"}
+ }
+
+
+
+ Percent
+
+ {this.props.post.optionFoursBarLength.toFixed(2)}%
+
+
+
+
+
+
+
+
+ 5. {this.props.post.optionFive || "Couldn't load option five"}
+
+
+
+
+
+
+
+
+ Votes
+
+ {this.props.post.optionFivesVotes}
+
+
+ {this.props.post.votedFor === "Five" ? this.handleRemoveVoteOnPoll() : this.handleVoteOnPoll("optionFivesVotes", "Five")}}>
+ Option Five
+
+ {this.props.post.pollVoteChanging ?
+
+ :
+ {this.props.post.votedFor === "Five" ? "Voted" : "Vote"}
+ }
+
+
+
+ Percent
+
+ {this.props.post.optionFivesBarLength.toFixed(2)}%
+
+
+
+
+
+
+
+
+ 6. {this.props.post.optionSix || "Couldn't load option six"}
+
+
+
+
+
+
+
+
+ Votes
+
+ {this.props.post.optionSixesVotes}
+
+
+ {this.props.post.votedFor === "Six" ? this.handleRemoveVoteOnPoll() : this.handleVoteOnPoll("optionSixesVotes", "Six")}}>
+ Option Six
+
+ {this.props.post.pollVoteChanging ?
+
+ :
+ {this.props.post.votedFor === "Six" ? "Voted" : "Vote"}
+ }
+
+
+
+ Percent
+
+ {this.props.post.optionSixesBarLength.toFixed(2)}%
+
+
+
+
+
+ {this.props.post.changingVote ?
+
+
+
+
+
+ :
+ <>
+
+
+
+
+ {this.props.post.votes}
+
+
+
+
+ >
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Total Votes: {this.props.post.optionOnesVotes + this.props.post.optionTwosVotes + this.props.post.optionThreesVotes + this.props.post.optionFoursVotes + this.props.post.optionFivesVotes + this.props.post.optionSixesVotes}
+
+ {getTimeFromUTCMS(this.props.post.datePosted)}
+ {this.props.post.comments} comments
+
+ >
+ )
+ }
+}
+
+export default function(props) {
+ const navigation = useNavigation();
+ const {serverUrl} = useContext(ServerUrlContext)
+ const {storedCredentials} = useContext(CredentialsContext)
+
+ const postProps = {
+ navigation,
+ post: props.post,
+ colors: props.colors,
+ colorsIndexNum: props.colorsIndexNum,
+ dispatch: props.dispatch,
+ serverUrl,
+ index: props.index,
+ //No useRawImages support yet - Might want to add that in the future
+ storedCredentials
+ }
+
+ return
+};
\ No newline at end of file
diff --git a/hooks/usePostReducer.js b/hooks/usePostReducer.js
index 241ce2d..7638e23 100644
--- a/hooks/usePostReducer.js
+++ b/hooks/usePostReducer.js
@@ -240,7 +240,69 @@ const reducer = (state, action) => {
}
}
- throw new Error('Wrong action type was passed to usePostReducer')
+ if (action.type === 'startPollVoteChange') {
+ if (typeof action.postIndex !== 'number') throw new Error('postIndex was not provided to startPollVoteChange action of usePostReducer')
+
+ if (typeof state.posts[action.postIndex] !== 'object' || Array.isArray(state.posts[action.postIndex]) || state.posts[action.postIndex] === null) throw new Error(`Post at index ${action.postIndex} is not an object`)
+
+ state.posts[action.postIndex] = {
+ ...state.posts[action.postIndex],
+ pollVoteChanging: true
+ }
+
+ return {...state};
+ }
+
+ if (action.type === 'stopPollVoteChange') {
+ if (typeof action.postIndex !== 'number') throw new Error('postIndex was not provided to stopPollVoteChange action of usePostReducer')
+
+ if (typeof state.posts[action.postIndex] !== 'object' || Array.isArray(state.posts[action.postIndex]) || state.posts[action.postIndex] === null) throw new Error(`Post at index ${action.postIndex} is not an object`)
+
+ state.posts[action.postIndex] = {
+ ...state.posts[action.postIndex],
+ pollVoteChanging: false
+ }
+
+ return {...state};
+ }
+
+ if (action.type === 'voteOnPoll') {
+ if (typeof action.postIndex !== 'number') throw new Error('postIndex was not provided to voteOnPoll action of usePostReducer')
+ if (typeof state.posts[action.postIndex] !== 'object' || Array.isArray(state.posts[action.postIndex]) || state.posts[action.postIndex] === null) throw new Error(`Post at index ${action.postIndex} is not an object`)
+
+ state.posts[action.postIndex] = {
+ ...state.posts[action.postIndex],
+ votedFor: action.optionSelected
+ }
+
+ return {...state}
+ }
+
+ if (action.type === 'removeVoteOnPoll') {
+ if (typeof action.postIndex !== 'number') throw new Error('postIndex was not provided to removeVoteOnPoll action of usePostReducer')
+ if (typeof state.posts[action.postIndex] !== 'object' || Array.isArray(state.posts[action.postIndex]) || state.posts[action.postIndex] === null) throw new Error(`Post at index ${action.postIndex} is not an object`)
+
+ state.posts[action.postIndex] = {
+ ...state.posts[action.postIndex],
+ votedFor: 'None'
+ }
+
+ return {...state}
+ }
+
+ if (action.type === 'openPollVoteMenu') {
+ if (typeof action.postIndex !== 'number') throw new Error('postIndex was not provided to openPollVoteMenu action of usePostReducer')
+ if (typeof state.posts[action.postIndex] !== 'object' || Array.isArray(state.posts[action.postIndex]) || state.posts[action.postIndex] === null) throw new Error(`Post at index ${action.postIndex} is not an object`)
+
+ state.posts[action.postIndex] = {
+ ...state.posts[action.postIndex],
+ openPollVoteMenu: state.posts[action.postIndex].openPollVoteMenu === action.openPollVoteMenu ? "None" : action.openPollVoteMenu
+ }
+
+ return {...state}
+ }
+
+ throw new Error(`Wrong action type was passed to usePostReducer: ${action.type}`)
}
const initialState = {
diff --git a/screens/ViewPollPostPage.js b/screens/ViewPollPostPage.js
index a3188b0..1aa7559 100644
--- a/screens/ViewPollPostPage.js
+++ b/screens/ViewPollPostPage.js
@@ -1,4 +1,4 @@
-import React, {useState, useContext} from 'react';
+import React, {useState, useContext, useEffect} from 'react';
import { StatusBar } from 'expo-status-bar';
// formik
@@ -66,41 +66,27 @@ import AsyncStorage from '@react-native-async-storage/async-storage';
import { CredentialsContext } from './../components/CredentialsContext';
import { View, ImageBackground, ScrollView, SectionList, ActivityIndicator, StyleSheet, TouchableOpacity, Text, Image } from 'react-native';
-import { useTheme } from '@react-navigation/native';
+import { useIsFocused, useTheme } from '@react-navigation/native';
import { ProfilePictureURIContext } from '../components/ProfilePictureURIContext';
import { ServerUrlContext } from '../components/ServerUrlContext.js';
import { StatusBarHeightContext } from '../components/StatusBarHeightContext';
import ParseErrorMessage from '../components/ParseErrorMessage';
import { getTimeFromUTCMS } from '../libraries/Time';
+import PollWithVotes from '../components/Posts/PollWithVotes';
+import usePostReducer from '../hooks/usePostReducer';
+import ThreeDotMenuActionSheet from '../components/Posts/ThreeDotMenuActionSheet';
const ViewPollPostPage = ({route, navigation}) => {
- const {colors, dark} = useTheme();
- const [hidePassword, setHidePassword] = useState(true);
+ const [postReducer, dispatch] = usePostReducer();
+ const [deleted, setDeleted] = useState(false)
+ const {colors, dark, colorsIndexNum} = useTheme();
const [message, setMessage] = useState();
const [messageType, setMessageType] = useState();
const {storedCredentials, setStoredCredentials} = useContext(CredentialsContext);
if (storedCredentials) {var {name } = storedCredentials} else {var {name } = {name: 'SSGUEST'}};
- const { pollTitle, pollSubTitle, optionOne, optionOnesColor, optionOnesVotes, optionOnesBarLength, optionTwo, optionTwosColor, optionTwosVotes, optionTwosBarLength, optionThree, optionThreesColor, optionThreesVotes, optionThreesBarLength, optionFour, optionFoursColor, optionFoursVotes, optionFoursBarLength, optionFive, optionFivesColor, optionFivesVotes, optionFivesBarLength, optionSix, optionSixesColor, optionSixesVotes, optionSixesBarLength, totalNumberOfOptions, pollLikes, pollId, votedFor, creatorPfpB64, creatorName, creatorDisplayName, datePosted} = route.params;
- //Titles use states
- var allDataCollected = {data: {pollTitle: pollTitle, pollSubTitle: pollSubTitle, optionOne: optionOne, optionOnesColor: optionOnesColor, optionOnesVotes: optionOnesVotes, optionOnesBarLength: optionOnesBarLength, optionTwo: optionTwo, optionTwosColor: optionTwosColor, optionTwosVotes: optionTwosVotes, optionTwosBarLength: optionTwosBarLength, optionThree: optionThree, optionThreesColor: optionThreesColor, optionThreesVotes: optionThreesVotes, optionThreesBarLength: optionThreesBarLength, optionFour: optionFour, optionFoursColor: optionFoursColor, optionFoursVotes: optionFoursVotes, optionFoursBarLength: optionFoursBarLength, optionFive: optionFive, optionFivesColor: optionFivesColor, optionFivesVotes: optionFivesVotes, optionFivesBarLength: optionFivesBarLength, optionSix: optionSix, optionSixesColor: optionSixesColor, optionSixesVotes: optionSixesVotes, optionSixesBarLength: optionSixesBarLength, totalNumberOfOptions: totalNumberOfOptions, pollLikes: pollLikes, pollId: pollId, votedFor: votedFor, creatorPfpB64: creatorPfpB64, creatorName: creatorName, creatorDisplayName: creatorName, datePosted}}
- const [objectForAllData, setObjectForAllData] = useState(allDataCollected)
- //
- const [optionOneInfoState, setOptionOneInfoState] = useState(false)
- const [optionTwoInfoState, setOptionTwoInfoState] = useState(false)
- const [optionThreeInfoState, setOptionThreeInfoState] = useState(false)
- const [optionFourInfoState, setOptionFourInfoState] = useState(false)
- const [optionFiveInfoState, setOptionFiveInfoState] = useState(false)
- const [optionSixInfoState, setOptionSixInfoState] = useState(false)
- const [optionOneVoteText, setOptionOneVoteText] = useState("Vote")
- const [optionTwoVoteText, setOptionTwoVoteText] = useState("Vote")
- const [optionThreeVoteText, setOptionThreeVoteText] = useState("Vote")
- const [optionFourVoteText, setOptionFourVoteText] = useState("Vote")
- const [optionFiveVoteText, setOptionFiveVoteText] = useState("Vote")
- const [optionSixVoteText, setOptionSixVoteText] = useState("Vote")
- const [limitVoteTextChange, setLimitVoteTextChange] = useState(false)
- const [likeSubmitting, setLikeSubmitting] = useState(false)
+ const { post, isOwner } = route.params;
//Comment stuff
const [ifCommentText, setIfCommentText] = useState("No comments found")
const [changeSections, setChangeSections] = useState([])
@@ -109,16 +95,6 @@ const ViewPollPostPage = ({route, navigation}) => {
const [commentLoadMax, setCommentLoadMax] = useState(10)
const [commentsLength , setCommentsLength] = useState("Loading")
const [loadingMoreComments, setLoadingMoreComments] = useState(false)
- //change stuff
- const [pollUpOrDownVotes, setPollUpOrDownVotes] = useState("Finding")
- const [initialPollUpOrDownVotes, setInitialPollUpOrDownVotes] = useState("Finding")
- const [pollUpOrDownVoted, setPollUpOrDownVoted] = useState("Finding")
- const [initialPollUpOrDownVoted, setInitialPollUpOrDownVoted] = useState("Finding")
- const [pollVotesForOptions, setPollVotesForOptions] = useState({optionOne: "Finding", optionTwo: "Finding", optionThree: "Finding", optionFour: "Finding", optionFive: "Finding", optionSix: "Finding"})
- const [initialPollVotesForOptions, setInitialPollVotesForOptions] = useState({optionOne: "Finding", optionTwo: "Finding", optionThree: "Finding", optionFour: "Finding", optionFive: "Finding", optionSix: "Finding"})
- const [pollBarLengths, setPollBarLengths] = useState({optionOnesBarLength: 0, optionTwosBarLength: 0, optionThreesBarLength: 0, optionFoursBarLength: 0, optionFivesBarLength:0, optionSixesBarLength: 0})
- const [pollVoteOption, setPollVoteOption] = useState("Finding")
- const [pollinitialVoteOption, setPollinitialVoteOption] = useState("Finding")
//PFP
const {profilePictureUri, setProfilePictureUri} = useContext(ProfilePictureURIContext)
//Server stuff
@@ -126,163 +102,16 @@ const ViewPollPostPage = ({route, navigation}) => {
const StatusBarHeight = useContext(StatusBarHeightContext);
- //get image of post
- async function getImageInPost(imageData, index) {
- return axios.get(`${serverUrl}/getImageOnServer/${imageData[index].imageKey}`)
- .then(res => 'data:image/jpeg;base64,' + res.data);
- }
- //profile image of creator
- async function getImageInPfp(imageData, index) {
- return axios.get(`${serverUrl}/getImageOnServer/${imageData[index].creatorPfpKey}`)
- .then(res => 'data:image/jpeg;base64,' + res.data);
- }
+ useEffect(() => {
+ dispatch({type: 'addPosts', posts: [post]})
+ }, [])
+
//profile image of commenter
async function getImageInPfpComments(commentData, index) {
return axios.get(`${serverUrl}/getImageOnServer/${commentData[index].profileImageKey}`)
.then(res => 'data:image/jpeg;base64,' + res.data);
}
- const layoutPollPosts = (data) => {
- console.log("here is data")
- console.log(data)
- var pollData = data.data
- console.log(pollData)
- console.log(pollData.length)
- var optionOnesBarLength = 16.6666666667
- var optionTwosBarLength = 16.6666666667
- var optionThreesBarLength = 16.6666666667
- var optionFoursBarLength = 16.6666666667
- var optionFivesBarLength = 16.6666666667
- var optionSixesBarLength = 16.6666666667
- var totalVotes = pollData[0].optionOnesVotes+pollData[0].optionTwosVotes+pollData[0].optionThreesVotes+pollData[0].optionFoursVotes+pollData[0].optionFivesVotes+pollData[0].optionSixesVotes
- if (totalVotes !== 0) {
- optionOnesBarLength = (pollData[0].optionOnesVotes/totalVotes)*100
- console.log("O1 BL")
- console.log(optionOnesBarLength)
- optionTwosBarLength = (pollData[0].optionTwosVotes/totalVotes)*100
- console.log("O2 BL")
- console.log(optionTwosBarLength)
- optionThreesBarLength = (pollData[0].optionThreesVotes/totalVotes)*100
- console.log("O3 BL")
- console.log(optionThreesBarLength)
- optionFoursBarLength = (pollData[0].optionFoursVotes/totalVotes)*100
- console.log("O4 BL")
- console.log(optionFoursBarLength)
- optionFivesBarLength = (pollData[0].optionFivesVotes/totalVotes)*100
- console.log("O5 BL")
- console.log(optionFivesBarLength)
- optionSixesBarLength = (pollData[0].optionSixesVotes/totalVotes)*100
- console.log("O6 BL")
- console.log(optionSixesBarLength)
- if (Number.isNaN(optionOnesBarLength)) {
- optionOnesBarLength = 0
- }
- if (Number.isNaN(optionTwosBarLength)) {
- optionTwosBarLength = 0
- }
- if (Number.isNaN(optionThreesBarLength)) {
- optionThreesBarLength = 0
- }
- if (Number.isNaN(optionFoursBarLength)) {
- optionFoursBarLength = 0
- }
- if (Number.isNaN(optionFivesBarLength)) {
- optionFivesBarLength = 0
- }
- if (Number.isNaN(optionSixesBarLength)) {
- optionSixesBarLength = 0
- }
- setPollBarLengths({optionOnesBarLength: optionOnesBarLength, optionTwosBarLength: optionTwosBarLength, optionThreesBarLength: optionThreesBarLength, optionFoursBarLength: optionFoursBarLength, optionFivesBarLength: optionFivesBarLength, optionSixesBarLength: optionSixesBarLength})
- } else {
- if (totalVotes == 0) {
- console.log("No Votes")
- if (pollData[0].totalNumberOfOptions == "Two") {
- optionOnesBarLength = 100/2
- optionTwosBarLength = 100/2
- optionThreesBarLength = 0
- optionFoursBarLength = 0
- optionFivesBarLength = 0
- optionSixesBarLength = 0
- setPollBarLengths({optionOnesBarLength: optionOnesBarLength, optionTwosBarLength: optionTwosBarLength, optionThreesBarLength: optionThreesBarLength, optionFoursBarLength: optionFoursBarLength, optionFivesBarLength: optionFivesBarLength, optionSixesBarLength: optionSixesBarLength})
- } else if (pollData[0].totalNumberOfOptions == "Three") {
- optionOnesBarLength = 100/3
- optionTwosBarLength = 100/3
- optionThreesBarLength = 100/3
- optionFoursBarLength = 0
- optionFivesBarLength = 0
- optionSixesBarLength = 0
- setPollBarLengths({optionOnesBarLength: optionOnesBarLength, optionTwosBarLength: optionTwosBarLength, optionThreesBarLength: optionThreesBarLength, optionFoursBarLength: optionFoursBarLength, optionFivesBarLength: optionFivesBarLength, optionSixesBarLength: optionSixesBarLength})
- } else if (pollData[0].totalNumberOfOptions == "Four") {
- optionOnesBarLength = 100/4
- optionTwosBarLength = 100/4
- optionThreesBarLength = 100/4
- optionFoursBarLength = 100/4
- optionFivesBarLength = 0
- optionSixesBarLength = 0
- setPollBarLengths({optionOnesBarLength: optionOnesBarLength, optionTwosBarLength: optionTwosBarLength, optionThreesBarLength: optionThreesBarLength, optionFoursBarLength: optionFoursBarLength, optionFivesBarLength: optionFivesBarLength, optionSixesBarLength: optionSixesBarLength})
- } else if (pollData[0].totalNumberOfOptions == "Five") {
- optionOnesBarLength = 100/5
- optionTwosBarLength = 100/5
- optionThreesBarLength = 100/5
- optionFoursBarLength = 100/5
- optionFivesBarLength = 100/5
- optionSixesBarLength = 0
- setPollBarLengths({optionOnesBarLength: optionOnesBarLength, optionTwosBarLength: optionTwosBarLength, optionThreesBarLength: optionThreesBarLength, optionFoursBarLength: optionFoursBarLength, optionFivesBarLength: optionFivesBarLength, optionSixesBarLength: optionSixesBarLength})
- } else if (pollData[0].totalNumberOfOptions == "Six") {
- optionOnesBarLength = 100/6
- optionTwosBarLength = 100/6
- optionThreesBarLength = 100/6
- optionFoursBarLength = 100/6
- optionFivesBarLength = 100/6
- optionSixesBarLength = 100/6
- setPollBarLengths({optionOnesBarLength: optionOnesBarLength, optionTwosBarLength: optionTwosBarLength, optionThreesBarLength: optionThreesBarLength, optionFoursBarLength: optionFoursBarLength, optionFivesBarLength: optionFivesBarLength, optionSixesBarLength: optionSixesBarLength})
- }
- }
- }
- }
-
- //Change to voted
- const prepareVotedandUpVoted = () => {
- const changeVoteTexts = (data) => {
- //set initial values
- const pollData = data.data[0]
- setPollUpOrDownVoted(pollData.pollUpOrDownVoted)
- setInitialPollUpOrDownVoted(pollData.pollUpOrDownVoted)
- setPollUpOrDownVotes(pollData.pollUpOrDownVotes)
- setPollVoteOption(pollData.votedFor)
- setPollinitialVoteOption(pollData.votedFor)
- setInitialPollVotesForOptions({optionOne: pollData.optionOnesVotes, optionTwo: pollData.optionTwosVotes, optionThree: pollData.optionThreesVotes, optionFour: pollData.optionFoursVotes, optionFive: pollData.optionFivesVotes, optionSix: pollData.optionSixesVotes})
- setPollVotesForOptions({optionOne: pollData.optionOnesVotes, optionTwo: pollData.optionTwosVotes, optionThree: pollData.optionThreesVotes, optionFour: pollData.optionFoursVotes, optionFive: pollData.optionFivesVotes, optionSix: pollData.optionSixesVotes})
- }
- const url = serverUrl + "/tempRoute/searchforpollpostsbyid";
-
- var toSend = {"pollId": pollId}
-
- axios.post(url, toSend).then((response) => {
- const result = response.data;
- const {message, status, data} = result;
-
- if (status !== 'SUCCESS') {
- handleMessage(message, status);
- } else {
- changeVoteTexts({data});
- layoutPollPosts({data});
- }
- //setSubmitting(false);
- }).catch(error => {
- console.error(error);
- //setSubmitting(false);
- handleMessage(ParseErrorMessage(error));
- })
- }
-
- if (limitVoteTextChange == false) {
- setLimitVoteTextChange(true);
- prepareVotedandUpVoted();
- }
-
- //
-
const Item = ({commentId, commenterName, commenterDisplayName, commentsText, commentUpVotes, commentReplies, datePosted, commenterImageB64}) => (
@@ -320,7 +149,7 @@ const ViewPollPostPage = ({route, navigation}) => {
{datePosted}
- {navigation.navigate("CommentViewPage", {commentId: commentId, postId: pollId, postFormat: "Poll"})}}>
+ {navigation.navigate("CommentViewPage", {commentId: commentId, postId: post._id, postFormat: "Poll"})}}>
{commentReplies} replies
@@ -384,7 +213,7 @@ const ViewPollPostPage = ({route, navigation}) => {
const url = `${serverUrl}/tempRoute/searchforpollcomments`;
const toSend = {
- pollId
+ pollId: post._id
}
setLoadingMoreComments(true)
axios.post(url, toSend).then((response) => {
@@ -436,522 +265,28 @@ const ViewPollPostPage = ({route, navigation}) => {
})
}
- const handleVoteOnPoll = (optionSelected) => {
- if (storedCredentials) {
- handleMessage(null);
- console.log(optionSelected)
- const url = serverUrl + "/tempRoute/voteonpoll";
-
- var toSend = {optionSelected: optionSelected, pollId: pollId}
-
- console.log(toSend)
-
- axios.post(url, toSend).then((response) => {
- const result = response.data;
- const {message, status, data} = result;
-
- if (status !== 'SUCCESS') {
- handleMessage(message, status);
- } else {
- handleMessage(message, status);
- console.log("Message:")
- console.log(message)
- var lastVote = data.lastVote
- console.log("Last Vote:")
- console.log(lastVote)
- if (message == "Vote successful") {
- //voted
- var optionOnesBarLength = 16.6666666667
- var optionTwosBarLength = 16.6666666667
- var optionThreesBarLength = 16.6666666667
- var optionFoursBarLength = 16.6666666667
- var optionFivesBarLength = 16.6666666667
- var optionSixesBarLength = 16.6666666667
- var o1V = initialPollVotesForOptions.optionOne
- var o2V = initialPollVotesForOptions.optionTwo
- var o3V = initialPollVotesForOptions.optionThree
- var o4V = initialPollVotesForOptions.optionFour
- var o5V = initialPollVotesForOptions.optionFive
- var o6V = initialPollVotesForOptions.optionSix
- //Change depending on initial
- if (pollVoteOption == "None") {
- if (optionSelected == "optionOnesVotes") {
- o1V = o1V+1
- } else if (optionSelected == "optionTwosVotes") {
- o2V = o2V+1
- } else if (optionSelected == "optionThreesVotes") {
- o3V = o3V+1
- } else if (optionSelected == "optionFoursVotes") {
- o4V = o4V+1
- } else if (optionSelected == "optionFivesVotes") {
- o5V = o5V+1
- } else {
- //six
- o6V = o6V+1
- }
- } else if (pollVoteOption == "One") {
- o1V = o1V-1
- if (optionSelected == "optionOnesVotes") {
- o1V = o1V+1
- } else if (optionSelected == "optionTwosVotes") {
- o2V = o2V+1
- } else if (optionSelected == "optionThreesVotes") {
- o3V = o3V+1
- } else if (optionSelected == "optionFoursVotes") {
- o4V = o4V+1
- } else if (optionSelected == "optionFivesVotes") {
- o5V = o5V+1
- } else {
- //six
- o6V = o6V+1
- }
- } else if (pollVoteOption == "Two") {
- o2V = o2V-1
- if (optionSelected == "optionOnesVotes") {
- o1V = o1V+1
- } else if (optionSelected == "optionTwosVotes") {
- o2V = o2V+1
- } else if (optionSelected == "optionThreesVotes") {
- o3V = o3V+1
- } else if (optionSelected == "optionFoursVotes") {
- o4V = o4V+1
- } else if (optionSelected == "optionFivesVotes") {
- o5V = o5V+1
- } else {
- //six
- o6V = o6V+1
- }
- } else if (pollVoteOption == "Three") {
- o3V = o3V-1
- if (optionSelected == "optionOnesVotes") {
- o1V = o1V+1
- } else if (optionSelected == "optionTwosVotes") {
- o2V = o2V+1
- } else if (optionSelected == "optionThreesVotes") {
- o3V = o3V+1
- } else if (optionSelected == "optionFoursVotes") {
- o4V = o4V+1
- } else if (optionSelected == "optionFivesVotes") {
- o5V = o5V+1
- } else {
- //six
- o6V = o6V+1
- }
- } else if (pollVoteOption == "Four") {
- o4V = o4V-1
- if (optionSelected == "optionOnesVotes") {
- o1V = o1V+1
- } else if (optionSelected == "optionTwosVotes") {
- o2V = o2V+1
- } else if (optionSelected == "optionThreesVotes") {
- o3V = o3V+1
- } else if (optionSelected == "optionFoursVotes") {
- o4V = o4V+1
- } else if (optionSelected == "optionFivesVotes") {
- o5V = o5V+1
- } else {
- //six
- o6V = o6V+1
- }
- } else if (pollVoteOption == "Five") {
- o5V = o5V-1
- if (optionSelected == "optionOnesVotes") {
- o1V = o1V+1
- } else if (optionSelected == "optionTwosVotes") {
- o2V = o2V+1
- } else if (optionSelected == "optionThreesVotes") {
- o3V = o3V+1
- } else if (optionSelected == "optionFoursVotes") {
- o4V = o4V+1
- } else if (optionSelected == "optionFivesVotes") {
- o5V = o5V+1
- } else {
- //six
- o6V = o6V+1
- }
- } else {
- o6V = o6V-1
- if (optionSelected == "optionOnesVotes") {
- o1V = o1V+1
- } else if (optionSelected == "optionTwosVotes") {
- o2V = o2V+1
- } else if (optionSelected == "optionThreesVotes") {
- o3V = o3V+1
- } else if (optionSelected == "optionFoursVotes") {
- o4V = o4V+1
- } else if (optionSelected == "optionFivesVotes") {
- o5V = o5V+1
- } else {
- //six
- o6V = o6V+1
- }
- }
- var totalVotes = o1V+o2V+o3V+o4V+o5V+o6V
- optionOnesBarLength = (o1V/totalVotes)*100
- console.log("O1 BL")
- console.log(optionOnesBarLength)
- optionTwosBarLength = (o2V/totalVotes)*100
- console.log("O2 BL")
- console.log(optionTwosBarLength)
- optionThreesBarLength = (o3V/totalVotes)*100
- console.log("O3 BL")
- console.log(optionThreesBarLength)
- optionFoursBarLength = (o4V/totalVotes)*100
- console.log("O4 BL")
- console.log(optionFoursBarLength)
- optionFivesBarLength = (o5V/totalVotes)*100
- console.log("O5 BL")
- console.log(optionFivesBarLength)
- optionSixesBarLength = (o6V/totalVotes)*100
- console.log("O6 BL")
- console.log(optionSixesBarLength)
- if (Number.isNaN(optionOnesBarLength)) {
- optionOnesBarLength = 0
- }
- if (Number.isNaN(optionTwosBarLength)) {
- optionTwosBarLength = 0
- }
- if (Number.isNaN(optionThreesBarLength)) {
- optionThreesBarLength = 0
- }
- if (Number.isNaN(optionFoursBarLength)) {
- optionFoursBarLength = 0
- }
- if (Number.isNaN(optionFivesBarLength)) {
- optionFivesBarLength = 0
- }
- if (Number.isNaN(optionSixesBarLength)) {
- optionSixesBarLength = 0
- }
- if (optionSelected == "optionOnesVotes") {
- setOptionOneVoteText("Voted")
- setOptionTwoVoteText("Vote")
- setOptionThreeVoteText("Vote")
- setOptionFourVoteText("Vote")
- setOptionFiveVoteText("Vote")
- setOptionSixVoteText("Vote")
- } else if (optionSelected == "optionTwosVotes") {
- setOptionOneVoteText("Vote")
- setOptionTwoVoteText("Voted")
- setOptionThreeVoteText("Vote")
- setOptionFourVoteText("Vote")
- setOptionFiveVoteText("Vote")
- setOptionSixVoteText("Vote")
- } else if (optionSelected == "optionThreesVotes") {
- setOptionOneVoteText("Vote")
- setOptionTwoVoteText("Vote")
- setOptionThreeVoteText("Voted")
- setOptionFourVoteText("Vote")
- setOptionFiveVoteText("Vote")
- setOptionSixVoteText("Vote")
- } else if (optionSelected == "optionFoursVotes") {
- setOptionOneVoteText("Vote")
- setOptionTwoVoteText("Vote")
- setOptionThreeVoteText("Vote")
- setOptionFourVoteText("Voted")
- setOptionFiveVoteText("Vote")
- setOptionSixVoteText("Vote")
- } else if (optionSelected == "optionFivesVotes") {
- setOptionOneVoteText("Vote")
- setOptionTwoVoteText("Vote")
- setOptionThreeVoteText("Vote")
- setOptionFourVoteText("Vote")
- setOptionFiveVoteText("Voted")
- setOptionSixVoteText("Vote")
- } else {
- setOptionOneVoteText("Vote")
- setOptionTwoVoteText("Vote")
- setOptionThreeVoteText("Vote")
- setOptionFourVoteText("Vote")
- setOptionFiveVoteText("Vote")
- setOptionSixVoteText("Voted")
- }
- setPollVotesForOptions({optionOne: o1V, optionTwo: o2V, optionThree: o3V, optionFour: o4V, optionFive: o5V, optionSix: o6V})
- setPollBarLengths({optionOnesBarLength: optionOnesBarLength, optionTwosBarLength: optionTwosBarLength, optionThreesBarLength: optionThreesBarLength, optionFoursBarLength: optionFoursBarLength, optionFivesBarLength: optionFivesBarLength, optionSixesBarLength: optionSixesBarLength})
- } else {
- //pulled
- console.log("Change based on pull")
- var optionOnesBarLength = 16.6666666667
- var optionTwosBarLength = 16.6666666667
- var optionThreesBarLength = 16.6666666667
- var optionFoursBarLength = 16.6666666667
- var optionFivesBarLength = 16.6666666667
- var optionSixesBarLength = 16.6666666667
- var o1V = initialPollVotesForOptions.optionOne
- var o2V = initialPollVotesForOptions.optionTwo
- var o3V = initialPollVotesForOptions.optionThree
- var o4V = initialPollVotesForOptions.optionFour
- var o5V = initialPollVotesForOptions.optionFive
- var o6V = initialPollVotesForOptions.optionSix
- if (o1V !== "Finding") {
- if (pollVoteOption == "One") {
- o1V = o1V-1
- } else if (pollVoteOption == "Two") {
- o2V = o2V-1
- } else if (pollVoteOption == "Three") {
- o3V = o3V-1
- } else if (pollVoteOption == "Four") {
- o4V = o4V-1
- } else if (pollVoteOption == "Five") {
- o5V = o5V-1
- } else if (pollVoteOption == "Six") {
- o6V = o6V-1
- } else {
- //Initial Poll Vote Option Would Be None
- //Keep original
- o1V = initialPollVotesForOptions.optionOne
- o2V = initialPollVotesForOptions.optionTwo
- o3V = initialPollVotesForOptions.optionThree
- o4V = initialPollVotesForOptions.optionFour
- o5V = initialPollVotesForOptions.optionFive
- o6V = initialPollVotesForOptions.optionSix
- }
- var totalVotes = o1V+o2V+o3V+o4V+o5V+o6V
- console.log("Total Votes:")
- console.log(totalVotes)
- if (totalVotes == 0) {
- console.log("No Votes")
- if (totalNumberOfOptions == "Two") {
- optionOnesBarLength = 100/2
- optionTwosBarLength = 100/2
- optionThreesBarLength = 0
- optionFoursBarLength = 0
- optionFivesBarLength = 0
- optionSixesBarLength = 0
- setPollVotesForOptions({optionOne: o1V, optionTwo: o2V, optionThree: o3V, optionFour: o4V, optionFive: o5V, optionSix: o6V})
- setPollBarLengths({optionOnesBarLength: optionOnesBarLength, optionTwosBarLength: optionTwosBarLength, optionThreesBarLength: optionThreesBarLength, optionFoursBarLength: optionFoursBarLength, optionFivesBarLength: optionFivesBarLength, optionSixesBarLength: optionSixesBarLength})
- } else if (totalNumberOfOptions == "Three") {
- optionOnesBarLength = 100/3
- optionTwosBarLength = 100/3
- optionThreesBarLength = 100/3
- optionFoursBarLength = 0
- optionFivesBarLength = 0
- optionSixesBarLength = 0
- setPollVotesForOptions({optionOne: o1V, optionTwo: o2V, optionThree: o3V, optionFour: o4V, optionFive: o5V, optionSix: o6V})
- setPollBarLengths({optionOnesBarLength: optionOnesBarLength, optionTwosBarLength: optionTwosBarLength, optionThreesBarLength: optionThreesBarLength, optionFoursBarLength: optionFoursBarLength, optionFivesBarLength: optionFivesBarLength, optionSixesBarLength: optionSixesBarLength})
- } else if (totalNumberOfOptions == "Four") {
- optionOnesBarLength = 100/4
- optionTwosBarLength = 100/4
- optionThreesBarLength = 100/4
- optionFoursBarLength = 100/4
- optionFivesBarLength = 0
- optionSixesBarLength = 0
- setPollVotesForOptions({optionOne: o1V, optionTwo: o2V, optionThree: o3V, optionFour: o4V, optionFive: o5V, optionSix: o6V})
- setPollBarLengths({optionOnesBarLength: optionOnesBarLength, optionTwosBarLength: optionTwosBarLength, optionThreesBarLength: optionThreesBarLength, optionFoursBarLength: optionFoursBarLength, optionFivesBarLength: optionFivesBarLength, optionSixesBarLength: optionSixesBarLength})
- } else if (totalNumberOfOptions == "Five") {
- optionOnesBarLength = 100/5
- optionTwosBarLength = 100/5
- optionThreesBarLength = 100/5
- optionFoursBarLength = 100/5
- optionFivesBarLength = 100/5
- optionSixesBarLength = 0
- setPollVotesForOptions({optionOne: o1V, optionTwo: o2V, optionThree: o3V, optionFour: o4V, optionFive: o5V, optionSix: o6V})
- setPollBarLengths({optionOnesBarLength: optionOnesBarLength, optionTwosBarLength: optionTwosBarLength, optionThreesBarLength: optionThreesBarLength, optionFoursBarLength: optionFoursBarLength, optionFivesBarLength: optionFivesBarLength, optionSixesBarLength: optionSixesBarLength})
- } else {
- optionOnesBarLength = 100/6
- optionTwosBarLength = 100/6
- optionThreesBarLength = 100/6
- optionFoursBarLength = 100/6
- optionFivesBarLength = 100/6
- optionSixesBarLength = 100/6
- setPollVotesForOptions({optionOne: o1V, optionTwo: o2V, optionThree: o3V, optionFour: o4V, optionFive: o5V, optionSix: o6V})
- setPollBarLengths({optionOnesBarLength: optionOnesBarLength, optionTwosBarLength: optionTwosBarLength, optionThreesBarLength: optionThreesBarLength, optionFoursBarLength: optionFoursBarLength, optionFivesBarLength: optionFivesBarLength, optionSixesBarLength: optionSixesBarLength})
- }
- } else {
- console.log("Pulled results")
- optionOnesBarLength = (o1V/totalVotes)*100
- console.log("O1 BL")
- console.log(optionOnesBarLength)
- optionTwosBarLength = (o2V/totalVotes)*100
- console.log("O2 BL")
- console.log(optionTwosBarLength)
- optionThreesBarLength = (o3V/totalVotes)*100
- console.log("O3 BL")
- console.log(optionThreesBarLength)
- optionFoursBarLength = (o4V/totalVotes)*100
- console.log("O4 BL")
- console.log(optionFoursBarLength)
- optionFivesBarLength = (o5V/totalVotes)*100
- console.log("O5 BL")
- console.log(optionFivesBarLength)
- optionSixesBarLength = (o6V/totalVotes)*100
- console.log("O6 BL")
- console.log(optionSixesBarLength)
- if (Number.isNaN(optionOnesBarLength)) {
- optionOnesBarLength = 0
- }
- if (Number.isNaN(optionTwosBarLength)) {
- optionTwosBarLength = 0
- }
- if (Number.isNaN(optionThreesBarLength)) {
- optionThreesBarLength = 0
- }
- if (Number.isNaN(optionFoursBarLength)) {
- optionFoursBarLength = 0
- }
- if (Number.isNaN(optionFivesBarLength)) {
- optionFivesBarLength = 0
- }
- if (Number.isNaN(optionSixesBarLength)) {
- optionSixesBarLength = 0
- }
- }
- setPollVotesForOptions({optionOne: o1V, optionTwo: o2V, optionThree: o3V, optionFour: o4V, optionFive: o5V, optionSix: o6V})
- setPollBarLengths({optionOnesBarLength: optionOnesBarLength, optionTwosBarLength: optionTwosBarLength, optionThreesBarLength: optionThreesBarLength, optionFoursBarLength: optionFoursBarLength, optionFivesBarLength: optionFivesBarLength, optionSixesBarLength: optionSixesBarLength})
- } else {
- handleMessage("Page didn't fully load try again", "FAILED")
- }
- }
- //loadAndGetValues()
- //persistLogin({...data[0]}, message, status);
- }
- setSubmitting(false);
-
- }).catch(error => {
- console.error(error);
- setSubmitting(false);
- handleMessage(ParseErrorMessage(error));
- })
- } else {
- navigation.navigate('ModalLoginScreen', {modal: true})
- }
- }
-
const handleMessage = (message, type = 'FAILED') => {
setMessage(message);
setMessageType(type);
}
- const UpVotePoll = () => {
- if (storedCredentials) {
- //Change to loading circle
- const beforeChange = pollUpOrDownVoted
- setPollUpOrDownVoted("Changing")
- //Do rest
- handleMessage(null, null, null);
- const url = serverUrl + "/tempRoute/upvotepoll";
-
- var toSend = {pollId: pollId}
-
- console.log(toSend)
+ const isFocused = useIsFocused();
- axios.post(url, toSend).then((response) => {
- const result = response.data;
- const {message, status, data} = result;
-
- if (status !== 'SUCCESS') {
- handleMessage(message, status, postNum);
- setPollUpOrDownVoted(beforeChange)
- } else {
- handleMessage(message, status);
- if (message == "Post UpVoted") {
- setPollUpOrDownVoted("UpVoted")
- } else {
- setPollUpOrDownVoted("Neither")
- }
- //loadAndGetValues()
- //persistLogin({...data[0]}, message, status);
- }
- }).catch(error => {
- console.error(error);
- setPollUpOrDownVoted(beforeChange)
- handleMessage(ParseErrorMessage(error), 'FAILED', postNum);
- })
+ const onDeleteCallback = () => {
+ if (isFocused) {
+ navigation.goBack();
} else {
- navigation.navigate('ModalLoginScreen', {modal: true})
+ setDeleted(true)
}
}
- const DownVotePoll = () => {
- if (storedCredentials) {
- //Change to loading circle
- const beforeChange = pollUpOrDownVoted
- setPollUpOrDownVoted("Changing")
- //Do rest
- handleMessage(null, null, null);
- const url = serverUrl + "/tempRoute/downvotepoll";
-
- var toSend = {pollId: pollId}
-
- console.log(toSend)
-
- axios.post(url, toSend).then((response) => {
- const result = response.data;
- const {message, status, data} = result;
-
- if (status !== 'SUCCESS') {
- handleMessage(message, status, postNum);
- setPollUpOrDownVoted(beforeChange)
- } else {
- handleMessage(message, status);
- if (message == "Post DownVoted") {
- setPollUpOrDownVoted("DownVoted")
- } else {
- setPollUpOrDownVoted("Neither")
- }
- //loadAndGetValues()
- //persistLogin({...data[0]}, message, status);
- }
- }).catch(error => {
- console.error(error);
- setPollUpOrDownVoted(beforeChange)
- handleMessage(ParseErrorMessage(error), 'FAILED', postNum);
- })
- } else {
- navigation.navigate('ModalLoginScreen', {modal: true})
- }
- }
-
- const openOptionOne = () => {
- if (optionOneInfoState !== true) {
- setOptionOneInfoState(true)
- } else {
- setOptionOneInfoState(false)
- }
- }
-
- const openOptionTwo = () => {
- if (optionTwoInfoState !== true) {
- setOptionTwoInfoState(true)
- } else {
- setOptionTwoInfoState(false)
- }
- }
-
- const openOptionThree = () => {
- if (optionThreeInfoState !== true) {
- setOptionThreeInfoState(true)
- } else {
- setOptionThreeInfoState(false)
- }
- }
-
- const openOptionFour = () => {
- if (optionFourInfoState !== true) {
- setOptionFourInfoState(true)
- } else {
- setOptionFourInfoState(false)
- }
- }
-
- const openOptionFive = () => {
- if (optionFiveInfoState !== true) {
- setOptionFiveInfoState(true)
- } else {
- setOptionFiveInfoState(false)
- }
- }
-
- const openOptionSix = () => {
- if (optionSixInfoState !== true) {
- setOptionSixInfoState(true)
- } else {
- setOptionSixInfoState(false)
- }
- }
+ useEffect(() => {
+ if (isFocused && deleted) navigation.goBack();
+ }, [isFocused])
return(
- <>
+ <>
+
{navigation.goBack()}}>
@@ -962,339 +297,18 @@ const ViewPollPostPage = ({route, navigation}) => {
resizeMethod="resize"
/>
- {creatorDisplayName ? creatorDisplayName : creatorName}'s poll
+ {(post.creatorDisplayName ? post.creatorDisplayName : post.creatorName) || 'ERROR'}'s poll
-
-
-
-
-
-
- {creatorDisplayName}
- @{creatorName}
-
-
-
- {objectForAllData.data.pollTitle || "Couldn't recieve data"}
-
-
- {objectForAllData.data.pollSubTitle || "Couldn't recieve data"}
-
-
-
- 1
-
-
- 2
-
-
- 3
-
-
- 4
-
-
- 5
-
-
- 6
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 1. {objectForAllData.data.optionOne || "Couldn't recieve data"}
-
-
-
-
-
-
-
-
- Votes
-
- {pollVotesForOptions.optionOne}
-
-
- {handleVoteOnPoll("optionOnesVotes")}}>
- Option One
-
- {optionOneVoteText}
-
-
-
- Percent
-
- {pollBarLengths.optionOnesBarLength.toFixed(2)}%
-
-
-
-
-
-
-
-
-
-
- 2. {objectForAllData.data.optionTwo || "Couldn't recieve data"}
-
-
-
-
-
-
-
-
- Votes
-
- {pollVotesForOptions.optionTwo}
-
-
- {handleVoteOnPoll("optionTwosVotes")}}>
- Option Two
-
- {optionTwoVoteText}
-
-
-
- Percent
-
- {pollBarLengths.optionTwosBarLength.toFixed(2)}%
-
-
-
-
-
-
-
-
- 3. {objectForAllData.data.optionThree || "Couldn't recieve data"}
-
-
-
-
-
-
-
-
- Votes
-
- {pollVotesForOptions.optionThree}
-
-
- {handleVoteOnPoll("optionThreesVotes")}}>
- Option Three
-
- {optionThreeVoteText}
-
-
-
- Percent
-
- {pollBarLengths.optionThreesBarLength.toFixed(2)}%
-
-
-
-
-
-
-
-
- 4. {objectForAllData.data.optionFour || "Couldn't recieve data"}
-
-
-
-
-
-
-
-
- Votes
-
- {pollVotesForOptions.optionFour}
-
-
- {handleVoteOnPoll("optionFoursVotes")}}>
- Option Four
-
- {optionFourVoteText}
-
-
-
- Percent
-
- {pollBarLengths.optionFoursBarLength.toFixed(2)}%
-
-
-
-
-
-
-
-
- 5. {objectForAllData.data.optionFive || "Couldn't recieve data"}
-
-
-
-
-
-
-
-
- Votes
-
- {pollVotesForOptions.optionFive}
-
-
- {handleVoteOnPoll("optionFivesVotes")}}>
- Option Five
-
- {optionFiveVoteText}
-
-
-
- Percent
-
- {pollBarLengths.optionFivesBarLength.toFixed(2)}%
-
-
-
-
-
-
-
-
- 6. {objectForAllData.data.optionSix || "Couldn't recieve data"}
-
-
-
-
-
-
-
-
- Votes
-
- {pollVotesForOptions.optionSix}
-
-
- {handleVoteOnPoll("optionSixesVotes")}}>
- Option Six
-
- {optionSixVoteText}
-
-
-
- Percent
-
- {pollBarLengths.optionSixesBarLength.toFixed(2)}%
-
-
-
-
-
- {pollUpOrDownVoted == "UpVoted" && ( {UpVotePoll()}}>
-
- )}
- {pollUpOrDownVoted == "Neither" && ( {UpVotePoll()}}>
-
- )}
- {pollUpOrDownVoted == "DownVoted" && ( {UpVotePoll()}}>
-
- )}
- {pollUpOrDownVoted == "Changing" && ()}
-
- {pollUpOrDownVoted == "Finding" && (
- {pollUpOrDownVotes}
- )}
- {pollUpOrDownVoted == "UpVoted" && (
- {initialPollUpOrDownVoted == "UpVoted" && (
- {pollUpOrDownVotes}
- )}
- {initialPollUpOrDownVoted == "Neither" && (
- {pollUpOrDownVotes+1}
- )}
- {initialPollUpOrDownVoted == "DownVoted" && (
- {pollUpOrDownVotes+2}
- )}
- )}
- {pollUpOrDownVoted == "Neither" && (
- {initialPollUpOrDownVoted == "Neither" && (
- {pollUpOrDownVotes}
- )}
- {initialPollUpOrDownVoted == "UpVoted" && (
- {pollUpOrDownVotes-1}
- )}
- {initialPollUpOrDownVoted == "DownVoted" && (
- {pollUpOrDownVotes+1}
- )}
- )}
- {pollUpOrDownVoted == "DownVoted" && (
- {initialPollUpOrDownVoted == "DownVoted" && (
- {pollUpOrDownVotes}
- )}
- {initialPollUpOrDownVoted == "Neither" && (
- {pollUpOrDownVotes-1}
- )}
- {initialPollUpOrDownVoted == "UpVoted" && (
- {pollUpOrDownVotes-2}
- )}
- )}
- {pollUpOrDownVoted == "Changing" && (
-
- )}
-
- {pollUpOrDownVoted == "DownVoted" && ( {DownVotePoll()}}>
-
- )}
- {pollUpOrDownVoted == "Neither" && ( {DownVotePoll()}}>
-
- )}
- {pollUpOrDownVoted == "UpVoted" && ( {DownVotePoll()}}>
-
- )}
- {pollUpOrDownVoted == "Changing" && ()}
-
-
-
-
-
-
-
-
-
-
-
-
- {typeof message === 'string' || message instanceof String && (
- {message}
- )}
-
- Total Votes: {pollVotesForOptions.optionOne+pollVotesForOptions.optionTwo+pollVotesForOptions.optionThree+pollVotesForOptions.optionFour+pollVotesForOptions.optionFive+pollVotesForOptions.optionSix}
-
- {getTimeFromUTCMS(datePosted)}
- {commentsLength} comments
-
+ {postReducer.posts.length > 0 ? : null}
{storedCredentials ?
Comments
{
if (values.comment == "") {
handleMessage('You cant post and empty comment');