Skip to content

Commit

Permalink
Add message component (#12)
Browse files Browse the repository at this point in the history
PR: #12
  • Loading branch information
firehawk89 authored Sep 25, 2023
1 parent d3191c0 commit 5d9cefc
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 9 deletions.
5 changes: 4 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"extends": "next/core-web-vitals"
"extends": "next/core-web-vitals",
"rules": {
"react/no-unescaped-entities": "off"
}
}
4 changes: 4 additions & 0 deletions public/icons/avatar.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions src/app/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@tailwind components;
@tailwind utilities;

.body {
@apply h-screen flex items-center justify-center bg-slate-300;
html,
body {
@apply min-h-screen;
}
4 changes: 3 additions & 1 deletion src/app/layout.js → src/app/layout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import './global.css'
export default function RootLayout({ children }) {
return (
<html lang="en">
<body className="body">{children}</body>
<body className="flex flex-col bg-slate-300">
<main>{children}</main>
</body>
</html>
)
}
5 changes: 0 additions & 5 deletions src/app/page.js

This file was deleted.

26 changes: 26 additions & 0 deletions src/app/page.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use client'

import Message from '@/components/message'

const now = Date.now()
const MOCK_MESSAGES = [
{ sentAt: now - 1000 * 60 * 30, content: `...` },
{ sentAt: now - 1000 * 60 * 10, content: `Hello, i\'m a message! 😎` },
{
sentAt: now,
content:
'Lorem ipsum dolor sit amet consectetur adipisicing elit. Id, porro',
},
]

export default function Home() {
return (
<main className="flex flex-col gap-3 p-3">
{MOCK_MESSAGES.map(({ sentAt, content }, i) => (
<Message key={i} sentAt={sentAt}>
{content}
</Message>
))}
</main>
)
}
25 changes: 25 additions & 0 deletions src/components/message.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { timeFormatter } from '@/utils/getFormattedDate'
import Image from 'next/image'
import Link from 'next/link'

export default function Message({ sentAt, children }) {
const { format: formatTime } = timeFormatter()

return (
<div className="flex items-end gap-2">
<Link className="rounded-full overflow-hidden" href="/">
<Image
className="object-center object-cover"
src="/icons/avatar.svg"
width={38}
height={38}
alt="Picture of the author"
/>
</Link>
<div className="flex justify-between gap-2 rounded-lg rounded-bl-none w-fit max-w-md py-2 px-3 bg-orange-100">
<p className="break-words">{children}</p>
<span className="text-xs self-end">{formatTime(sentAt)}</span>
</div>
</div>
)
}
7 changes: 7 additions & 0 deletions src/utils/getFormattedDate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const timeFormatter = (options) =>
new Intl.DateTimeFormat('en', {
hour: '2-digit',
minute: '2-digit',
hour12: false,
...options,
})

0 comments on commit 5d9cefc

Please sign in to comment.