From 63a9a5d7d96b1eb13a1782e47c614524348e4eaf Mon Sep 17 00:00:00 2001 From: Marquis Kurt Date: Wed, 24 Apr 2019 14:29:33 -0400 Subject: [PATCH 1/5] Check that posts's length is greater than 0 before running (fix #13) --- src/pages/ProfilePage.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/pages/ProfilePage.tsx b/src/pages/ProfilePage.tsx index 50f5a7e..7b777e3 100644 --- a/src/pages/ProfilePage.tsx +++ b/src/pages/ProfilePage.tsx @@ -122,7 +122,7 @@ class ProfilePage extends Component { loadMoreTimelinePieces() { const { match: {params}} = this.props; this.setState({ viewDidLoad: false, viewIsLoading: true}) - if (this.state.posts) { + if (this.state.posts && this.state.posts.length > 0) { this.client.get(`/accounts/${params.profileId}/statuses`, { max_id: this.state.posts[this.state.posts.length - 1].id, limit: 20 }).then((resp: any) => { let newPosts: [Status] = resp.data; let posts = this.state.posts as [Status]; @@ -150,9 +150,11 @@ class ProfilePage extends Component { variant: 'error', }); }) + } else { + this.props.enqueueSnackbar("Reached end of posts", { variant: 'error'} ); } - } - + } + toggleFollow() { if (this.state.relationship) { if (this.state.relationship.following) { From 80f0bac51ba97963463f2df4710c7dc2bd6808dc Mon Sep 17 00:00:00 2001 From: Marquis Kurt Date: Wed, 24 Apr 2019 16:35:08 -0400 Subject: [PATCH 2/5] Make a LinkableAvatar and link avatar to profile (reblogged or not) (fixes #17) --- src/components/Post/Post.tsx | 6 +++--- src/interfaces/overrides.tsx | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/components/Post/Post.tsx b/src/components/Post/Post.tsx index 9467cd0..1e182d1 100644 --- a/src/components/Post/Post.tsx +++ b/src/components/Post/Post.tsx @@ -21,11 +21,11 @@ import { Visibility } from '../../types/Visibility'; import moment from 'moment'; import AttachmentComponent from '../Attachment'; import Mastodon from 'megalodon'; -import { LinkableChip, LinkableMenuItem, LinkableIconButton } from '../../interfaces/overrides'; +import { LinkableChip, LinkableMenuItem, LinkableIconButton, LinkableAvatar } from '../../interfaces/overrides'; import {withSnackbar} from 'notistack'; import ShareMenu from './PostShareMenu'; import {emojifyString} from '../../utilities/emojis'; -import { PollOption, Poll } from '../../types/Poll'; +import { PollOption } from '../../types/Poll'; interface IPostProps { post: Status; @@ -445,7 +445,7 @@ export class Post extends React.Component { } action={ diff --git a/src/interfaces/overrides.tsx b/src/interfaces/overrides.tsx index 0871fe5..e06d7cc 100644 --- a/src/interfaces/overrides.tsx +++ b/src/interfaces/overrides.tsx @@ -7,6 +7,7 @@ import { MenuItemProps } from '@material-ui/core/MenuItem'; import { MenuItem } from '@material-ui/core'; import Button, { ButtonProps } from '@material-ui/core/Button'; import Fab, { FabProps } from '@material-ui/core/Fab'; +import Avatar, { AvatarProps } from '@material-ui/core/Avatar'; import { userLoggedIn } from '../utilities/accounts'; export interface ILinkableListItemProps extends ListItemProps { @@ -39,6 +40,11 @@ export interface ILinkableFabProps extends FabProps { replace?: boolean; } +export interface ILinkableAvatarProps extends AvatarProps { + to: string; + replace?: boolean; +} + export const LinkableListItem = (props: ILinkableListItemProps) => ( ) @@ -62,6 +68,9 @@ export const LinkableButton = (props: ILinkableButtonProps) => ( export const LinkableFab = (props: ILinkableFabProps) => ( ) +export const LinkableAvatar = (props: ILinkableAvatarProps) => ( + +) export const ProfileRoute = (rest: any, component: Component) => ( ( From 5ae9f688e748ab7b51a42018077ed017f1b4535a Mon Sep 17 00:00:00 2001 From: Marquis Kurt Date: Wed, 24 Apr 2019 16:49:22 -0400 Subject: [PATCH 3/5] Add linkable avatar and add 'view profile' button as action (fixes #15) --- src/pages/Notifications.tsx | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/pages/Notifications.tsx b/src/pages/Notifications.tsx index 5424288..74958e2 100644 --- a/src/pages/Notifications.tsx +++ b/src/pages/Notifications.tsx @@ -20,11 +20,12 @@ import { DialogActions, Tooltip } from '@material-ui/core'; +import AssignmentIndIcon from '@material-ui/icons/AssignmentInd'; import PersonIcon from '@material-ui/icons/Person'; import PersonAddIcon from '@material-ui/icons/PersonAdd'; import DeleteIcon from '@material-ui/icons/Delete'; import {styles} from './PageLayout.styles'; -import {LinkableIconButton} from '../interfaces/overrides'; +import { LinkableIconButton, LinkableAvatar } from '../interfaces/overrides'; import ForumIcon from '@material-ui/icons/Forum'; import Mastodon from 'megalodon'; import { Notification } from '../types/Notification'; @@ -147,9 +148,9 @@ class NotificationsPage extends Component { return ( - + - + @@ -164,11 +165,18 @@ class NotificationsPage extends Component { { notif.type === "follow"? - - this.followMember(notif.account)}> - - - : + + + + + + + + this.followMember(notif.account)}> + + + + : notif.status? From 4db838590d564eb4872c74735e360ac632c36bb1 Mon Sep 17 00:00:00 2001 From: Marquis Kurt Date: Wed, 24 Apr 2019 17:12:08 -0400 Subject: [PATCH 4/5] Make all avatars clickable and change profile button to new icon --- src/pages/About.tsx | 13 +++++++------ src/pages/Messages.tsx | 6 +++--- src/pages/Recommendations.tsx | 17 +++++++++-------- src/pages/Search.tsx | 33 +++++++++++++++++++++++++++------ 4 files changed, 46 insertions(+), 23 deletions(-) diff --git a/src/pages/About.tsx b/src/pages/About.tsx index 4c7a63b..5a0dddd 100644 --- a/src/pages/About.tsx +++ b/src/pages/About.tsx @@ -18,6 +18,7 @@ import OpenInNewIcon from '@material-ui/icons/OpenInNew'; import DomainIcon from '@material-ui/icons/Domain'; import ChatIcon from '@material-ui/icons/Chat'; import PersonIcon from '@material-ui/icons/Person'; +import AssignmentIndIcon from '@material-ui/icons/AssignmentInd'; import NetworkCheckIcon from '@material-ui/icons/NetworkCheck'; import UpdateIcon from '@material-ui/icons/Update'; import InfoIcon from '@material-ui/icons/Info'; @@ -25,7 +26,7 @@ import NotesIcon from '@material-ui/icons/Notes'; import CodeIcon from '@material-ui/icons/Code'; import {styles} from './PageLayout.styles'; import {Instance} from '../types/Instance'; -import {LinkableIconButton} from '../interfaces/overrides'; +import {LinkableIconButton, LinkableAvatar} from '../interfaces/overrides'; import Mastodon from 'megalodon'; import { UAccount } from '../types/Account'; import { getConfig } from '../utilities/settings'; @@ -114,7 +115,7 @@ class AboutPage extends Component { - + { - + @@ -193,9 +194,9 @@ class AboutPage extends Component { - + - + @@ -206,7 +207,7 @@ class AboutPage extends Component { - + diff --git a/src/pages/Messages.tsx b/src/pages/Messages.tsx index c4d774b..dc2ffa3 100644 --- a/src/pages/Messages.tsx +++ b/src/pages/Messages.tsx @@ -5,7 +5,7 @@ import ForumIcon from '@material-ui/icons/Forum'; import {styles} from './PageLayout.styles'; import Mastodon from 'megalodon'; import { Status } from '../types/Status'; -import { LinkableIconButton } from '../interfaces/overrides'; +import { LinkableIconButton, LinkableAvatar } from '../interfaces/overrides'; interface IMessagesState { posts?: [Status]; @@ -73,9 +73,9 @@ class MessagesPage extends Component { return ( - + - + diff --git a/src/pages/Recommendations.tsx b/src/pages/Recommendations.tsx index 650671b..9eb8dc8 100644 --- a/src/pages/Recommendations.tsx +++ b/src/pages/Recommendations.tsx @@ -3,8 +3,9 @@ import {withStyles, Typography, List, ListItem, Paper, ListItemText, Avatar, Lis import {styles} from './PageLayout.styles'; import Mastodon from 'megalodon'; import {Account} from '../types/Account'; -import { LinkableIconButton } from '../interfaces/overrides'; +import { LinkableIconButton, LinkableAvatar } from '../interfaces/overrides'; import AccountCircleIcon from '@material-ui/icons/AccountCircle'; +import AssignmentIndIcon from '@material-ui/icons/AssignmentInd'; import PersonAddIcon from '@material-ui/icons/PersonAdd'; import CheckIcon from '@material-ui/icons/Check'; import CloseIcon from '@material-ui/icons/Close'; @@ -120,7 +121,7 @@ class RecommendationsPage extends Component - + @@ -164,20 +165,20 @@ class RecommendationsPage extends Component - + + + + + + this.followMember(suggestion)}> - - - - - ); diff --git a/src/pages/Search.tsx b/src/pages/Search.tsx index 9690c2b..d6708db 100644 --- a/src/pages/Search.tsx +++ b/src/pages/Search.tsx @@ -10,11 +10,15 @@ import { Paper, withStyles, Typography, - CircularProgress + CircularProgress, + Tooltip, + IconButton } from '@material-ui/core'; import PersonIcon from '@material-ui/icons/Person'; +import AssignmentIndIcon from '@material-ui/icons/AssignmentInd'; +import PersonAddIcon from '@material-ui/icons/PersonAdd'; import {styles} from './PageLayout.styles'; -import {LinkableIconButton} from '../interfaces/overrides'; +import {LinkableIconButton, LinkableAvatar} from '../interfaces/overrides'; import Mastodon from 'megalodon'; import {parse as parseParams, ParsedQuery} from 'query-string'; import { Results } from '../types/Search'; @@ -145,6 +149,16 @@ class SearchPage extends Component { }); } + followMemberFromQuery(acct: Account) { + let client = new Mastodon(localStorage.getItem('access_token') as string, localStorage.getItem('baseurl') + "/api/v1"); + client.post(`/accounts/${acct.id}/follow`).then((resp: any) => { + this.props.enqueueSnackbar('You are now following this account.'); + }).catch((err: Error) => { + this.props.enqueueSnackbar("Couldn't follow account: " + err.name, { variant: 'error' }); + console.error(err.message); + }) + } + showAllAccountsFromQuery() { const { classes } = this.props; return ( @@ -158,13 +172,20 @@ class SearchPage extends Component { return ( - + - - - + + + + + + + this.followMemberFromQuery(acct)}> + + + ); From 1c663dc079d276295b527c48f061bf36978639c6 Mon Sep 17 00:00:00 2001 From: Marquis Kurt Date: Thu, 25 Apr 2019 18:28:30 -0400 Subject: [PATCH 5/5] Add setState to else clause --- src/pages/ProfilePage.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/pages/ProfilePage.tsx b/src/pages/ProfilePage.tsx index 7b777e3..11c1272 100644 --- a/src/pages/ProfilePage.tsx +++ b/src/pages/ProfilePage.tsx @@ -152,6 +152,10 @@ class ProfilePage extends Component { }) } else { this.props.enqueueSnackbar("Reached end of posts", { variant: 'error'} ); + this.setState({ + viewIsLoading: false, + viewDidLoad: true + }) } }