activitypub-academy/app/javascript/mastodon/features/activity_log/index.js

69 lines
1.6 KiB
JavaScript
Raw Normal View History

2022-12-20 04:23:04 +09:00
import React from 'react';
2022-12-24 01:24:28 +09:00
import PropTypes from 'prop-types';
import Column from 'mastodon/components/column';
import ColumnHeader from 'mastodon/components/column_header';
2023-01-02 23:34:54 +09:00
import dummy_data from './dummy-data.json';
2022-12-24 01:24:28 +09:00
import ColumnSettings from './components/column_settings';
2022-11-22 00:30:53 +09:00
2022-12-20 04:23:04 +09:00
import ActivityPubVisualization from 'activity-pub-visualization';
2022-12-24 00:53:57 +09:00
export default class ActivityLog extends React.PureComponent {
2022-11-22 00:30:53 +09:00
2022-11-30 03:10:06 +09:00
state = {
2023-01-02 23:34:54 +09:00
logs: dummy_data,
2022-11-30 03:10:06 +09:00
};
2022-12-24 01:24:28 +09:00
static propTypes = {
multiColumn: PropTypes.bool,
};
2022-12-09 02:27:05 +09:00
2022-11-30 03:10:06 +09:00
componentDidMount() {
this.eventSource = new EventSource('/api/v1/activity_log');
this.eventSource.onmessage = (event) => {
this.setState({ logs: [...this.state.logs, JSON.parse(event.data)] });
};
}
componentWillUnmount() {
if (this.eventSource) {
this.eventSource.close();
}
}
2022-12-24 01:24:28 +09:00
handleHeaderClick = () => {
this.column.scrollTop();
}
clearLog = () => {
this.setState({ logs: [] });
}
2022-11-22 00:30:53 +09:00
render () {
2022-12-22 03:40:05 +09:00
const darkMode = !(document.body && document.body.classList.contains('theme-mastodon-light'));
2022-12-24 01:24:28 +09:00
const { multiColumn } = this.props;
return (
<Column bindToDocument={!multiColumn} ref={this.setRef} label='Activity Log'>
<ColumnHeader
icon='comments'
title='Activity Log'
onClick={this.handleHeaderClick}
multiColumn={multiColumn}
>
<ColumnSettings clearLog={this.clearLog} />
</ColumnHeader>
<div className={`${darkMode ? 'dark' : ''}`}>
<ActivityPubVisualization logs={this.state.logs} />
</div>
</Column>
);
2022-12-09 01:57:22 +09:00
}
2022-12-24 01:24:28 +09:00
2022-12-09 01:57:22 +09:00
}