Files
web2.0-frontend/src/views/NewsFeedPage/NewsFeedPageView.tsx
T
Elmo Kankkunen a4a3da7b44 News feed page
2022-10-12 22:47:54 +03:00

57 lines
1.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import React from "react";
import {
Card,
CardSection,
} from "@components/index";
import Post from "@models/Feed";
import noop from "@utils/noop";
import { getTranslateFunc } from "../../i18n";
interface NewsFeedPageViewProps {
posts: Post[];
}
const cardTimeOpts: Intl.DateTimeFormatOptions = {
day: "numeric",
month: "numeric",
year: "numeric",
hour: "numeric",
minute: "2-digit",
};
const NewsFeedPageView: React.FC<NewsFeedPageViewProps> = ({ posts }) => {
const isFi = true;
const t = getTranslateFunc("fi");
const buttonText = `${t("Lue lisää")}\xa0`;
const locale = isFi ? "fi-FI" : "en-GB";
const filteredFeed = posts.map((post) => ({
...post,
title: isFi ? post.title_fi : post.title_en,
description: isFi ? post.description_fi : post.description_en,
content: isFi ? post.content_fi : post.content_en,
publish_time: new Date(post.publish_time).toLocaleString(locale, cardTimeOpts),
}));
return (
<CardSection>
{filteredFeed.map((post) => (
<Card
key={post.id}
title={post.title}
text={post.description}
startTime={post.publish_time}
link={`/feed/${post.id}`}
buttonOnClick={noop}
buttonText={buttonText}
/>
))}
</CardSection>
);
};
export default NewsFeedPageView;