docbrown/app/javascript/packs/homePage.jsx
Nick Taylor 86eb75cee7
Report a Message in Connect (#12229)
* Frontend Ready for Connect Report Abuse

* add feedback api

* js defination fix

* Added Hooks to the Component

* add json response in feedback

* Block popup added

* fix render issue

* Made changes in internal view

* change error message

* Added few design changes =

* add test cases

* Update app/javascript/chat/actions/requestActions.js

Co-authored-by: Nick Taylor <nick@iamdeveloper.com>

* add PR suggestions

* add backend test cases

* report abuse form close

* Update app/javascript/chat/actions/requestActions.js

Co-authored-by: Nick Taylor <nick@iamdeveloper.com>

* Update app/javascript/chat/ReportAbuse/index.jsx

Co-authored-by: Nick Taylor <nick@iamdeveloper.com>

* add test cases

* Update app/javascript/chat/ReportAbuse/index.jsx

Co-authored-by: Nick Taylor <nick@iamdeveloper.com>

* Update app/javascript/chat/ReportAbuse/index.jsx

Co-authored-by: Marcy Sutton <holla@marcysutton.com>

* Update app/javascript/chat/ReportAbuse/index.jsx

Co-authored-by: Marcy Sutton <holla@marcysutton.com>

* group the fieldset

* fix report abuse api

* fix test case

* fix request test case

* fix typo

* cleaned up markup in report abuse component.

* Fixed spacing between abuse options.

* Fixed wording in report abuse confirmation.

* Removed unnecessary data-testid and aria-label attributes.

* Added some top margin to the report abuse form.

* Update app/javascript/chat/message.jsx

Co-authored-by: Suzanne Aitchison <suzanne@forem.com>

* Added a legend to the the fieldset.

* Update app/javascript/chat/actions/requestActions.js

Co-authored-by: Michael Kohl <citizen428@dev.to>

Co-authored-by: Sarthak <7lovesharma7@gmail.com>
Co-authored-by: Narender Singh <narender2031@gmail.com>
Co-authored-by: Marcy Sutton <holla@marcysutton.com>
Co-authored-by: Suzanne Aitchison <suzanne@forem.com>
Co-authored-by: Michael Kohl <citizen428@dev.to>
2021-01-19 12:07:47 -05:00

119 lines
3.3 KiB
JavaScript

import { h, render } from 'preact';
import { TagsFollowed } from '../leftSidebar/TagsFollowed';
/* global userData */
// This logic is similar to that in initScrolling.js.erb
const frontPageFeedPathNames = new Map([
['/', ''],
['/top/week', 'week'],
['/top/month', 'month'],
['/top/year', 'year'],
['/top/infinity', 'infinity'],
['/latest', 'latest'],
]);
/**
* Renders tags followed in the left side bar of the homepage.
*
* @param {HTMLElement} tagsFollowedContainer DOM element to render tags followed.
* @param {object} user The currently logged on user, null if not logged on.
*/
function renderTagsFollowed(user = userData()) {
const tagsFollowedContainer = document.getElementById(
'sidebar-nav-followed-tags',
);
if (!tagsFollowedContainer) {
// Not on the homepage, so nothing to do.
return false;
}
if (user === null || document.getElementById('followed-tags-wrapper')) {
return;
}
// Only render if a user is logged on.
const { followed_tags } = user; // eslint-disable-line camelcase
const followedTags = JSON.parse(followed_tags);
// This should be done server-side potentially
// sort tags by descending weight, descending popularity and name
followedTags.sort((tagA, tagB) => {
return (
tagB.points - tagA.points ||
tagB.hotness_score - tagA.hotness_score ||
tagA.name.localeCompare(tagB.name)
);
});
render(
<TagsFollowed tags={followedTags} />,
tagsFollowedContainer,
tagsFollowedContainer.firstElementChild,
);
}
function renderSidebar() {
const sidebarContainer = document.getElementById('sidebar-wrapper-right');
// If the screen's width is less than 1024px we don't need this extra data.
if (sidebarContainer && screen.width > 1023 && window.location.pathname === '/') {
window.fetch('/sidebars/home')
.then(res => res.text())
.then(response => {
sidebarContainer.innerHTML = response;
});
}
}
const feedTimeFrame = frontPageFeedPathNames.get(window.location.pathname);
if (!document.getElementById('featured-story-marker')) {
const waitingForDataLoad = setInterval(() => {
const { user = null, userStatus } = document.body.dataset;
if (userStatus === 'logged-out') {
return;
}
if (userStatus === 'logged-in' && user !== null) {
clearInterval(waitingForDataLoad);
if (document.getElementById('rendered-article-feed')) {
return;
}
import('./homePageFeed').then(({ renderFeed }) => {
// We have user data, render followed tags.
renderFeed(feedTimeFrame);
InstantClick.on('change', () => {
const { userStatus: currentUserStatus } = document.body.dataset;
if (currentUserStatus === 'logged-out') {
return;
}
const url = new URL(window.location);
const changedFeedTimeFrame = frontPageFeedPathNames.get(url.pathname);
if (!frontPageFeedPathNames.has(url.pathname)) {
return;
}
renderFeed(changedFeedTimeFrame);
});
});
renderTagsFollowed();
renderSidebar();
}
}, 2);
}
InstantClick.on('change', () => {
if (document.body.dataset.userStatus !== 'logged-in') {
// Nothing to do, the user is not logged on.
return false;
}
renderTagsFollowed();
renderSidebar();
});
InstantClick.init();