docbrown/app/assets/javascripts/initializers/initializeBaseUserData.js
ludwiczakpawel a77dfefc2a
Homepage UI Improvements (#5890) [deploy]
* de-emphasizing right sidebar: mostly colors & spacing

* adding a bit more love to typography in sidebar

* changing language on LISTINGS widget header

* hiding profile widget from left sidebar

* cards shadow now looks like a bit less random and annoying

* actually doing the same with all shadows! YOLO

* some spacing cleanups around sidebars

* this time some typography love

* im committing but not really sure what exactly

* adding a bit more love to feed card

* looks like i broke some other views.. time to fix em all

* cleaning up typography a bit more

* .

* separating empty search results styling

* created a card styling mixing to reduce some code.. also moved cheese around a bit

* several more cleanups

* improving responsiveness

* i fixed what i broke

* more cleanups

* org badge

* .

* ...

* responsiveness

* .

* some adjustments

* bring back profile card

* tiny logo adjustment

* bunch of further refainments

* typography

* a bit more refainments

* whoops

* bringing back CTAs styling to loggedout sidebar

* fixes to left tags in left sidebar after merge

* buttons fix

* fixing border-color

* Update app/assets/stylesheets/articles.scss

Typo!

Co-Authored-By: Nick Taylor <nick@iamdeveloper.com>

* .

* css cleanup + double border on article page

* removing unnecessary comments

* get rid of loading glitch

* static vs fixed header

* Update system specs

* Update client test snapshots

* Further modify homepage specs

Co-authored-by: Nick Taylor <nick@iamdeveloper.com>
Co-authored-by: Ben Halpern <bendhalpern@gmail.com>
2020-02-19 11:24:44 -05:00

118 lines
3.7 KiB
JavaScript

'use strict';
/* global userData, filterXSS */
function initializeUserProfileContent(user) {
document.getElementById('sidebar-profile--avatar').src = user.profile_image_90;
document.getElementById('sidebar-profile--avatar').alt = user.username;
document.getElementById('sidebar-profile--name').innerHTML = filterXSS(
user.name,
);
document.getElementById('sidebar-profile--username').innerHTML = '@' + user.username;
document.getElementById('sidebar-profile').href = '/' + user.username;
}
function initializeUserSidebar(user) {
if (!document.getElementById('sidebar-nav')) return;
initializeUserProfileContent(user);
let followedTags = JSON.parse(user.followed_tags);
const tagSeparatorLabel =
followedTags.length === 0
? 'Follow tags to improve your feed'
: 'Other Popular Tags';
followedTags.forEach(tag => {
const element = document.getElementById(
'default-sidebar-element-' + tag.name,
);
if (element) {
element.remove();
}
});
document.getElementById('tag-separator').innerHTML = tagSeparatorLabel;
document.getElementById('sidebar-nav-default-tags').classList.add('showing');
}
function addRelevantButtonsToArticle(user) {
var articleContainer = document.getElementById('article-show-container');
if (articleContainer) {
if (parseInt(articleContainer.dataset.authorId, 10) === user.id) {
let actions = [
`<a href="${articleContainer.dataset.path}/edit" rel="nofollow">EDIT</a>`,
];
if (JSON.parse(articleContainer.dataset.published) === true) {
actions.push(
`<a href="${articleContainer.dataset.path}/manage" rel="nofollow">MANAGE</a>`,
);
}
if (user.pro) {
actions.push(
`<a href="${articleContainer.dataset.path}/stats" rel="nofollow">STATS</a>`,
);
}
document.getElementById('action-space').innerHTML = actions.join('');
} else if (user.trusted) {
document.getElementById('action-space').innerHTML =
'<a href="' +
articleContainer.dataset.path +
'/mod" rel="nofollow">MODERATE <span class="post-word">POST</span></a>';
}
}
}
function addRelevantButtonsToComments(user) {
if (document.getElementById('comments-container')) {
// buttons are actually <span>'s
var settingsButts = document.getElementsByClassName('comment-actions');
for (let i = 0; i < settingsButts.length; i += 1) {
let butt = settingsButts[i];
const { action, commentableUserId, userId } = butt.dataset;
if (parseInt(userId, 10) === user.id) {
butt.style.display = 'inline-block';
}
if (
action === 'hide-button' &&
parseInt(commentableUserId, 10) === user.id
) {
butt.style.display = 'inline-block';
} else if (
action === 'hide-button' &&
parseInt(commentableUserId, 10) !== user.id
) {
butt.style.display = 'none';
}
}
if (user.trusted) {
var modButts = document.getElementsByClassName('mod-actions');
for (let i = 0; i < modButts.length; i += 1) {
let butt = modButts[i];
butt.className = 'mod-actions';
butt.style.display = 'inline-block';
}
}
}
}
function initializeBaseUserData() {
const user = userData();
const userProfileLinkHTML =
'<a href="/' +
user.username +
'" id="first-nav-link"><div class="option prime-option">@' +
user.username +
'</div></a>';
document.getElementById(
'user-profile-link-placeholder',
).innerHTML = userProfileLinkHTML;
document.getElementById('nav-profile-image').src = user.profile_image_90;
initializeUserSidebar(user);
addRelevantButtonsToArticle(user);
addRelevantButtonsToComments(user);
}