File tree Expand file tree Collapse file tree 2 files changed +19
-13
lines changed Expand file tree Collapse file tree 2 files changed +19
-13
lines changed Original file line number Diff line number Diff line change @@ -22,26 +22,29 @@ export const renderFeeds = (feeds) => {
2222 ` ;
2323} ;
2424
25- export const renderPosts = ( posts ) => {
25+ export const renderPosts = ( posts , viewedPostsIds ) => {
2626 const postsContainer = document . querySelector ( ".posts" ) ;
2727
2828 postsContainer . innerHTML = `
29- <div class="card border-0">
30- <div class="card-body">
31- <h2 class="card-title h4">Посты</h2>
32- </div>
33- <ul class="list-group border-0 rounded-0">
34- ${ posts
35- . map (
36- ( post ) => `
29+ <div class="card border-0">
30+ <div class="card-body">
31+ <h2 class="card-title h4">Посты</h2>
32+ </div>
33+ <ul class="list-group border-0 rounded-0">
34+ ${ posts
35+ . map (
36+ ( post ) => {
37+ const titleStyle = viewedPostsIds . includes ( post . id ) ? "fw-normal" : "fw-bold" ;
38+ return `
3739 <li class="list-group-item d-flex justify-content-between align-items-start border-0 border-end-0">
38- <a href="${ post . link } " class="fw-bold" data-id="${ post . id } " target="_blank" rel="noopener noreferrer">${ post . title } </a>
40+ <a href="${ post . link } " class=${ titleStyle } data-id="${ post . id } " target="_blank" rel="noopener noreferrer">${ post . title } </a>
3941 <button type="button" class="btn btn-outline-primary btn-sm modal-btn" data-id="${ post . id } " data-bs-toggle="modal" data-bs-target="#modal">Просмотр</button>
4042 </li>
41- `
43+ ` }
4244 )
4345 . join ( "" ) }
4446 </ul>
4547 </div>
4648 ` ;
4749} ;
50+
Original file line number Diff line number Diff line change @@ -23,13 +23,16 @@ const createState = () => {
2323 feedsChecking ( ) ;
2424 }
2525 if ( path === "posts" ) {
26- renderPosts ( state . posts ) ;
26+ renderPosts ( state . posts , [ ...state . viewedPostsIds ] ) ;
27+ state . posts . forEach ( ( post ) => {
28+ post . rendered = true ;
29+ } ) ;
2730 }
2831 if ( path === "activeItem" ) {
2932 if ( state . activeItem !== null ) {
3033 showModal ( state . activeItem ) ;
3134 markPostAsRead ( state . activeItem . id ) ; //проверять на уникальность!
32- // менять стиль по button.dataset.id?
35+ renderPosts ( state . posts , [ ... state . viewedPostsIds ] ) ;
3336 } else {
3437 closeModal ( ) ;
3538 }
You can’t perform that action at this time.
0 commit comments