Skip to content

Commit 0dcf44a

Browse files
update
1 parent fe99fd2 commit 0dcf44a

3 files changed

Lines changed: 131 additions & 17 deletions

File tree

controllers/controller.js

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,20 @@ const DashboardLoad = async (req, res) => {
7676
}
7777
}
7878

79+
// Prepare slider problem lists
80+
const ownerGpIds = yourCommunities.map(c => c.gp_id);
81+
const memberGpIds = communitiesYouUse.map(c => c.gp_id);
82+
83+
// Fetch recent problems for owner communities and member communities
84+
const ownerProblems = ownerGpIds.length > 0 ? await Problems.find({ com_id: { $in: ownerGpIds } }).sort({ _id: -1 }).limit(50) : [];
85+
const memberProblems = memberGpIds.length > 0 ? await Problems.find({ com_id: { $in: memberGpIds } }).sort({ _id: -1 }).limit(50) : [];
86+
7987
res.render("dashboard", {
8088
user: user,
8189
yourCommunities: yourCommunities,
82-
communitiesYouUse: communitiesYouUse
90+
communitiesYouUse: communitiesYouUse,
91+
ownerProblems: ownerProblems,
92+
memberProblems: memberProblems
8393
});
8494

8595
} catch (error) {
@@ -417,8 +427,11 @@ const raiseProblem = async (req, res) => {
417427

418428
// Check if user is member of community
419429
const community = await Communities.findOne({ gp_id: communityId });
420-
if (!community || !community.members.includes(userId)) {
421-
return res.status(403).json({ error: 'Not a member of this community' });
430+
if (!community) {
431+
return res.redirect('/discover?error=Community not found');
432+
}
433+
if (!community.members.includes(userId)) {
434+
return res.redirect(`/com/${communityId}?error=You must join the community to raise a problem`);
422435
}
423436

424437
// Generate unique problem ID
@@ -495,16 +508,15 @@ const raiseProblem = async (req, res) => {
495508
);
496509
}
497510

498-
res.json({
499-
success: true,
500-
message: 'Problem raised successfully',
501-
problemId: pb_id,
502-
hasAudio: problemData.has_audio
503-
});
511+
return res.redirect(`/com/${communityId}?success=Problem raised successfully`);
504512

505513
} catch (error) {
506514
console.log('Error raising problem:', error);
507-
res.status(500).json({ error: 'Failed to raise problem' });
515+
try {
516+
return res.redirect(`/com/${req.params.id}?error=Failed to raise problem`);
517+
} catch (e) {
518+
return res.redirect('/dashboard?error=Failed to raise problem');
519+
}
508520
}
509521
};
510522

