docbrown/app/javascript/modCenter/moderationArticles.jsx
Arit Amana a78ccf2310
[deploy] [ModCenter] Fix "FlagUser" Modal functionality (#8995)
* Make FlagUserModal show up on click

* Explain extra div

* Make sure "Vomit All" reaction fires accurately

* Make test-file comment clearer

* Fix bug when 2 articles are open and the FlagUser modal does not open for the first article

* Still working it out ...

* Tests broken; need help

* Get rid of debugging alerts

* Fixed broken tests for <SingleArticle />

* Write tests for ModerationArticles component

* Complete tests for ModerationArticles component

* Employ safer Preact testing techniques

* Query all articles using "data-testid"

* Revert changes

* Got it working with portals for non-iframe implementation.

* wip tests

* Got mod tools flag user modal wprking on article page again.

* Added some documentation the code.

* Now confirm is disabled until you select an item in the flag user modal.

* Revert "wip tests"

This reverts commit fb7a0825039fd377cad04d9dedad9d1146b03978.

* test prep

* Fixed broken test.

* Refactored to use useRef hook.

* Rename a variable

* remove unnecessary comments

Co-authored-by: Nick Taylor <nick@dev.to>
2020-07-15 13:54:52 -04:00

68 lines
1.9 KiB
JavaScript

import { h, Component } from 'preact';
import SingleArticle from './singleArticle';
export class ModerationArticles extends Component {
state = {
articles: JSON.parse(
document.getElementById('mod-index-list').dataset.articles,
),
prevSelectedArticleId: undefined,
selectedArticleId: undefined,
};
toggleArticle = (id, path) => {
const { prevSelectedArticleId } = this.state;
const selectedArticle = document.getElementById(`article-iframe-${id}`);
if (prevSelectedArticleId > 0) {
document.getElementById(
`article-iframe-${prevSelectedArticleId}`,
).innerHTML = '';
}
this.setState({ selectedArticleId: id, prevSelectedArticleId: id });
if (
id === prevSelectedArticleId &&
document.querySelectorAll('.opened').length > 0
) {
selectedArticle.classList.remove('opened');
return;
}
selectedArticle.classList.add('opened');
selectedArticle.innerHTML = `<iframe class="article-iframe" src="${path}"></iframe><iframe data-testid="mod-iframe-${id}" class="actions-panel-iframe" id="mod-iframe-${id}" src="${path}/actions_panel"></iframe>`;
};
render() {
const { articles, selectedArticleId } = this.state;
return (
<div className="moderation-articles-list">
{articles.map((article) => {
const {
id,
title,
path,
cached_tag_list: cachedTagList,
published_at: publishedAt,
user,
} = article;
return (
<SingleArticle
id={id}
title={title}
path={path}
cachedTagList={cachedTagList}
key={id}
publishedAt={publishedAt}
user={user}
articleOpened={id === selectedArticleId}
toggleArticle={this.toggleArticle}
/>
);
})}
</div>
);
}
}