diff --git a/src/App.js b/src/App.js index acf9193..30a8ba6 100644 --- a/src/App.js +++ b/src/App.js @@ -25,7 +25,6 @@ import Search from 'src/components/pages/discover/search'; import ViewHashtag from 'src/components/pages/discover/view-hashtag'; import Direct from "src/components/pages/direct"; import Conversation, { Compose } from "src/components/pages/direct/conversation"; -import Notifications from 'src/components/pages/profile/notifications'; import UserList from "src/components/pages/user-list.js"; import Settings from "src/components/pages/profile/settings.js"; diff --git a/src/components/pages/authenticate.js b/src/components/pages/authenticate.js index e80db5c..5096036 100644 --- a/src/components/pages/authenticate.js +++ b/src/components/pages/authenticate.js @@ -125,16 +125,7 @@ const Authenticate = ({navigation}) => { token.access_token ).then(resp => resp.json()); - await AsyncStorage.multiSet([ - [ "@user_profile", JSON.stringify(profile), ], - [ // TODO: Enable storing notifications - "@user_notifications", - JSON.stringify({ - unread: false, - memory: [] - }), - ], - ]); + await AsyncStorage.setItem("@user_profile", JSON.stringify(profile)); navigation.replace("Main"); }; diff --git a/src/components/pages/profile.js b/src/components/pages/profile.js index 1090d46..fe217f0 100644 --- a/src/components/pages/profile.js +++ b/src/components/pages/profile.js @@ -191,18 +191,15 @@ const Profile = ({ navigation }) => { const init = async () => { const [ profilePair, - notifPair, instancePair, tokenPair ] = await AsyncStorage.multiGet([ "@user_profile", - "@user_notifications", "@user_instance", "@user_token", ]); const profile = JSON.parse(profilePair[1]); - const notifs = JSON.parse(notifPair[1]); const instance = instancePair[1]; const accessToken = JSON.parse(tokenPair[1]).access_token; @@ -225,7 +222,6 @@ const Profile = ({ navigation }) => { setState({...state, profile: latestProfile, - notifs: notifs, posts: posts, listedUsers: followers, loaded: true, @@ -244,8 +240,7 @@ const Profile = ({ navigation }) => { own = { true } profile = { state.profile } posts = { state.posts } - listedUsers = { state.listedUsers } - notifs = { state.notifs }/> + listedUsers = { state.listedUsers }/> : <> } diff --git a/src/components/pages/profile/notifications.js b/src/components/pages/profile/notifications.js deleted file mode 100644 index c9fbecc..0000000 --- a/src/components/pages/profile/notifications.js +++ /dev/null @@ -1,440 +0,0 @@ -import React, { useState, useEffect } from "react"; - -import { - Dimensions, - View, - TouchableOpacity, - Image, - Text, -} from "react-native"; -import { FontAwesome } from "@expo/vector-icons"; - -import AsyncStorage from "@react-native-async-storage/async-storage"; - -const TEST_IMAGE = "https://cache.desktopnexus.com/thumbseg/2255/2255124-bigthumbnail.jpg"; -const TEST_NOTIFICATIONS = [ - { - id: 1, - type: "follow", - account: { - acct: "njms", - avatar: TEST_IMAGE, - }, - }, - { - id: 2, - type: "follow_request", - account: { - acct: "njms", - avatar: TEST_IMAGE, - }, - }, - { - id: 3, - type: "mention", - account: { - acct: "njms", - avatar: TEST_IMAGE, - }, - status: { - id: 1, - media_attachments: [], - content: "This is a message", - } - }, - { - id: 4, - type: "mention", - account: { - acct: "njms", - avatar: TEST_IMAGE, - }, - status: { - id: 1, - media_attachments: [ - { url: TEST_IMAGE } - ], - content: "This is a message", - } - }, - { - id: 5, - type: "mention", - account: { - acct: "njms", - avatar: TEST_IMAGE, - }, - status: { - id: 1, - media_attachments: [ - { url: TEST_IMAGE } - ], - content: "This is a really really really really really really" - + " really really really really really really long message", - } - }, - { - id: 6, - type: "reblog", - account: { - acct: "njms", - avatar: TEST_IMAGE, - }, - status: { - id: 1, - media_attachments: [ - { url: TEST_IMAGE } - ], - } - }, - { - id: 7, - type: "favourite", - account: { - acct: "njms", - avatar: TEST_IMAGE, - }, - status: { - id: 1, - media_attachments: [ - { url: TEST_IMAGE } - ], - } - }, - { - id: 8, - type: "status", - account: { - acct: "njms", - avatar: TEST_IMAGE, - }, - status: { - id: 1, - media_attachments: [ - { url: TEST_IMAGE } - ], - } - }, -] - -function navigateProfileFactory(nav, acct) { - return () => { - 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 UserText = (props) => { - return ( - { - props.navigation.navigate("ViewProfile", { - acct: props.acct - }); - } - }> - { props.acct }  - - ); -}; - -const Notification = (props) => { - return ( - - - - - - - - { props.children } - - { props.button ? - - - { props.buttonLabel } - - - : <> - } - - ); -}; - -const Follow = (props) => { - return ( - - - - has followed you. - - - ); -}; - -const FollowRequest = (props) => { - return ( - console.log("Request accepted") }> - - - has requested to follow you. - - - ); -}; - -const Mention = (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 Reblog = (props) => { - return ( - - - - - shared your post. - - - ); -}; - -const Favourite = (props) => { - return ( - - - - - liked your post. - - - ); -}; - -const Status = (props) => { - return ( - - - - just posted. - - - ); -}; - -const Notifications = ({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 ( - <> - navigation = { navigation }> - { state.loaded ? - - { - state.notifications.map(notif => - renderNotification(notif, navigation) - ) - } - - : <> - } - - ); -} - -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: { - marginRight: 10, - }, - status: { fontStyle: "italic" }, - - buttonContainer: { - marginLeft: "auto", - marginRight: 10, - }, - button: { - borderWidth: 1, - borderColor: "#888", - borderRadius: 10, - padding: 10, - }, - }, - bold: { fontWeight: "bold" }, -}; - -export default Notifications; diff --git a/src/components/pages/profile/settings.js b/src/components/pages/profile/settings.js index 667f8a9..028d112 100644 --- a/src/components/pages/profile/settings.js +++ b/src/components/pages/profile/settings.js @@ -37,7 +37,6 @@ const Settings = (props) => { await AsyncStorage.multiRemove([ "@user_profile", - "@user_notifications", "@user_instance", "@user_token", ]); diff --git a/src/requests.js b/src/requests.js index 352ee0e..16d9461 100644 --- a/src/requests.js +++ b/src/requests.js @@ -1,9 +1,5 @@ import AsyncStorage from "@react-native-async-storage/async-storage"; -const TEST_NOTIFICATIONS = [{ id: 1 }, { id: 2 }]; -const TEST_NEW_NOTIFICATIONS_1 = [{ id: 1 }, { id: 2 }]; -const TEST_NEW_NOTIFICATIONS_2 = [{ id: 1 }, { id: 2 }, { id: 3 }]; - export function objectToForm(obj) { let form = new FormData(); @@ -14,31 +10,6 @@ export function objectToForm(obj) { return form; } -export async function checkUnreadNotifications() { - // If the check has already been made since the last time notifications.js - // has been opened - const notifications = JSON.parse(await AsyncStorage.getItem("@user_notifications")); - - if (notifications.unread) { - return true; - } else { - // Some promise to get new notifications - const newNotifs = await Promise.resolve(TEST_NEW_NOTIFICATIONS_2); - - const isUnread = JSON.stringify(newNotifs) != JSON.stringify(notifications.memory); - - // Update stored notifications - await AsyncStorage.setItem( - "@user_notifications", - JSON.stringify({...notifications, - unread: isUnread, - }) - ); - - return isUnread; - } -} - export async function postForm(url, data = false, token = false, contentType = false) { // Send a POST request with data formatted with FormData returning JSON let headers = {};