@@ -558,7 +570,7 @@ const inviteMember = async (req, res) => {
558570
await sendNotification(
559571
[userToInvite.us_id],
560572
'invitation',
561-
`You've been invited to join ${community.Name}`,
573+
`You have been invited to join ${community.Name}`,
562574
communityId
563575
);
564576

@@ -695,7 +707,7 @@ const leaveCommunity = async (req, res) => {
695707
console.log("here")
696708
const ownerId = community.members.length > 0 ? community.members[0] : null;
697709
if (ownerId && ownerId !== userId) {
698-
console.log("here")
710+
console.log("here")
699711
await sendNotification([ownerId], 'general', `${req.session.user} left the community ${community.Name}`);
700712
}
701713
} catch (e) {
@@ -751,7 +763,7 @@ const markProblemSolved = async (req, res) => {
751763
{
752764
$set: {
753765
solved: true,
754-
solved_at: new Date(),
766+
solved_at: new Date(),
755767
worker_remarks: worker_remarks || '',
756768
solved_by: userId
757769
}
@@ -874,7 +886,7 @@ const getNotifications = async (req, res) => {
874886

875887
} catch (error) {
876888
console.log(error);
877-
res.json([]);
889+
res.status(500).json({ error: 'Failed to get notifications' });
878890
}
879891
};
880892

views/community.pug

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1351,7 +1351,7 @@ body
13511351
// Raise Problem Section with Audio Recording
13521352
.raise-problem-section
13531353
.section-title Raise New Problem
1354-
form#raiseProblemForm(data-community-id=community.gp_id)
1354+
form#raiseProblemForm(action=`/com/${community.gp_id}/raise-problem`, method="POST", data-community-id=community.gp_id)
13551355
.form-row
13561356
.form-group
13571357
label(for="category") Problem Category *

views/dashboard.pug

Lines changed: 104 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,17 @@ html(lang="en")
800800
}
801801
}
802802

803+
/* Slider styles */
804+
.slider{position:relative;margin:1rem 0}
805+
.slider-track{display:flex;gap:1rem;overflow-x:auto;padding:1rem 0;scroll-behavior:smooth}
806+
.slide-card{min-width:260px;background:var(--darker);border:1px solid var(--gray-dark);padding:1rem;border-radius:10px;flex:0 0 auto}
807+
.slider-prev,.slider-next{position:absolute;top:50%;transform:translateY(-50%);background:rgba(0,0,0,0.55);border:none;color:#fff;padding:0.5rem;border-radius:6px;cursor:pointer;z-index:5}
808+
.slider-prev{left:0.5rem}
809+
.slider-next{right:0.5rem}
810+
.slide-link{color:var(--light);text-decoration:none;display:block}
811+
.slide-title{font-weight:600;margin-bottom:0.5rem}
812+
.slide-meta{color:var(--gray);font-size:0.85rem}
813+
803814
body
804815
// Header
805816
header.dashboard-header
@@ -863,6 +874,57 @@ html(lang="en")
863874
h3 Settings
864875
p Manage your account preferences
865876

877+
// Problems Sliders (Owner / Member)
878+
section.slider-section
879+
.section-header
880+
.section-title Problems In Your Communities
881+
if ownerProblems && ownerProblems.length > 0
882+
.slider
883+
button.slider-prev(type="button")
884+
i.fas.fa-chevron-left
885+
.slider-track#ownerSlider
886+
each problem in ownerProblems
887+
.slide-card
888+
a.slide-link(href=`/com/${problem.com_id}`)
889+
.slide-title #{(problem.msg && problem.msg.length > 80) ? problem.msg.substring(0,80) + '...' : (problem.msg || 'Untitled problem')}
890+
.slide-meta
891+
span #{problem.category || 'general'}
892+
| •
893+
span #{problem.solved ? 'Solved' : 'Open'}
894+
button.slider-next(type="button")
895+
i.fas.fa-chevron-right
896+
else
897+
.empty-state
898+
.empty-icon
899+
i.fas.fa-list
900+
h3 No Problems In Your Owned Communities
901+
p There are no active problems raised in the communities you own.
902+
903+
section.slider-section
904+
.section-header
905+
.section-title Problems In Communities You Use
906+
if memberProblems && memberProblems.length > 0
907+
.slider
908+
button.slider-prev(type="button")
909+
i.fas.fa-chevron-left
910+
.slider-track#memberSlider
911+
each problem in memberProblems
912+
.slide-card
913+
a.slide-link(href=`/com/${problem.com_id}`)
914+
.slide-title #{(problem.msg && problem.msg.length > 80) ? problem.msg.substring(0,80) + '...' : (problem.msg || 'Untitled problem')}
915+
.slide-meta
916+
span #{problem.category || 'general'}
917+
| •
918+
span #{problem.solved ? 'Solved' : 'Open'}
919+
button.slider-next(type="button")
920+
i.fas.fa-chevron-right
921+
else
922+
.empty-state
923+
.empty-icon
924+
i.fas.fa-list
925+
h3 No Problems Found
926+
p There are no problems in communities you are a member of.
927+
866928
// Your Communities Section
867929
section.communities-section
868930
.section-header
@@ -932,6 +994,8 @@ html(lang="en")
932994
i.fas.fa-search
933995
| Find Communities
934996

997+
998+
935999
// Create Community Modal
9361000
.modal#createCommunityModal
9371001
.modal-content
@@ -1207,5 +1271,43 @@ html(lang="en")
12071271
// Auto-refresh notifications every 30 seconds
12081272
setInterval(loadNotifications, 30000);
12091273

1210-
// Load notifications on page load
1211-
document.addEventListener('DOMContentLoaded', loadNotifications);
1274+
// Slider initialization: prev/next and drag-to-scroll
1275+
function initSliders() {
1276+
document.querySelectorAll('.slider').forEach(slider => {
1277+
const track = slider.querySelector('.slider-track');
1278+
const prev = slider.querySelector('.slider-prev');
1279+
const next = slider.querySelector('.slider-next');
1280+
if (!track) return;
1281+
1282+
if (prev) prev.addEventListener('click', () => {
1283+
track.scrollBy({ left: -Math.round(track.clientWidth * 0.8), behavior: 'smooth' });
1284+
});
1285+
if (next) next.addEventListener('click', () => {
1286+
track.scrollBy({ left: Math.round(track.clientWidth * 0.8), behavior: 'smooth' });
1287+
});
1288+
1289+
// Mouse drag to scroll
1290+
let isDown = false, startX, scrollLeft;
1291+
track.addEventListener('mousedown', (e) => {
1292+
isDown = true;
1293+
track.classList.add('active');
1294+
startX = e.pageX - track.offsetLeft;
1295+
scrollLeft = track.scrollLeft;
1296+
});
1297+
track.addEventListener('mouseleave', () => { isDown = false; track.classList.remove('active'); });
1298+
track.addEventListener('mouseup', () => { isDown = false; track.classList.remove('active'); });
1299+
track.addEventListener('mousemove', (e) => {
1300+
if (!isDown) return;
1301+
e.preventDefault();
1302+
const x = e.pageX - track.offsetLeft;
1303+
const walk = (x - startX) * 1; // scroll-fast factor
1304+
track.scrollLeft = scrollLeft - walk;
1305+
});
1306+
});
1307+
}
1308+
1309+
// Load notifications and initialize sliders on page load
1310+
document.addEventListener('DOMContentLoaded', () => {
1311+
loadNotifications();
1312+
initSliders();
1313+
});

0 commit comments

Comments
 (0)