import React, { Component } from "react"; import { withStyles, Typography, CircularProgress, ListSubheader, Link, Paper, List, ListItem, ListItemText, ListItemAvatar, ListItemSecondaryAction, Tooltip, IconButton } from "@material-ui/core"; import { styles } from "./PageLayout.styles"; import { UAccount, Account } from "../types/Account"; import { Tag } from "../types/Tag"; import Mastodon from "megalodon"; import { LinkableAvatar, LinkableIconButton } from "../interfaces/overrides"; import moment from "moment"; import FireplaceIcon from "@material-ui/icons/Fireplace"; import TrendingUpIcon from "@material-ui/icons/TrendingUp"; import SearchIcon from "@material-ui/icons/Search"; import OpenInNewIcon from "@material-ui/icons/OpenInNew"; import AssignmentIndIcon from "@material-ui/icons/AssignmentInd"; interface IActivityPageState { user?: UAccount; trendingTags?: [Tag]; activeProfileDirectory?: [Account]; newProfileDirectory?: [Account]; viewLoading: boolean; viewLoaded?: boolean; viewErrored?: boolean; } class ActivityPage extends Component { client: Mastodon; constructor(props: any) { super(props); this.client = new Mastodon( localStorage.getItem("access_token") as string, localStorage.getItem("baseurl") + "/api/v1" ); this.state = { viewLoading: true }; } componentDidMount() { this.getAccountData(); this.client .get("/trends", { limit: 3 }) .then((resp: any) => { let trendingTags: [Tag] = resp.data; this.setState({ trendingTags }); }) .catch((err: Error) => { this.setState({ viewLoading: false, viewErrored: true }); console.error(err.message); }); this.client .get("/directory", { local: true, order: "active", limit: 5 }) .then((resp: any) => { let profileDirectory: [Account] = resp.data; this.setState({ activeProfileDirectory: profileDirectory }); }) .catch((err: Error) => { this.setState({ viewLoading: false, viewErrored: true }); console.log(err.message); }); this.client .get("/directory", { local: true, order: "new", limit: 5 }) .then((resp: any) => { let profileDirectory: [Account] = resp.data; this.setState({ newProfileDirectory: profileDirectory, viewLoading: false, viewLoaded: true }); }) .catch((err: Error) => { this.setState({ viewLoading: false, viewErrored: true }); console.log(err.message); }); } getAccountData() { this.client .get("/accounts/verify_credentials") .then((resp: any) => { let data: UAccount = resp.data; this.setState({ user: data }); }) .catch((err: Error) => { this.props.enqueueSnackbar( "Couldn't find profile info: " + err.name ); console.error(err.message); let acct = localStorage.getItem("account") as string; this.setState({ user: JSON.parse(acct) }); }); } render() { const { classes } = this.props; return (
Hey there,{" "} {this.state.user ? this.state.user.display_name || this.state.user.acct : "user"} ! Take a look at what's been happening on your instance.
{this.state.viewLoaded ? (
Trending hashtags {this.state.trendingTags && this.state.trendingTags.length > 0 ? ( {this.state.trendingTags.map((tag: Tag) => ( ))} ) : ( It looks like there aren't any trending tags on your instance as of right now. )}
Who's been active {this.state.activeProfileDirectory && this.state.activeProfileDirectory.length > 0 ? ( {this.state.activeProfileDirectory.map( (account: Account) => ( ) )} ) : ( It looks like there aren't any active people in the profile directory yet. )}
New arrivals {this.state.newProfileDirectory && this.state.newProfileDirectory.length > 0 ? ( {this.state.newProfileDirectory.map( (account: Account) => ( ) )} ) : ( It looks like there aren't any new arrivals listed in the profile directory yet. )}
) : null} {this.state.viewErrored ? ( Bummer. Something went wrong when loading instance activity. ) : ( )} {this.state.viewLoading ? (
) : ( )}
Trending hashtags and the profile directory may not appear here if your instance isn't up to date. Check the{" "} about page to see if your instance is running the latest version.
); } } export default withStyles(styles)(ActivityPage);