mirror of
https://git.rdcenter.ru/RDCenter/skb-kit.git
synced 2026-12-05 05:49:45 +00:00
Отображение счетчика просмотров, фикс даты публикации
This commit is contained in:
1 parent
dc8478b318
commit
79856ce5be
4 files changed
+57
-8
No files matched your search
@@ -3,9 +3,9 @@ import { useParams } from "react-router-dom";
|
||||
|
||||
import { PageContent, PageHeader } from "../../components";
|
||||
import { getNewsByID, vkWallUrl } from "../../../api";
|
||||
import { MediaBlock, Slider, VKvideo } from "../../../components";
|
||||
import { Slider } from "../../../components";
|
||||
|
||||
import { extLink } from "../../../assets/images";
|
||||
import { extLink, views } from "../../../assets/images";
|
||||
import "./NewsItem.styles.scss";
|
||||
|
||||
function NewsItem() {
|
||||
@@ -14,11 +14,23 @@ function NewsItem() {
|
||||
const params = useParams();
|
||||
const newsID = params.id;
|
||||
|
||||
function formatDate(timestamp) {
|
||||
const date = new Date(timestamp * 1000);
|
||||
|
||||
const day = String(date.getDate()).padStart(2, '0');
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||||
const year = date.getFullYear();
|
||||
|
||||
return `${day}.${month}.${year}`; // DD.MM.YYYY
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
const loadData = async () => {
|
||||
const newItem = await getNewsByID(newsID);
|
||||
console.log('newItem.views', newItem.views);
|
||||
console.log('newItem.date', newItem.date);
|
||||
newItem.date = formatDate(newItem.date);
|
||||
setNews(newItem);
|
||||
console.log('newItem', newItem);
|
||||
};
|
||||
loadData();
|
||||
}, [newsID]);
|
||||
@@ -33,12 +45,14 @@ function NewsItem() {
|
||||
<h1>{news.heading}</h1>
|
||||
</PageHeader>
|
||||
<PageContent className="content" id="news-item-page">
|
||||
{news.videos.length !== 0 && <VKvideo video={news.videos[0]} />}
|
||||
{news.photos.length !== 0 && <Slider images={news.photos} />}
|
||||
{news.text.map(textRow => <p dangerouslySetInnerHTML={{ __html: textRow }}></p>)}
|
||||
<div className="row">
|
||||
<p><a href={newsUrl} target="_blank" rel="noreferrer">Ссылка на новость <img class="icon" src={extLink} /></a></p>
|
||||
<p className="date">Дата публикации: {news.date}</p>
|
||||
<p><a href={newsUrl} target="_blank" rel="noreferrer">Ссылка на новость <img class="icon" src={extLink} alt="" /></a></p>
|
||||
<div id="right">
|
||||
<p><img class="icon" src={views} alt="" />{news.views}</p>
|
||||
<p id="date">Дата публикации: {news.date}</p>
|
||||
</div>
|
||||
</div>
|
||||
</PageContent>
|
||||
</>
|
||||
|
||||
@@ -2,15 +2,32 @@
|
||||
|
||||
#news-item-page .row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
justify-content: space-between;
|
||||
margin-top: 2em;
|
||||
|
||||
>* {
|
||||
display: inline-block;
|
||||
width: fit-content;
|
||||
}
|
||||
|
||||
.icon {
|
||||
height: $main-font-size;
|
||||
}
|
||||
|
||||
.date {
|
||||
#right {
|
||||
text-align: right;
|
||||
color: rgb(100, 100, 100);
|
||||
|
||||
.icon {
|
||||
margin-right: 0.5em;
|
||||
}
|
||||
|
||||
p {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
#date {
|
||||
margin-left: 1em;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user