const logout = (event) => { event.preventDefault() document.cookie = 'x-auth-token= ; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;' delete Axios.defaults.headers.common['x-auth-token'] setAuthUser({ action: LOGOUT_USER, payload: null }) setNotification({ action: ADD_NOTI, data: { id: genId(), type: 'success', message: 'Logged out successully.', color: 'green' } }) return <Redirect to='/' /> }
// Search user const searchUser = async (event) => { if (!event.target.value) { setSearch([]) return null } try { const resp = await Axios.get(`${BASE_URL}/user/search/${event.target.value}/0`) setSearch(resp.data) } catch (err) { setNotification({ action: ADD_NOTI, data: { id: genId(), message: 'Could not search for user. Please try again later', type: 'error', color: 'red' } }) } }
// Follow user const unFollowUser = async () => { try { const resp = await Axios({ method: 'DELETE', url: `${BASE_URL}/user/unfollow/${isFollowing}` }) unFollow(resp.data) } catch (err) { setNotification({ action: ADD_NOTI, data: { id: genId(), message: 'Couldnot unfollow user. Please try again later', type: 'error', color: 'red' } }) } }
action: ADD_NOTI, data: { id: genId(), message: 'There was an error while loading your followers. Please try again later', type: 'error',
// Delete post const deletePost = async () => { try { setDeleting(true) const resp = await deleteImages(posts.posts.contents[postId].images) if (!resp) throw new Error('Failed to delete images') await Axios.delete(`${BASE_URL}/post/${postId}`) setPost({ action: DELETE_POST, data: { postId: postId } }) console.log('hello') } catch (err) { setNotification({ action: ADD_NOTI, data: { id: genId(), message: 'Could not delete post. Try again later', type: 'error', color: 'red' } }) } }
action: ADD_NOTI, data: { id: genId(), message: 'Could not upload picture. Please try again later', type: 'error',
action: ADD_NOTI, data: { id: genId(), message: 'Could not unlike the post. Try again later', type: 'error',
action: ADD_NOTI, data: { id: genId(), message: err.response.data.message, type: 'error',
// To load user posts const getPosts = async (userId, current) => { try { const result = await Axios({ method: 'POST', url: `${BASE_URL}/post/${userId}`, headers: { 'Content-Type': 'application/json' }, data: { current: current } }) if (!result.data.posts.ids.length) return setLoadMore(false) setPost({ action: SET_POSTS, data: result.data }) } catch (err) { setNotification({ action: ADD_NOTI, data: { id: genId(), message: 'There was an error while loading posts. Please try again later', type: 'error', color: 'red' } }) } }
action: ADD_NOTI, data: { id: genId(), message: 'There was an error while loading posts. Please try again later', type: 'error',
action: ADD_NOTI, data: { id: genId(), message: 'Could not like the post. Try again later', type: 'error',
action: ADD_NOTI, data: { id: genId(), message: 'Could not load comments. Please try again later', type: 'error',
// Follow user const followUser = async () => { try { const resp = await Axios({ method: 'POST', url: `${BASE_URL}/user/follow`, headers: { 'Content-Type': 'application/json' }, data: { followedUser: userId } }) follow(resp.data) } catch (err) { setNotification({ action: ADD_NOTI, data: { id: genId(), message: 'Couldnot follow user. Please try again later', type: 'error', color: 'red' } }) } }
action: ADD_NOTI, data: { id: genId(), message: 'There was an error while loading people you follow. Please try again later', type: 'error',