@ -2,7 +2,7 @@ import React, { Component } from 'react'
import { Container , Table , Button , Icon } from 'semantic-ui-react'
import { Container , Table , Button , Icon } from 'semantic-ui-react'
import toastr from 'toastr'
import toastr from 'toastr'
import Moment from 'react-moment' ;
import Moment from 'react-moment' ;
import util from '../util/util'
export default class RecentComponent extends Component {
export default class RecentComponent extends Component {
state = {
state = {
recent : null
recent : null
@ -28,11 +28,8 @@ export default class RecentComponent extends Component {
this . props . history . push ( ` /visitors/ ${ id } ` )
this . props . history . push ( ` /visitors/ ${ id } ` )
}
}
onEntryDeletion ( visit ) {
onEntryDeletion ( entry ) {
fetch ( visit . DeletionURL )
util . deleteEntry ( entry . DeletionURL )
. then ( res => res . ok ? res . json ( ) : Promise . reject ( res . json ( ) ) )
. then ( ( ) => this . loadRecentURLs ( ) )
. catch ( e => e instanceof Promise ? e . then ( error => toastr . error ( ` Could not delete: ${ error . error } ` ) ) : null )
}
}
render ( ) {
render ( ) {
@ -53,7 +50,7 @@ export default class RecentComponent extends Component {
{ recent && Object . keys ( recent ) . map ( key => < Table . Row key = { key } title = "Click to view visitor statistics" >
{ recent && Object . keys ( recent ) . map ( key => < Table . Row key = { key } title = "Click to view visitor statistics" >
< Table . Cell onClick = { this . onRowClick . bind ( this , key ) } > { recent [ key ] . Public . URL } < / T a b l e . C e l l >
< Table . Cell onClick = { this . onRowClick . bind ( this , key ) } > { recent [ key ] . Public . URL } < / T a b l e . C e l l >
< Table . Cell onClick = { this . onRowClick . bind ( this , key ) } > < Moment > { recent [ key ] . Public . CreatedOn } < / M o m e n t > < / T a b l e . C e l l >
< Table . Cell onClick = { this . onRowClick . bind ( this , key ) } > < Moment > { recent [ key ] . Public . CreatedOn } < / M o m e n t > < / T a b l e . C e l l >
< Table . Cell onClick = { this . onRowClick . bind ( this , key ) } > { ` ${ window . location . origin } / ${ key } ` } < / T a b l e . C e l l >
< Table . Cell > { ` ${ window . location . origin } / ${ key } ` } < / T a b l e . C e l l >
< Table . Cell onClick = { this . onRowClick . bind ( this , key ) } > { recent [ key ] . Public . VisitCount } < / T a b l e . C e l l >
< Table . Cell onClick = { this . onRowClick . bind ( this , key ) } > { recent [ key ] . Public . VisitCount } < / T a b l e . C e l l >
< Table . Cell > < Button animated = 'vertical' onClick = { this . onEntryDeletion . bind ( this , recent [ key ] ) } >
< Table . Cell > < Button animated = 'vertical' onClick = { this . onEntryDeletion . bind ( this , recent [ key ] ) } >
< Button . Content hidden > Delete < / B u t t o n . C o n t e n t >
< Button . Content hidden > Delete < / B u t t o n . C o n t e n t >