Skip to content

Commit

Permalink
resolved/unresolved working
Browse files Browse the repository at this point in the history
  • Loading branch information
Kayla Lei committed Oct 9, 2024
1 parent 3da21d4 commit adcaf57
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 51 deletions.
Binary file modified dump.rdb
Binary file not shown.
59 changes: 21 additions & 38 deletions public/src/client/topic/threadTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,29 @@ define('forum/topic/threadTools', [
});

topicContainer.on('click', '[component="topic/mark-resolved"]', function () {
var text = document.getElementById('resolve-text');
var isResolved = text.innerHTML === 'Mark Resolved';

if (isResolved) {
markTopicResolved();
topicCommand('put', '/resolved', undefined, () => {
if (app.previousUrl && !app.previousUrl.match('^/topic')) {
ajaxify.go(app.previousUrl, function () {
handleBack.onBackClicked(true);
});
} else if (ajaxify.data.category) {
ajaxify.go('category/' + ajaxify.data.category.slug, handleBack.onBackClicked);
}
alerts.success('Topic has been marked as resolved');
} else {
markTopicUnresolved();
});
});

topicContainer.on('click', '[component="topic/mark-unresolved"]', function () {
topicCommand('del', '/resolved', undefined, () => {
if (app.previousUrl && !app.previousUrl.match('^/topic')) {
ajaxify.go(app.previousUrl, function () {
handleBack.onBackClicked(true);
});
} else if (ajaxify.data.category) {
ajaxify.go('category/' + ajaxify.data.category.slug, handleBack.onBackClicked);
}
alerts.success('Topic has been marked as unresolved');
}
});
});

topicContainer.on('click', '[component="topic/mark-unread-for-all"]', function () {
Expand Down Expand Up @@ -158,36 +171,6 @@ define('forum/topic/threadTools', [
changeWatching('ignore');
});

function markTopicResolved() {
const tid = ajaxify.data.tid;
api.put(`/topics/${tid}/resolved`, {}, () => {
console.log('Resolved API called');
toggleResolve('resolved');
});
}

function markTopicUnresolved() {
const tid = ajaxify.data.tid;
api.del(`/topics/${tid}/resolved`, {}, () => {
console.log('Unresolved API called');
toggleResolve('unresolved');
});
}

// Toggle the button text and icon based on the resolved/unresolved state
function toggleResolve(state) {
var text = document.getElementById('resolve-text');
var icon = document.getElementById('resolve-icon');

if (state === 'resolved') {
text.innerHTML = 'Mark Unresolved';
icon.className = 'fa fa-fw fa-times text-danger';
} else {
text.innerHTML = 'Mark Resolved';
icon.className = 'fa fa-fw fa-check text-success';
}
}

function changeWatching(type, state = 1) {
const method = state ? 'put' : 'del';
api[method](`/topics/${tid}/${type}`, {}, () => {
Expand Down
12 changes: 0 additions & 12 deletions src/api/topics.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,20 +301,8 @@ topicsAPI.bump = async (caller, { tid }) => {

topicsAPI.markResolved = async (caller, { tid }) => {
await topics.setTopicField(tid, 'resolved', true);
console.log('resolved pressed!');
};

topicsAPI.markUnresolved = async (caller, { tid }) => {
await topics.setTopicField(tid, 'resolved', false);
console.log('unresolved pressed!');
};

topicsAPI.isResolved = async (caller, { tid }) => {
const isResolved = await topics.getTopicFields(tid, ['resolved']);
if (strictEqual(isResolved.resolved, 'false')){
return false;
}
else{
return true;
}
};
8 changes: 8 additions & 0 deletions src/controllers/category.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,18 @@ categoryController.get = async function (req, res, next) {
});

analytics.increment([`pageviews:byCid:${categoryData.cid}`]);
categoryData.topics = setResolvedBooleans(categoryData.topics);

res.render('category', categoryData);
};

function setResolvedBooleans(topics) {
for (let i = 0; i < topics.length; i++) {
topics[i].resolved = topics[i].resolved === 'true';
}
return topics;
}

async function buildBreadcrumbs(req, categoryData) {
const breadcrumbs = [
{
Expand Down
1 change: 1 addition & 0 deletions src/controllers/topics.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ topicsController.get = async function getTopic(req, res, next) {
rel.href = `${url}/topic/${topicData.slug}${rel.href}`;
res.locals.linkTags.push(rel);
});
topicData.resolved = topicData.resolved === 'true';
res.render('topic', topicData);
};

Expand Down
2 changes: 1 addition & 1 deletion src/views/partials/data/category.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<td class="text-center">
<!-- Resolved/Not Resolved Display -->
{{{ if resolved }}}
{{{ if topics.resolved }}}
<span class="badge badge-success">
<i class="fa fa-check-circle"></i> Resolved
</span>
Expand Down

0 comments on commit adcaf57

Please sign in to comment.