2023-01-16 03:58:48 +09:00
import React from 'react' ;
import { connect } from 'react-redux' ;
import ImmutablePureComponent from 'react-immutable-pure-component' ;
2023-01-15 01:19:37 +09:00
import { FormattedMessage } from 'react-intl' ;
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-14 01:57:41 +09:00
import { HotKeys } from 'react-hotkeys' ;
2023-01-26 06:50:16 +09:00
import { setExplorerData } from 'mastodon/actions/activitypub_explorer' ;
2023-01-15 01:19:37 +09:00
import DismissableBanner from 'mastodon/components/dismissable_banner' ;
2023-01-02 23:34:54 +09:00
2023-01-26 05:34:01 +09:00
import { ActivityPubVisualization } from 'activitypub-visualization' ;
2022-12-24 01:24:28 +09:00
2023-01-16 03:58:48 +09:00
const mapStateToProps = ( state ) => {
return {
logs : state . getIn ( [ 'activity_log' , 'logs' ] ) ,
} ;
} ;
2022-12-22 03:40:05 +09:00
2023-01-16 03:58:48 +09:00
export default @ connect ( mapStateToProps )
class ActivityLog extends ImmutablePureComponent {
2022-12-24 01:24:28 +09:00
2023-01-26 06:50:16 +09:00
static contextTypes = {
router : PropTypes . object ,
} ;
2023-01-16 03:58:48 +09:00
static propTypes = {
2023-01-26 06:50:16 +09:00
dispatch : PropTypes . func . isRequired ,
2023-01-16 03:58:48 +09:00
multiColumn : PropTypes . bool ,
2023-01-14 01:57:41 +09:00
} ;
2023-01-16 03:58:48 +09:00
handleHeaderClick = ( ) => {
this . column . scrollTop ( ) ;
}
2023-01-03 03:50:03 +09:00
2023-01-16 03:58:48 +09:00
setRef = c => {
this . column = c ;
}
render ( ) {
2023-01-26 06:50:16 +09:00
const { dispatch , logs , multiColumn } = this . props ;
2023-01-16 03:58:48 +09:00
const darkMode = ! ( document . body && document . body . classList . contains ( 'theme-mastodon-light' ) ) ;
// hijack the toggleHidden shortcut to copy the logs to clipbaord
const handlers = {
toggleHidden : ( ) => navigator . clipboard . writeText ( JSON . stringify ( logs , null , 2 ) ) ,
} ;
return (
< Column bindToDocument = { ! multiColumn } ref = { this . setRef } label = 'Activity Log' >
< ColumnHeader
icon = 'comments'
title = 'Activity Log'
onClick = { this . handleHeaderClick }
multiColumn = { multiColumn }
/ >
< DismissableBanner id = 'activity_log' >
< p >
< FormattedMessage
id = 'dismissable_banner.activity_log_information'
defaultMessage = 'When you interact with another instance (for example, follow an account on another instance), the resulting Activities will be shown here. You can find more information on my {blog}.'
values = { {
blog : < a href = '//seb.jambor.dev/' style = { { color : darkMode ? '#8c8dff' : '#3a3bff' , textDecoration : 'none' } } > blog < / a > ,
} }
/ >
< / p >
< p style = { { paddingTop : '5px' } } >
< FormattedMessage
id = 'dismissable_banner.activity_log_clear'
defaultMessage = 'Note: Activities will only be logged while Mastodon is open. When you navigate elsewhere or reload the page, the log will be cleared.'
/ >
< / p >
< / D i s m i s s a b l e B a n n e r >
< HotKeys handlers = { handlers } >
< div className = { ` ${ darkMode ? 'dark' : '' } ` } >
2023-01-26 06:50:16 +09:00
< ActivityPubVisualization logs = { logs } showExplorerLink onExplorerLinkClick = { ( data ) => {
dispatch ( setExplorerData ( data ) ) ;
this . context . router . history . push ( '/activitypub_explorer' ) ;
} } / >
2023-01-16 03:58:48 +09:00
< / d i v >
< / H o t K e y s >
< / C o l u m n >
) ;
}
}