Skip to content

Commit

Permalink
Fix: Use undefined instead of null | fix '/threads' bug
Browse files Browse the repository at this point in the history
  • Loading branch information
plibither8 committed Apr 7, 2019
1 parent e9f8d5b commit e204868
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
8 changes: 6 additions & 2 deletions src/features/comments-ui-tweaks.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ import {paths} from '../libs/paths';
async function init(metadata) {
const me = metadata.user.name;

const itemId = getUrlParams('id');
const op = itemId ? (await getItemInfo(itemId)).by : null;
let op;

if (metadata.path === '/item') {
const itemId = getUrlParams('id');
op = itemId ? (await getItemInfo(itemId)).by : undefined;
}

const comments = getAllComments();

Expand Down
2 changes: 1 addition & 1 deletion src/features/toggle-all-comments-and-replies.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function toggleAllReplies() {
allComments.forEach((comment, id) => {
const currentIndent = comment.querySelector('td.ind img').width / 40;
const nextIndent = id + 1 === allComments.length ?
null :
undefined :
allComments[id + 1].querySelector('td.ind img').width / 40;

if (nextIndent && nextIndent > currentIndent) {
Expand Down
4 changes: 2 additions & 2 deletions src/libs/dom-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ export function getGroupedStories(itemlist) {
const storyUrl = rows[i].querySelector('a.storylink').href;

const scoreSpan = rows[i + 1].querySelector('span.score');
const score = scoreSpan ? parseInt(scoreSpan.innerText, 10) : null;
const score = scoreSpan ? parseInt(scoreSpan.innerText, 10) : undefined;

const defaultRank = parseInt(rows[i].querySelector('span.rank').innerText, 10);

const commentsLink = [...rows[i + 1].querySelectorAll('a')]
.find(a => a.innerText.includes('comment') || a.innerText.includes('discuss'));
const commentsCount = commentsLink ? parseInt(commentsLink.innerText, 10) : null;
const commentsCount = commentsLink ? parseInt(commentsLink.innerText, 10) : undefined;

const elements = [
rows[i],
Expand Down
8 changes: 4 additions & 4 deletions src/libs/initialise.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,20 @@ const featureList = [
const getMetadata = new Promise(resolve => {
const metadata = {
path: window.location.pathname,
itemId: null,
itemId: undefined,
user: {
loggedIn: false,
name: null
name: undefined
},
isJob: false,
options: null,
options: undefined,
firstLoad: false
};

window.addEventListener('load', async () => {
metadata.itemId = getUrlParams('id');
metadata.user.loggedIn = isLoggedIn();
metadata.user.name = metadata.user.loggedIn ? getLoggedInUser() : null;
metadata.user.name = metadata.user.loggedIn ? getLoggedInUser() : undefined;
metadata.isJob = (metadata.itemId && metadata.path === '/item') ? await isItemJob(metadata.itemId) : false;
metadata.options = await getOptions;
resolve(metadata);
Expand Down

0 comments on commit e204868

Please sign in to comment.