import React, { useEffect, useState } from 'react'; import { Table, Typography } from 'antd'; import { ColumnsType } from 'antd/lib/table/interface'; import format from 'date-fns/format'; import { FEDERATION_ACTIONS, fetchData } from '../../utils/apis'; import { isEmptyObject } from '../../utils/format'; const { Title, Paragraph } = Typography; export interface Action { iri: string; actorIRI: string; type: string; timestamp: Date; } export default function FediverseActions() { const [actions, setActions] = useState([]); const getActions = async () => { try { const result = await fetchData(FEDERATION_ACTIONS, { auth: true }); if (isEmptyObject(result)) { setActions([]); } else { setActions(result); } } catch (error) { console.log('==== error', error); } }; useEffect(() => { getActions(); }, []); const columns: ColumnsType = [ { title: 'Action', dataIndex: 'type', key: 'type', width: 50, render: (_, record) => { let image; let title; switch (record.type) { case 'FEDIVERSE_ENGAGEMENT_REPOST': image = '/img/repost.svg'; title = 'Share'; break; case 'FEDIVERSE_ENGAGEMENT_LIKE': image = '/img/like.svg'; title = 'Like'; break; case 'FEDIVERSE_ENGAGEMENT_FOLLOW': image = '/img/follow.svg'; title = 'Follow'; break; default: image = ''; } return (
{title}
{title}
); }, }, { title: 'From', dataIndex: 'actorIRI', key: 'from', render: (_, record) => {record.actorIRI}, }, { title: 'When', dataIndex: 'timestamp', key: 'timestamp', render: (_, record) => { const dateObject = new Date(record.timestamp); return format(dateObject, 'P pp'); }, }, ]; function makeTable(data: Action[], tableColumns: ColumnsType) { return ( row.iri} pagination={{ pageSize: 50 }} /> ); } return (
Fediverse Actions Below is a list of actions that were taken by others in response to your posts as well as people who requested to follow you. {makeTable(actions, columns)}
); }