From 1dc775004e2161a414acd39f1b8bf1e57066a9bf Mon Sep 17 00:00:00 2001 From: natjms Date: Tue, 11 May 2021 06:29:25 -0300 Subject: [PATCH] Enable loading posts from a grid view --- src/components/pages/profile.js | 19 ++---------- src/components/pages/view-post.js | 26 ++++++++-------- src/components/posts/grid-post.js | 23 -------------- src/components/posts/grid-view.js | 38 +++++++++++++++-------- src/components/posts/post.js | 50 ------------------------------- 5 files changed, 42 insertions(+), 114 deletions(-) delete mode 100644 src/components/posts/grid-post.js diff --git a/src/components/pages/profile.js b/src/components/pages/profile.js index fe118eb..68a9527 100644 --- a/src/components/pages/profile.js +++ b/src/components/pages/profile.js @@ -244,12 +244,6 @@ const ProfileJsx = ({ navigation }) => { }; const RawProfileJsx = (props) => { - let [state, setState] = useState({ - own: props.own, - profile: props.profile, - notifs: props.notifs, - }); - const notif_pack = { active: require("assets/eva-icons/bell-unread.png"), inactive: require("assets/eva-icons/bell-black.png") @@ -298,7 +292,7 @@ const RawProfileJsx = (props) => { { - state.own ? + props.own ? { } }> { - state.own ? + props.own ? <>View followers : <>{ props.mutuals + " mutuals" } } @@ -370,14 +364,7 @@ const RawProfileJsx = (props) => { { - props.navigation.navigate("ViewPost", { - id: id, - originTab: "Profile" - }); - } - } /> + navigation = { props.navigation }/> ); }; diff --git a/src/components/pages/view-post.js b/src/components/pages/view-post.js index 481ba1b..2a47812 100644 --- a/src/components/pages/view-post.js +++ b/src/components/pages/view-post.js @@ -1,23 +1,25 @@ -import React from "react"; +import React, { useState, useEffect } from "react"; -import { ScreenWithFullNavigationJsx } from "src/components/navigation/navigators"; -import { PostByIdJsx } from "src/components/posts/post"; +import { ScreenWithBackBarJsx } from "src/components/navigation/navigators"; +import { PostByDataJsx } from "src/components/posts/post"; const ViewPostJsx = ({navigation}) => { - const id = navigation.getParam("id", undefined); + const [state, setState] = useState({ + post: navigation.getParam("post", null), + loaded: false, + }); - if (id == undefined) { - throw Error("ID not specified when navigating to ViewPost!"); + if (state.post == null) { + throw Error("Post not given when navigating to ViewPost!"); } return ( - - + - + data = { state.post } /> + ); } diff --git a/src/components/posts/grid-post.js b/src/components/posts/grid-post.js deleted file mode 100644 index 4b5b4c6..0000000 --- a/src/components/posts/grid-post.js +++ /dev/null @@ -1,23 +0,0 @@ -import React, { useEffect, useState } from "react"; -import { Image, Dimensions, TouchableWithoutFeedback } from "react-native"; - -const GridPostJsx = (props) => { - return ( - props.openPostCallback(props.id)}> - - - ) -} - -const screen_width = Dimensions.get("window").width; -const styles = { - gridImage: { - width: screen_width / 3, - height: screen_width / 3 - } -}; - -export default GridPostJsx; \ No newline at end of file diff --git a/src/components/posts/grid-view.js b/src/components/posts/grid-view.js index 9675866..26f4fdf 100644 --- a/src/components/posts/grid-view.js +++ b/src/components/posts/grid-view.js @@ -3,10 +3,9 @@ import { View, Dimensions, Image, + TouchableOpacity, } from "react-native"; -import GridPostJsx from "src/components/posts/grid-post"; - function partition(arr, size) { let newArray = []; for (let i = 0; i < arr.length; i += size) { @@ -17,6 +16,23 @@ function partition(arr, size) { return newArray } +const GridPostJsx = (props) => { + return ( + { + props.navigation.navigate("ViewPost", { + post: props.data, + }); + }}> + + + ) +} + const GridViewJsx = (props) => { let rows = partition(props.posts, 3); return ( @@ -28,19 +44,11 @@ const GridViewJsx = (props) => { key = { i }> { row.map((post) => { - const post_url = post - .media_attachments[0] - .preview_url; - return ( props.openPostCallback(id) - } - /> + navigation = { props.navigation } + data = { post } /> ); }) @@ -59,7 +67,11 @@ const styles = { padding: 0, margin: 0, flexDirection: "row" - } + }, + gridImage: { + width: screen_width / 3, + height: screen_width / 3 + }, }; export default GridViewJsx; diff --git a/src/components/posts/post.js b/src/components/posts/post.js index ad693b2..2b91a1c 100644 --- a/src/components/posts/post.js +++ b/src/components/posts/post.js @@ -171,56 +171,6 @@ export const PostByDataJsx = (props) => { ); } -export const PostByIdJsx = (props) => { - /* - Renders a post given the post's ID in the properties, as is done when - retrieving an individual post on someone's profile. - */ - let [state, setState] = useState({ - avatar: "", - username: "", - media_attachments: [], - favourited: false, - reblogged: false, - content: "", - timestamp: 0, - loaded: false, - dimensions: [] - }); - - useEffect(() => { - // TODO: Make API request using props.id, set it as the state - (() => { - Promise.all(getDimensionsPromises([{ url: TEST_IMAGE }])) - .then(dimensions => { - setState({ - avatar: TEST_IMAGE, - username: "njms", - media_attachments: [{ url: TEST_IMAGE }], - favourited: false, - reblogged: false, - content: "Also learning Claire de Lune feels a lot like reading the communist manifesto", - timestamp: 1596745156000, - loaded: true, - dimensions: dimensions - }); - }); - })(); - }, []); - - return ( - - { state.loaded ? - - : - } - - ) -} - const styles = { postHeader: { display: "flex",