Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notifusfront #34

Merged
merged 3 commits into from
Sep 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 70 additions & 21 deletions public/src/client/topic.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,46 @@ define('forum/topic', [
}
});

Topic.init = async function () {
Topic.init = function () {
console.log('Topic.init is running');

// Listen for the correct event (composer topics post)
$(window).on('action:composer.topics.post', function (event, data) {
console.log('Topic Post Event Triggered:', data); // Log the event data

if (data && data.data && data.data.uid) { // Correctly access the UID
const uid = data.data.uid;
const topicName = data.data.title || 'Unknown Topic'; // Get the topic name

console.log('Topic post detected. UID:', uid, 'Topic Name:', topicName);

// Fetch the username based on the UID
api.get(`/users/${uid}`, {}, function (err, userData) {
if (err || !userData) {
console.error('Error fetching username:', err);
return;
}

const username = userData.username || 'Unknown User';
console.log('Username fetched:', username);

// Display the notification
require(['alerts'], function (alerts) {
alerts.alert({
title: 'New Post Created!',
message: `${username} has successfully posted in the topic "${topicName}".`,
type: 'success',
timeout: 5000,
});
});
});
} else {
console.log('No valid UID found in data');
}
});

console.log('Event listener for posts.save attached');

const tidChanged = !tid || parseInt(tid, 10) !== parseInt(ajaxify.data.tid, 10);
tid = ajaxify.data.tid;
currentUrl = ajaxify.currentPage;
Expand All @@ -48,35 +87,45 @@ define('forum/topic', [
if (tidChanged) {
posts.signaturesShown = {};
}
await posts.onTopicPageLoad(components.get('post'));
navigator.init('[component="topic"]>[component="post"]', ajaxify.data.postcount, Topic.toTop, Topic.toBottom, Topic.navigatorCallback);

postTools.init(tid);
threadTools.init(tid, $('.topic'));
events.init();
// Use .then() instead of await for promises
posts.onTopicPageLoad(components.get('post')).then(function () {
console.log('Posts loaded on topic page');

sort.handleSort('topicPostSort', 'topic/' + ajaxify.data.slug);
navigator.init('[component="topic"]>[component="post"]', ajaxify.data.postcount, Topic.toTop, Topic.toBottom, Topic.navigatorCallback);
postTools.init(tid);
threadTools.init(tid, $('.topic'));
events.init();

if (!config.usePagination) {
infinitescroll.init($('[component="topic"]'), posts.loadMorePosts);
}
sort.handleSort('topicPostSort', 'topic/' + ajaxify.data.slug);

addBlockQuoteHandler();
addCodeBlockHandler();
addParentHandler();
addRepliesHandler();
addPostsPreviewHandler();
setupQuickReply();
handleBookmark(tid);
handleThumbs();
if (!config.usePagination) {
infinitescroll.init($('[component="topic"]'), posts.loadMorePosts);
}

addBlockQuoteHandler();
addCodeBlockHandler();
addParentHandler();
addRepliesHandler();
addPostsPreviewHandler();
setupQuickReply();
handleBookmark(tid);
handleThumbs();
handleTopicSearch();

$(window).on('scroll', utils.debounce(updateTopicTitle, 250));
$(window).on('scroll', utils.debounce(updateTopicTitle, 250));

handleTopicSearch();
hooks.on('action:topic.loaded', function (data) {
console.log('action:topic.loaded event fired', data); // Log the event
});

hooks.fire('action:topic.loaded', ajaxify.data);
console.log('Event listeners attached');
}).catch(function (err) {
console.error('Error during topic page load:', err);
});
};


function handleTopicSearch() {
require(['mousetrap'], (mousetrap) => {
if (config.topicSearchEnabled) {
Expand Down