feat: show 5 recent questions by default with Load More / Show Less pagination
This commit is contained in:
@@ -73,6 +73,7 @@ export default function Community() {
|
|||||||
const [likedIds, setLikedIds] = useState<Set<string>>(new Set());
|
const [likedIds, setLikedIds] = useState<Set<string>>(new Set());
|
||||||
const [expandedQuestionIds, setExpandedQuestionIds] = useState<Set<string>>(new Set());
|
const [expandedQuestionIds, setExpandedQuestionIds] = useState<Set<string>>(new Set());
|
||||||
const [questions, setQuestions] = useState<any[]>(QUESTIONS_DATA);
|
const [questions, setQuestions] = useState<any[]>(QUESTIONS_DATA);
|
||||||
|
const [visibleCount, setVisibleCount] = useState(5);
|
||||||
|
|
||||||
const toggleAnswers = (id: string) => {
|
const toggleAnswers = (id: string) => {
|
||||||
setExpandedQuestionIds((prev) => {
|
setExpandedQuestionIds((prev) => {
|
||||||
@@ -130,6 +131,9 @@ export default function Community() {
|
|||||||
tagsVal.some((t: string) => t.toLowerCase().includes(searchQuery.toLowerCase()));
|
tagsVal.some((t: string) => t.toLowerCase().includes(searchQuery.toLowerCase()));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const visibleQuestions = filteredQuestions.slice(0, visibleCount);
|
||||||
|
const hasMore = visibleCount < filteredQuestions.length;
|
||||||
|
|
||||||
const handleConfess = () => {
|
const handleConfess = () => {
|
||||||
if (!confessionText.trim()) return;
|
if (!confessionText.trim()) return;
|
||||||
setConfessionPosted(true);
|
setConfessionPosted(true);
|
||||||
@@ -302,24 +306,24 @@ export default function Community() {
|
|||||||
type="text"
|
type="text"
|
||||||
placeholder="Search questions..."
|
placeholder="Search questions..."
|
||||||
value={searchQuery}
|
value={searchQuery}
|
||||||
onChange={(e) => setSearchQuery(e.target.value)}
|
onChange={(e) => { setSearchQuery(e.target.value); setVisibleCount(5); }}
|
||||||
className="w-full pl-10 pr-4 py-2.5 rounded-xl border border-slate-200 bg-white text-[13px] text-slate-800 placeholder-slate-400 focus:outline-none focus:border-slate-400 transition-colors"
|
className="w-full pl-10 pr-4 py-2.5 rounded-xl border border-slate-200 bg-white text-[13px] text-slate-800 placeholder-slate-400 focus:outline-none focus:border-slate-400 transition-colors"
|
||||||
style={{ fontFamily: 'Inter, sans-serif' }}
|
style={{ fontFamily: 'Inter, sans-serif' }}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Questions */}
|
{/* Questions */}
|
||||||
<StaggerContainer key={filteredQuestions.length} className="flex flex-col gap-4">
|
<StaggerContainer key={visibleCount + '-' + filteredQuestions.length} className="flex flex-col gap-4">
|
||||||
{filteredQuestions.map((q, idx) => {
|
{visibleQuestions.map((q, idx) => {
|
||||||
const isFeatured = idx === 0 && searchQuery === '';
|
const isFeatured = idx === 0 && searchQuery === '';
|
||||||
return (
|
return (
|
||||||
<StaggerItem key={q.id}>
|
<StaggerItem key={q.id}>
|
||||||
<motion.div
|
<motion.div
|
||||||
whileHover={{ y: -1 }}
|
whileHover={{ y: -0.5 }}
|
||||||
className={`bg-white rounded-xl border p-5 transition-all shadow-xs ${
|
className={`bg-white rounded-xl border p-5 transition-all duration-300 hover:border-slate-350 hover:shadow-[0_8px_30px_rgba(17,24,39,0.015)] ${
|
||||||
isFeatured
|
isFeatured
|
||||||
? 'border-l-4 border-l-slate-900 border-slate-200'
|
? 'border-l-2 border-l-slate-800 border-slate-200'
|
||||||
: 'border-slate-200/80'
|
: 'border-slate-200/50'
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
<div className="flex items-start gap-4">
|
<div className="flex items-start gap-4">
|
||||||
@@ -327,36 +331,36 @@ export default function Community() {
|
|||||||
<img
|
<img
|
||||||
src={getAvatar(q.author)}
|
src={getAvatar(q.author)}
|
||||||
alt={q.author}
|
alt={q.author}
|
||||||
className="w-9 h-9 rounded-lg object-cover bg-slate-100 border border-slate-100 shrink-0"
|
className="w-10 h-10 rounded-xl object-cover bg-slate-50 border border-slate-100 shrink-0"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div className="flex-1 min-w-0">
|
<div className="flex-1 min-w-0">
|
||||||
{/* Header / Meta */}
|
{/* Header / Meta */}
|
||||||
<div className="flex items-center gap-2 mb-1.5 flex-wrap">
|
<div className="flex items-center gap-2 mb-1.5 flex-wrap">
|
||||||
<span className="text-xs font-semibold text-slate-800">{q.author}</span>
|
<span className="text-xs font-bold text-slate-800 hover:text-slate-900 transition-colors" style={{ fontFamily: 'Poppins, sans-serif' }}>{q.author}</span>
|
||||||
<span className="text-[10px] text-slate-300">•</span>
|
<span className="text-[10px] text-slate-300">•</span>
|
||||||
<span className="text-[11px] text-slate-400">{getRelativeTime(q.createdAt)}</span>
|
<span className="text-[10px] text-slate-400 font-medium" style={{ fontFamily: 'Inter, sans-serif' }}>{getRelativeTime(q.createdAt)}</span>
|
||||||
{isFeatured && (
|
{isFeatured && (
|
||||||
<span className="ml-auto px-2 py-0.5 rounded text-[10px] font-bold bg-slate-900 text-white tracking-wider uppercase">★ Popular</span>
|
<span className="ml-auto bg-amber-50 text-amber-700 border border-amber-200/40 text-[9px] px-1.5 py-0.5 rounded font-semibold tracking-wide uppercase">★ Popular</span>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h3 className={`font-bold text-slate-950 mb-1 hover:text-slate-700 cursor-pointer transition-colors tracking-tight ${
|
<h3 className={`font-bold text-slate-900 mb-1 hover:text-slate-700 cursor-pointer transition-colors tracking-tight ${
|
||||||
isFeatured ? 'text-base md:text-lg' : 'text-sm md:text-base'
|
isFeatured ? 'text-base md:text-lg' : 'text-sm md:text-base'
|
||||||
}`}
|
}`}
|
||||||
style={{ fontFamily: 'Poppins, sans-serif' }}>
|
style={{ fontFamily: 'Poppins, sans-serif' }}>
|
||||||
{q.title}
|
{q.title}
|
||||||
</h3>
|
</h3>
|
||||||
<p className="text-[13px] text-slate-600 mb-4 leading-relaxed line-clamp-2" style={{ fontFamily: 'Inter, sans-serif' }}>
|
<p className="text-[13px] text-slate-650 mb-4 leading-relaxed line-clamp-2" style={{ fontFamily: 'Inter, sans-serif' }}>
|
||||||
{q.body}
|
{q.body}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div className="flex items-center justify-between flex-wrap gap-3 pt-1 border-t border-slate-100">
|
<div className="flex items-center justify-between flex-wrap gap-3 pt-1.5 border-t border-slate-100/60">
|
||||||
<div className="flex flex-wrap gap-1.5">
|
<div className="flex flex-wrap gap-1.5">
|
||||||
{(q.tags || []).map((tag) => (
|
{(q.tags || []).map((tag) => (
|
||||||
<span
|
<span
|
||||||
key={tag}
|
key={tag}
|
||||||
className="px-2.5 py-0.5 rounded-lg text-[10px] font-medium bg-slate-100 text-slate-600"
|
className="px-2 py-0.5 rounded-md text-[10px] font-medium bg-slate-50 text-slate-500 border border-slate-100/60 hover:bg-slate-100/60 hover:text-slate-700 transition-colors cursor-pointer"
|
||||||
style={{ fontFamily: 'Inter, sans-serif' }}
|
style={{ fontFamily: 'Inter, sans-serif' }}
|
||||||
>
|
>
|
||||||
#{tag}
|
#{tag}
|
||||||
@@ -364,29 +368,29 @@ export default function Community() {
|
|||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex items-center gap-4 text-[11px] text-slate-400">
|
<div className="flex items-center gap-2 text-[10px] text-slate-400 font-bold">
|
||||||
<button
|
<button
|
||||||
onClick={() => toggleAnswers(q.id)}
|
onClick={() => toggleAnswers(q.id)}
|
||||||
className={`flex items-center gap-1.5 px-2 py-1 rounded-lg transition-all cursor-pointer border-0 bg-slate-50 hover:bg-slate-100 ${
|
className={`flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg transition-all duration-200 cursor-pointer border border-slate-200/30 ${
|
||||||
expandedQuestionIds.has(q.id.toString())
|
expandedQuestionIds.has(q.id.toString())
|
||||||
? 'bg-slate-900 text-white font-semibold'
|
? 'bg-slate-900 text-white border-slate-900'
|
||||||
: 'text-slate-500 hover:text-slate-800'
|
: 'bg-slate-50 hover:bg-slate-100 text-slate-500 hover:text-slate-700'
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
<MessageCircle className="w-3.5 h-3.5" />
|
<MessageCircle className="w-3.5 h-3.5" />
|
||||||
<span>{getAnswersCount(q)} answers</span>
|
<span>{getAnswersCount(q)} answers</span>
|
||||||
</button>
|
</button>
|
||||||
{q.isAnswered && (
|
{q.isAnswered && (
|
||||||
<span className="px-2 py-0.5 rounded-lg bg-emerald-50 text-emerald-700 font-semibold text-[10px]">✓ Answered</span>
|
<span className="bg-emerald-50 text-emerald-700 border border-emerald-200/40 text-[9px] px-1.5 py-0.5 rounded font-semibold tracking-wide uppercase">✓ Answered</span>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Like/Vote Button inside bottom bar */}
|
{/* Like/Vote Button inside bottom bar */}
|
||||||
<button
|
<button
|
||||||
onClick={() => toggleLike(q.id)}
|
onClick={() => toggleLike(q.id)}
|
||||||
className={`flex items-center gap-1.5 px-2.5 py-1 rounded-lg transition-all cursor-pointer ${
|
className={`flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg transition-all duration-200 cursor-pointer border ${
|
||||||
likedIds.has(q.id.toString())
|
likedIds.has(q.id.toString())
|
||||||
? 'bg-slate-900 text-white font-semibold'
|
? 'bg-rose-50 text-rose-600 border-rose-100/60 hover:bg-rose-100/60'
|
||||||
: 'bg-slate-50 hover:bg-slate-100 text-slate-500 hover:text-slate-800'
|
: 'bg-slate-50 hover:bg-slate-100 text-slate-500 hover:text-slate-700 border-slate-200/30'
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
<ThumbsUp className="w-3 h-3" />
|
<ThumbsUp className="w-3 h-3" />
|
||||||
@@ -397,20 +401,20 @@ export default function Community() {
|
|||||||
|
|
||||||
{/* Expandable Answers Section */}
|
{/* Expandable Answers Section */}
|
||||||
{expandedQuestionIds.has(q.id.toString()) && (
|
{expandedQuestionIds.has(q.id.toString()) && (
|
||||||
<div className="mt-4 pt-4 border-t border-slate-100/80 flex flex-col gap-3">
|
<div className="mt-4 pt-4 border-t border-slate-100 flex flex-col gap-3.5 pl-3 border-l-2 border-l-slate-100">
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
<h4 className="text-xs font-bold text-slate-800 tracking-tight" style={{ fontFamily: 'Poppins, sans-serif' }}>
|
<h4 className="text-[11px] font-bold text-slate-700 tracking-tight uppercase" style={{ fontFamily: 'Poppins, sans-serif' }}>
|
||||||
Answers ({getAnswersCount(q)})
|
Answers ({getAnswersCount(q)})
|
||||||
</h4>
|
</h4>
|
||||||
</div>
|
</div>
|
||||||
{Array.isArray(q.answers) && q.answers.length > 0 ? (
|
{Array.isArray(q.answers) && q.answers.length > 0 ? (
|
||||||
<div className="flex flex-col gap-2.5 max-h-60 overflow-y-auto pr-1">
|
<div className="flex flex-col gap-2.5 max-h-60 overflow-y-auto pr-1">
|
||||||
{q.answers.map((ans: any) => (
|
{q.answers.map((ans: any) => (
|
||||||
<div key={ans.id} className="bg-slate-50/60 rounded-xl p-3.5 border border-slate-100/90 hover:border-slate-200/60 transition-all">
|
<div key={ans.id} className="bg-slate-50/50 rounded-xl p-3.5 border border-slate-100 hover:bg-slate-50/80 transition-colors">
|
||||||
<div className="flex items-center gap-2 mb-1.5 flex-wrap">
|
<div className="flex items-center gap-2 mb-1.5 flex-wrap">
|
||||||
<span className="text-[11px] font-semibold text-slate-700">{ans.author}</span>
|
<span className="text-xs font-bold text-slate-700" style={{ fontFamily: 'Poppins, sans-serif' }}>{ans.author}</span>
|
||||||
<span className="text-[9px] text-slate-300">•</span>
|
<span className="text-[9px] text-slate-300">•</span>
|
||||||
<span className="text-[10px] text-slate-400">{getRelativeTime(ans.createdAt)}</span>
|
<span className="text-[10px] text-slate-400 font-medium" style={{ fontFamily: 'Inter, sans-serif' }}>{getRelativeTime(ans.createdAt)}</span>
|
||||||
</div>
|
</div>
|
||||||
<p className="text-xs text-slate-600 leading-relaxed" style={{ fontFamily: 'Inter, sans-serif' }}>
|
<p className="text-xs text-slate-600 leading-relaxed" style={{ fontFamily: 'Inter, sans-serif' }}>
|
||||||
{ans.body}
|
{ans.body}
|
||||||
@@ -432,6 +436,40 @@ export default function Community() {
|
|||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</StaggerContainer>
|
</StaggerContainer>
|
||||||
|
|
||||||
|
{/* Load More / Show Less */}
|
||||||
|
{filteredQuestions.length > 5 && (
|
||||||
|
<div className="flex flex-col items-center gap-3 mt-6">
|
||||||
|
{hasMore ? (
|
||||||
|
<>
|
||||||
|
<p className="text-[11px] text-slate-400 font-medium" style={{ fontFamily: 'Inter, sans-serif' }}>
|
||||||
|
Showing {visibleCount} of {filteredQuestions.length} questions
|
||||||
|
</p>
|
||||||
|
<motion.button
|
||||||
|
whileHover={{ scale: 1.015 }}
|
||||||
|
whileTap={{ scale: 0.985 }}
|
||||||
|
onClick={() => setVisibleCount((c) => c + 5)}
|
||||||
|
className="flex items-center gap-2 px-5 py-2.5 rounded-xl border border-slate-200 bg-white text-slate-700 text-[13px] font-semibold hover:bg-slate-50 hover:border-slate-300 transition-all duration-200 cursor-pointer shadow-sm"
|
||||||
|
style={{ fontFamily: 'Poppins, sans-serif' }}
|
||||||
|
>
|
||||||
|
<ChevronRight className="w-4 h-4 rotate-90" />
|
||||||
|
Load More Questions
|
||||||
|
</motion.button>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<motion.button
|
||||||
|
whileHover={{ scale: 1.015 }}
|
||||||
|
whileTap={{ scale: 0.985 }}
|
||||||
|
onClick={() => setVisibleCount(5)}
|
||||||
|
className="flex items-center gap-2 px-5 py-2.5 rounded-xl border border-slate-200 bg-white text-slate-500 text-[13px] font-medium hover:bg-slate-50 hover:border-slate-300 transition-all duration-200 cursor-pointer"
|
||||||
|
style={{ fontFamily: 'Poppins, sans-serif' }}
|
||||||
|
>
|
||||||
|
<ChevronRight className="w-4 h-4 -rotate-90" />
|
||||||
|
Show Less
|
||||||
|
</motion.button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Sidebar */}
|
{/* Sidebar */}
|
||||||
@@ -555,8 +593,8 @@ export default function Community() {
|
|||||||
{CONFESSIONS_DATA.map((conf) => (
|
{CONFESSIONS_DATA.map((conf) => (
|
||||||
<StaggerItem key={conf.id}>
|
<StaggerItem key={conf.id}>
|
||||||
<motion.div
|
<motion.div
|
||||||
whileHover={{ y: -1 }}
|
whileHover={{ y: -0.5 }}
|
||||||
className="bg-white rounded-xl border border-slate-200/80 p-5 shadow-xs"
|
className="bg-white rounded-xl border border-slate-200/50 p-5 transition-all duration-300 hover:border-slate-350 hover:shadow-[0_8px_30px_rgba(17,24,39,0.015)]"
|
||||||
>
|
>
|
||||||
<div className="flex items-start justify-between mb-3">
|
<div className="flex items-start justify-between mb-3">
|
||||||
<div className="flex items-center gap-2.5">
|
<div className="flex items-center gap-2.5">
|
||||||
@@ -564,31 +602,32 @@ export default function Community() {
|
|||||||
<Shield className="w-4 h-4 text-slate-500" />
|
<Shield className="w-4 h-4 text-slate-500" />
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<span className="text-xs font-semibold text-slate-800" style={{ fontFamily: 'Poppins, sans-serif' }}>Anonymous</span>
|
<span className="text-xs font-bold text-slate-800" style={{ fontFamily: 'Poppins, sans-serif' }}>Anonymous</span>
|
||||||
<p className="text-[10px] text-slate-400">{getRelativeTime(conf.createdAt)}</p>
|
<p className="text-[10px] text-slate-400 font-medium" style={{ fontFamily: 'Inter, sans-serif' }}>{getRelativeTime(conf.createdAt)}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{conf.category && (
|
{conf.category && (
|
||||||
<span className="px-2 py-0.5 rounded text-[10px] font-bold bg-slate-50 text-slate-650 border border-slate-200/40" style={{ fontFamily: 'Poppins, sans-serif' }}>
|
<span className="px-2 py-0.5 rounded text-[10px] font-semibold bg-slate-55 text-slate-650 border border-slate-200/40" style={{ fontFamily: 'Poppins, sans-serif' }}>
|
||||||
{conf.category}
|
{conf.category}
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<p className="text-[13px] text-slate-700 leading-relaxed mb-4" style={{ fontFamily: 'Inter, sans-serif' }}>{conf.content}</p>
|
<p className="text-[13px] text-slate-750 leading-relaxed mb-4" style={{ fontFamily: 'Inter, sans-serif' }}>{conf.content}</p>
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
<button
|
<button
|
||||||
onClick={() => toggleLike(conf.id)}
|
onClick={() => toggleLike(conf.id)}
|
||||||
className={`flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg transition-all cursor-pointer ${
|
className={`flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg transition-all duration-200 cursor-pointer border text-[10px] font-bold ${
|
||||||
likedIds.has(conf.id)
|
likedIds.has(conf.id)
|
||||||
? 'bg-slate-900 text-white'
|
? 'bg-rose-50 text-rose-600 border-rose-100/60 hover:bg-rose-100/60'
|
||||||
: 'bg-slate-50 hover:bg-slate-100 text-slate-500'
|
: 'bg-slate-50 hover:bg-slate-100 text-slate-500 hover:text-slate-700 border-slate-200/30'
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
<Heart
|
<Heart
|
||||||
className="w-3.5 h-3.5"
|
className="w-3.5 h-3.5"
|
||||||
fill={likedIds.has(conf.id) ? '#ffffff' : 'none'}
|
fill={likedIds.has(conf.id) ? '#e11d48' : 'none'}
|
||||||
|
color={likedIds.has(conf.id) ? '#e11d48' : 'currentColor'}
|
||||||
/>
|
/>
|
||||||
<span className="text-xs">{conf.reactions + (likedIds.has(conf.id) ? 1 : 0)}</span>
|
<span>{conf.reactions + (likedIds.has(conf.id) ? 1 : 0)}</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</motion.div>
|
</motion.div>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"telegram_bot_token": "8859374355:AAH0dhwstkTBhRerRTjzmb2RG2fjPbigzvo",
|
"telegram_bot_token": "8859374355:AAH0dhwstkTBhRerRTjzmb2RG2fjPbigzvo",
|
||||||
"helper_chat_ids": [971749136],
|
"helper_chat_ids": [971749136,5567776672],
|
||||||
"spring_backend_url": "http://localhost:8080"
|
"spring_backend_url": "http://localhost:8080"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user