Enable view-comments.js to retrieve profile data from AsyncStorage

This commit is contained in:
Nat 2021-04-02 21:53:29 -03:00
parent d344ad8933
commit e07b89b981
1 changed files with 27 additions and 26 deletions

View File

@ -1,6 +1,7 @@
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import { Dimensions, View, Image, TextInput, Text } from "react-native"; import { Dimensions, View, Image, TextInput, Text } from "react-native";
import { ScrollView } from "react-native-gesture-handler"; import { ScrollView } from "react-native-gesture-handler";
import AsyncStorage from "@react-native-async-storage/async-storage";
import { timeToAge } from "src/interface/rendering"; import { timeToAge } from "src/interface/rendering";
import { activeOrNot } from "src/interface/interactions"; import { activeOrNot } from "src/interface/interactions";
@ -212,21 +213,22 @@ const ViewCommentsJsx = (props) => {
}); });
useEffect(() => { useEffect(() => {
(() => { // Some magical function that will get all the data needed AsyncStorage.getItem("@user_profile").then((profileJSON) => {
setState({ ...state, setState({ ...state,
descendants: threadify(TEST_CONTEXT.descendants), descendants: threadify(TEST_CONTEXT.descendants),
postData: props.navigation.getParam("postData"), postData: props.navigation.getParam("postData"),
profile: JSON.parse(profileJSON),
loaded: true, loaded: true,
}); });
})(); });
}, []); }, []);
return ( return (
<ContextJsx> <ContextJsx>
<View style = { { flex: 1 } }> { state.loaded ?
<BackBarJsx navigation = { props.navigation }/> <View style = { { flex: 1 } }>
<ScrollView> <BackBarJsx navigation = { props.navigation }/>
{ state.loaded ? <ScrollView>
<View style = { { display: state.loaded ? "block" : "none" } }> <View style = { { display: state.loaded ? "block" : "none" } }>
<View style = { styles.parentPost }> <View style = { styles.parentPost }>
<CommentJsx <CommentJsx
@ -237,7 +239,6 @@ const ViewCommentsJsx = (props) => {
state.descendants.map((thread, i) => { state.descendants.map((thread, i) => {
const comment = thread[0]; const comment = thread[0];
const subs = thread.slice(1); const subs = thread.slice(1);
return ( return (
<View key = { i }> <View key = { i }>
<CommentJsx data = { comment }/> <CommentJsx data = { comment }/>
@ -259,27 +260,27 @@ const ViewCommentsJsx = (props) => {
} }
</View> </View>
</View> </View>
: <View></View> </ScrollView>
} <View style = { styles.commentForm }>
</ScrollView> <Image
<View style = { styles.commentForm }> style = { styles.avatar }
<Image source = { { uri: state.profile.avatar } }/>
style = { styles.avatar } <TextInput
source = { { uri: TEST_IMAGE } }/> style = { styles.commentInput }
<TextInput placeholder = "Say something..."
style = { styles.commentInput } multiline = { true }
placeholder = "Say something..." onChangeText = { c => setState({...state, reply: c }) }/>
multiline = { true } <View style = { styles.submitContainer }>
onChangeText = { c => setState({...state, reply: c }) }/> <TouchableWithoutFeedback>
<View style = { styles.submitContainer }> <Image
<TouchableWithoutFeedback> style = { styles.commentSubmit }
<Image source = { require("assets/eva-icons/paper-plane.png") }/>
style = { styles.commentSubmit } </TouchableWithoutFeedback>
source = { require("assets/eva-icons/paper-plane.png") }/> </View>
</TouchableWithoutFeedback>
</View> </View>
</View> </View>
</View> : <></>
}
</ContextJsx> </ContextJsx>
); );
} }