diff --git a/src/components/pages/profile.js b/src/components/pages/profile.js index 5854c73..a671a8f 100644 --- a/src/components/pages/profile.js +++ b/src/components/pages/profile.js @@ -149,19 +149,22 @@ const ProfileDisplayJsx = ({navigation}) => { inactive: require("assets/eva-icons/bell-black.png") } - useEffect(async () => { - const profile = JSON.parse(await AsyncStorage.getItem("@user_profile")); - const notifications = JSON.parse( - await AsyncStorage.getItem("@user_notifications") - ); + useEffect(() => { + AsyncStorage.multiGet(["@user_profile", "@user_notifications"]) + .then(values => { + const [profileJSON, notificationsJSON] = values; - setState({ - profile: profile, - unreadNotifications: notifications.unread, - mutuals: getMutuals(TEST_YOUR_FOLLOWERS, TEST_THEIR_FOLLOWERS), - own: true, - loaded: true, - }); + const profile = JSON.parse(profileJSON[1]); + const notifications = JSON.parse(notificationsJSON[1]); + console.log(notifications); + setState({ + profile: profile, + unreadNotifications: notifications.unread, + mutuals: getMutuals(TEST_YOUR_FOLLOWERS, TEST_THEIR_FOLLOWERS), + own: true, + loaded: true, + }); + }); }, []); let profileButton; @@ -209,7 +212,12 @@ const ProfileDisplayJsx = ({navigation}) => { { state.own ? - + { + navigation.navigate("Notifications"); + } + }> { + nav.navigate("ViewProfile", { + acct: acct, + }); + }; +} + +function navigatePostFactory(nav, id) { + return () => { + nav.navigate("ViewPost", { + originTab: "Profile", + id: id, + }); + } +} + +function renderNotification(notif, navigation) { + switch(notif.type) { + case "follow": + return + case "follow_request": + return + case "mention": + return + case "reblog": + return + case "favourite": + return + case "status": + return + default: + // We're not expecting polls to be super popular on Pixelfed + return <> + } +} + +const UserTextJsx = (props) => { + return ( + { + props.navigation.navigate("ViewProfile", { + acct: props.acct + }); + } + }> + { props.acct }  + + ); +}; + +const NotificationJsx = (props) => { + return ( + + + + + + + + { props.children } + + { props.button ? + + + { props.buttonLabel } + + + : <> + } + + ); +}; + +const FollowJsx = (props) => { + return ( + + + + has followed you. + + + ); +}; + +const FollowRequestJsx = (props) => { + return ( + console.log("Request accepted") }> + + + has requested to follow you. + + + ); +}; + +const MentionJsx = (props) => { + let uri; + let imageStyle; + let thumbnailCallback; + + if (props.data.status.media_attachments.length > 0) { + // If it's a comment... + uri = props.data.status.media_attachments[0].url; + imageStyle = {}; + thumbnailCallback = navigatePostFactory( + props.navigation, + props.data.status.id + ); + } else { + // If it's a reply to your comment... + uri = props.data.account.avatar; + imageStyle = styles.notif.circularThumbnail; + thumbnailCallback = navigateProfileFactory( + props.navigation, + props.data.account.acct + ); + } + + return ( + + + + mentioned you: + + "{ props.data.status.content }" + + + + ); +}; + +const ReblogJsx = (props) => { + return ( + + + + + shared your post. + + + ); +}; + +const FavouriteJsx = (props) => { + return ( + + + + + liked your post. + + + ); +}; + +const StatusJsx = (props) => { + return ( + + + + just posted. + + + ); +}; const NotificationsJsx = ({navigation}) => { + const [state, setState] = useState({ + loaded: false, + }); + + useEffect(() => { + const read = JSON.stringify({ + unread: false, + memory: [ + { id: 1 }, + { id: 2 }, + { id: 3 }, + ] + }); + + AsyncStorage.mergeItem("@user_notifications", read) + .then(() => { + setState({...state, + notifications: TEST_NOTIFICATIONS, + loaded: true + }) + }); + + }, []); + return ( - - - + + { state.loaded ? + + { + state.notifications.map(notif => + renderNotification(notif, navigation) + ) + } + + : <> + } + ); } -export default NotificationsJsx; \ No newline at end of file +const SCREEN_WIDTH = Dimensions.get("window").width; + +const styles = { + notif: { + container: { + flexDirection: "row", + alignItems: "center", + paddingLeft: 20, + marginTop: 10, + marginBottom: 10, + }, + + circularThumbnail: { borderRadius: SCREEN_WIDTH / 16 }, + thumbnailContainer: { + marginRight: 10, + }, + thumbnail: { + width: SCREEN_WIDTH / 8, + height: SCREEN_WIDTH / 8, + }, + + contentContainer: { + flexShrink: 1, + flexDirection: "row", + alignItems: "center", + }, + inlineIcon: { + width: 20, + height: 20, + marginRight: 10, + }, + status: { fontStyle: "italic" }, + + buttonContainer: { + marginLeft: "auto", + marginRight: 10, + }, + button: { + borderWidth: 1, + borderColor: "#888", + borderRadius: 10, + padding: 10, + }, + }, + bold: { fontWeight: "bold" }, +}; + +export default NotificationsJsx; diff --git a/src/components/pages/view-post.js b/src/components/pages/view-post.js index 5cc87ce..481ba1b 100644 --- a/src/components/pages/view-post.js +++ b/src/components/pages/view-post.js @@ -3,14 +3,20 @@ import React from "react"; import { ScreenWithFullNavigationJsx } from "src/components/navigation/navigators"; import { PostByIdJsx } from "src/components/posts/post"; -const ViewPostJsx = (props) => { +const ViewPostJsx = ({navigation}) => { + const id = navigation.getParam("id", undefined); + + if (id == undefined) { + throw Error("ID not specified when navigating to ViewPost!"); + } + return ( + active = { navigation.getParam("originTab", "Timeline") } + navigation = { navigation }> + navigation = { navigation } + id = { id } /> ); } diff --git a/src/requests.js b/src/requests.js index 64c075d..9e8349a 100644 --- a/src/requests.js +++ b/src/requests.js @@ -17,9 +17,6 @@ export async function checkUnreadNotifications() { const isUnread = JSON.stringify(newNotifs) != JSON.stringify(notifications.memory); - console.log(JSON.stringify(newNotifs)); - console.log(JSON.stringify(notifications.memory)); - // Update stored notifications await AsyncStorage.setItem( "@user_notifications",