Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add message component #12

Merged
merged 1 commit into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
DemianParkhomenko marked this conversation as resolved.
Show resolved Hide resolved
}
}
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,
})