Skip to content

Commit

Permalink
Fixing linter errors in topics.js and cateogry.js
Browse files Browse the repository at this point in the history
  • Loading branch information
alx-zhu committed Oct 10, 2024
1 parent 2f075ec commit f23b1f7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions public/src/client/category.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,13 @@ define('forum/category', [
const titleMatch = title.indexOf(searchTerm) !== -1;
const contentEl = topicEl.find('[component="topic/hidden-content"]');
const content = contentEl.text().toLowerCase();
const contentIdx = content.indexOf(searchTerm)
const hasMatch = (titleMatch || (contentIdx !== -1))
const contentIdx = content.indexOf(searchTerm);
const hasMatch = (titleMatch || (contentIdx !== -1));
const searchContentEl = topicEl.find('[component="topic/search-content"]');

topicEl.toggleClass('hidden', !hasMatch);

// Use topic/search-content placeholder to display the 100 character preview around the search term.
// Use topic/search-content placeholder to display the 100 character preview around the search term.
// Only do this if the search is more than 2 characters
if (contentIdx !== -1 && searchTerm.length >= 2) {
const start = Math.max(0, contentIdx - 50);
Expand All @@ -149,19 +149,19 @@ define('forum/category', [
const highlightedSnippet = snippet.replace(new RegExp(`(${searchTerm})`, 'gi'), '<strong class="highlight">$1</strong>');
searchContentEl.html(`...${highlightedSnippet}...`);
} else {
searchContentEl.html("");
searchContentEl.html('');
}
});

// Show the alert for no matches if there are no matched topics, otherwise keep it hidden.
const visibleTopics = topicEls.filter(':not(.hidden)');
const alertComponent = $('[component="category/topic/no-matches"]')
const alertComponent = $('[component="category/topic/no-matches"]');
if (visibleTopics.length === 0) {
alertComponent.removeClass('hidden');
alertComponent.html(`No topics match the search term ${searchTerm}.`);
} else {
alertComponent.addClass('hidden');
alertComponent.html("");
alertComponent.html('');
}
});
}
Expand Down
6 changes: 3 additions & 3 deletions src/categories/topics.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

const sanitizeHtml = require('sanitize-html');
const db = require('../database');
const topics = require('../topics');
const plugins = require('../plugins');
Expand All @@ -9,22 +10,21 @@ const user = require('../user');
const notifications = require('../notifications');
const translator = require('../translator');
const batch = require('../batch');
const sanitizeHtml = require('sanitize-html');

module.exports = function (Categories) {
Categories.getCategoryTopics = async function (data) {
let results = await plugins.hooks.fire('filter:category.topics.prepare', data);
const tids = await Categories.getTopicIds(results);
let topicsData = await topics.getTopicsByTids(tids, data.uid);
topicsData = await user.blocks.filter(data.uid, topicsData);

// Add actual post content to the topicsData to show search previews
const mainPosts = await topics.getMainPosts(tids, data.uid);
topicsData.forEach((topic, idx) => {
// Clean all html, allowing no tags or attributes
topic.content = sanitizeHtml(mainPosts[idx].content, {
allowedTags: [],
allowedAttributes: {}
allowedAttributes: {},
});
});

Expand Down

0 comments on commit f23b1f7

Please sign in to comment.