shellphone.app/app/features/messages/components/conversations-list.tsx

43 lines
1.5 KiB
TypeScript
Raw Normal View History

import { Link } from "@remix-run/react";
import { useLoaderData } from "superjson-remix";
2022-05-14 10:22:06 +00:00
import { IoChevronForward } from "react-icons/io5";
import { formatRelativeDate } from "~/features/core/helpers/date-formatter";
import PhoneInitLoader from "~/features/core/components/phone-init-loader";
import EmptyMessages from "./empty-messages";
2022-05-19 23:16:38 +00:00
import type { MessagesLoaderData } from "~/features/messages/loaders/messages";
2022-05-14 10:22:06 +00:00
export default function ConversationsList() {
2022-05-21 23:45:13 +00:00
const { conversations, isFetchingMessages } = useLoaderData<MessagesLoaderData>();
2022-05-14 10:22:06 +00:00
2022-05-21 23:45:13 +00:00
if (isFetchingMessages || !conversations) {
2022-05-14 10:22:06 +00:00
// we're still importing messages from twilio
return <PhoneInitLoader />;
}
if (Object.keys(conversations).length === 0) {
return <EmptyMessages />;
}
return (
<ul className="divide-y">
{Object.values(conversations).map(({ recipient, formattedPhoneNumber, lastMessage }) => {
return (
<li key={`sms-conversation-${recipient}`} className="py-2 px-4">
2022-05-19 23:16:38 +00:00
<Link prefetch="intent" to={`/messages/${recipient}`} className="flex flex-col">
2022-05-14 10:22:06 +00:00
<div className="flex flex-row justify-between">
<span className="font-medium">{formattedPhoneNumber ?? recipient}</span>
<div className="text-gray-700 flex flex-row gap-x-1">
{formatRelativeDate(lastMessage.sentAt)}
<IoChevronForward className="w-4 h-4 my-auto" />
</div>
</div>
<div className="line-clamp-2 text-gray-700">{lastMessage.content}</div>
</Link>
</li>
);
})}
</ul>
);
}