Skip to content

Commit

Permalink
Merge pull request #286 from systemli/remove-prepend-time
Browse files Browse the repository at this point in the history
🔥 Remove prepend time capabilties
  • Loading branch information
0x46616c6b authored May 27, 2022
2 parents 960a99c + 41a9145 commit 7dee7bc
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 51 deletions.
27 changes: 2 additions & 25 deletions src/components/Message.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { render, screen } from '@testing-library/react'
import dayjs from 'dayjs'
import React from 'react'
import Message from './Message'

Expand All @@ -15,33 +14,13 @@ describe('Message', function () {
attachments: [],
geo_information: '{"type":"FeatureCollection","features":[]}',
}
const { asFragment } = render(
<Message message={message} prependTime={false} />
)
const { asFragment } = render(<Message message={message} />)

expect(asFragment()).toMatchSnapshot()

expect(screen.getByText('a few seconds ago')).toBeInTheDocument()
})

test('renders with prepended time', function () {
const time = new Date()
const message = {
id: '1',
text: 'message',
ticker: 1,
creation_date: time,
tweet_id: '',
tweet_user: '',
attachments: [],
geo_information: '{"type":"FeatureCollection","features":[]}',
}

render(<Message message={message} prependTime />)

expect(screen.getByText(dayjs(time).format('HH:mm') + ' message'))
})

test('renders with map correctly', function () {
const message = {
id: '1',
Expand All @@ -54,9 +33,7 @@ describe('Message', function () {
geo_information:
'{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Point","coordinates":[13.466282,52.5024]},"properties":null}]}',
}
const { asFragment } = render(
<Message message={message} prependTime={false} />
)
const { asFragment } = render(<Message message={message} />)

expect(asFragment()).toMatchSnapshot()
})
Expand Down
11 changes: 1 addition & 10 deletions src/components/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const AttachmentsWrapper = styled(Card.Content)`

interface Props {
message: MessageType
prependTime: boolean
}

const Message: FC<Props> = props => {
Expand All @@ -30,20 +29,12 @@ const Message: FC<Props> = props => {
)
const creationDate = dayjs(props.message.creation_date).format('LLLL')

function prependTime() {
if (props.prependTime) {
return dayjs(props.message.creation_date).format('HH:mm') + ' '
}

return ''
}

return (
<Card fluid>
<CardContent>
<div
dangerouslySetInnerHTML={{
__html: prependTime() + replaceMagic(props.message.text),
__html: replaceMagic(props.message.text),
}}
/>
</CardContent>
Expand Down
2 changes: 1 addition & 1 deletion src/components/MessageList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('MessageList', function () {
.fn()
.mockImplementation(intersectionObserverMock)

render(<MessageList prependTime={false} refreshInterval={10} />)
render(<MessageList refreshInterval={10} />)

expect(screen.getByText('Loading messages')).toBeInTheDocument()
expect(
Expand Down
7 changes: 1 addition & 6 deletions src/components/MessageList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { getTimeline } from '../lib/api'

interface Props {
refreshInterval: number
prependTime: boolean
}

const MessageList: FC<Props> = props => {
Expand Down Expand Up @@ -130,11 +129,7 @@ const MessageList: FC<Props> = props => {
return (
<div>
{messages.map(message => (
<Message
key={message.id}
message={message}
prependTime={props.prependTime}
/>
<Message key={message.id} message={message} />
))}
{!lastMessageReceived && (
<div ref={loadMoreSpinnerRef}>
Expand Down
1 change: 0 additions & 1 deletion src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export type Ticker = {
domain: string
id: string
title: string
prepend_time: boolean
information: TickerInformation
}

Expand Down
10 changes: 2 additions & 8 deletions src/views/ActiveView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ const ActiveView: FC<Props> = props => {
<About isModal ticker={props.ticker} />
{headline && <HeaderWrapper content={headline} size={'large'} />}
<ReloadInfo />
<MessageList
prependTime={props.ticker.prepend_time}
refreshInterval={props.refreshInterval}
/>
<MessageList refreshInterval={props.refreshInterval} />
</Wrapper>
)
}
Expand All @@ -57,10 +54,7 @@ const ActiveView: FC<Props> = props => {
<Grid.Row columns={2}>
<Grid.Column computer={10} tablet={10}>
<div ref={handleContextRef}>
<MessageList
prependTime={props.ticker.prepend_time}
refreshInterval={props.refreshInterval}
/>
<MessageList refreshInterval={props.refreshInterval} />
</div>
</Grid.Column>
<Grid.Column computer={6} tablet={6}>
Expand Down

0 comments on commit 7dee7bc

Please sign in to comment.