Skip to content

Commit 911b4cc

Browse files
authored
feat(feed,tracker): default feed group to science and support common optional subjects in tracker (#433)
* feat(feed,tracker): default feed group to science and support common optional subjects in tracker * style(feed): align feed vote button designs, enhance blog share, and clean sidebar note library text
1 parent a16c60a commit 911b4cc

7 files changed

Lines changed: 269 additions & 128 deletions

File tree

‎app/Http/Controllers/HomeController.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class HomeController extends Controller
1919
public function index(Request $request)
2020
{
2121
$course = in_array($request->query('course'), ['hsc', 'ssc'], true) ? $request->query('course') : 'hsc';
22-
$group = in_array($request->query('group'), ['science', 'commerce', 'humanities'], true) ? $request->query('group') : null;
22+
$group = in_array($request->query('group'), ['science', 'commerce', 'humanities'], true) ? $request->query('group') : 'science';
2323
$sort = in_array($request->query('sort'), ['trending', 'recent'], true) ? $request->query('sort') : 'trending';
2424
$page = max(1, (int) $request->query('page', 1));
2525

@@ -48,14 +48,14 @@ public function index(Request $request)
4848
public function feed(Request $request)
4949
{
5050
$course = in_array($request->query('course'), ['hsc', 'ssc'], true) ? $request->query('course') : 'hsc';
51-
$group = in_array($request->query('group'), ['science', 'commerce', 'humanities'], true) ? $request->query('group') : null;
51+
$group = in_array($request->query('group'), ['science', 'commerce', 'humanities'], true) ? $request->query('group') : 'science';
5252
$sort = in_array($request->query('sort'), ['trending', 'recent'], true) ? $request->query('sort') : 'trending';
5353
$page = max(1, (int) $request->query('page', 1));
5454

5555
return response()->json($this->getFeed($course, $group, $sort, $page));
5656
}
5757

58-
private function getFeed(string $course, ?string $group, string $sort, int $page = 1): array
58+
private function getFeed(string $course, string $group, string $sort, int $page = 1): array
5959
{
6060
$page = max(1, $page);
6161
$currentUserId = Auth::id();

‎resources/js/components/blogs/BlogFeedCard.vue‎

Lines changed: 102 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
<script setup lang="ts">
22
import { Link, router } from '@inertiajs/vue3';
3-
import { Check, Eye, Heart, MessageSquare, Share2 } from 'lucide-vue-next';
3+
import {
4+
Check,
5+
Eye,
6+
Heart,
7+
Loader2,
8+
MessageSquare,
9+
Share2,
10+
} from 'lucide-vue-next';
411
import { ref, watch } from 'vue';
512
613
import VerifiedBadge from '@/components/VerifiedBadge.vue';
714
import { useAppreciation } from '@/lib/useAppreciation';
815
import { useAuth } from '@/lib/useAuth';
16+
import { getCsrfToken } from '@/lib/useCsrf';
917
import { formatTimeAgo } from '@/lib/useDate';
1018
1119
interface User {
@@ -166,18 +174,92 @@ const toggleAppreciation = () => {
166174
};
167175
168176
const copied = ref(false);
177+
const isSharing = ref(false);
169178
170-
const copyLink = async () => {
171-
const url = `${window.location.origin}/blogs/${props.blog.slug}`;
179+
const shareBlog = async () => {
180+
if (isSharing.value) {
181+
return;
182+
}
183+
184+
isSharing.value = true;
185+
186+
const originalUrl = `${window.location.origin}/blogs/${props.blog.slug}`;
187+
let finalUrl = originalUrl;
172188
173189
try {
174-
await navigator.clipboard.writeText(url);
190+
const res = await fetch('/api/short-urls', {
191+
method: 'POST',
192+
headers: {
193+
'Content-Type': 'application/json',
194+
Accept: 'application/json',
195+
'X-XSRF-TOKEN': getCsrfToken(),
196+
'X-Requested-With': 'XMLHttpRequest',
197+
},
198+
credentials: 'same-origin',
199+
body: JSON.stringify({
200+
original_url: originalUrl,
201+
}),
202+
});
203+
204+
if (res.ok) {
205+
const data = await res.json();
206+
207+
if (data.short_url) {
208+
finalUrl = data.short_url;
209+
}
210+
}
211+
} catch {
212+
// Fallback to original URL
213+
} finally {
214+
isSharing.value = false;
215+
}
216+
217+
if (navigator.share) {
218+
try {
219+
await navigator.share({
220+
title: props.blog.title,
221+
url: finalUrl,
222+
});
223+
copied.value = true;
224+
setTimeout(() => {
225+
copied.value = false;
226+
}, 2500);
227+
228+
return;
229+
} catch {
230+
// fallback to clipboard
231+
}
232+
}
233+
234+
try {
235+
if (navigator.clipboard && window.isSecureContext) {
236+
await navigator.clipboard.writeText(finalUrl);
237+
} else {
238+
throw new Error('Clipboard API unavailable');
239+
}
240+
175241
copied.value = true;
176242
setTimeout(() => {
177243
copied.value = false;
178-
}, 2000);
244+
}, 2500);
179245
} catch {
180-
// fallback
246+
try {
247+
const textarea = document.createElement('textarea');
248+
textarea.value = finalUrl;
249+
textarea.style.position = 'fixed';
250+
textarea.style.opacity = '0';
251+
document.body.appendChild(textarea);
252+
textarea.focus();
253+
textarea.select();
254+
document.execCommand('copy');
255+
document.body.removeChild(textarea);
256+
copied.value = true;
257+
setTimeout(() => {
258+
copied.value = false;
259+
}, 2500);
260+
} catch {
261+
// fallback failed
262+
}
181263
}
182264
};
183265
</script>
@@ -327,7 +409,7 @@ const copyLink = async () => {
327409
<!-- Featured Image (Attached image preview below excerpt) -->
328410
<div
329411
v-if="blog.featured_image || blog.featured_image_path"
330-
class="dark:bg-gray-850 mt-3 max-h-80 overflow-hidden rounded-xl border border-slate-200/80 bg-slate-50 dark:border-gray-800"
412+
class="mt-3 max-h-80 overflow-hidden rounded-xl border border-slate-200/80 bg-slate-50 dark:border-gray-800 dark:bg-gray-800/50"
331413
>
332414
<img
333415
:src="blog.featured_image || blog.featured_image_path || ''"
@@ -355,7 +437,7 @@ const copyLink = async () => {
355437
:class="[
356438
isReacted
357439
? 'border-rose-200 bg-rose-50/90 text-rose-700 dark:border-rose-900/60 dark:bg-rose-950/40 dark:text-rose-300'
358-
: 'dark:bg-gray-850 border-slate-200/80 bg-slate-50/70 text-slate-700 hover:border-slate-300 hover:bg-slate-100 dark:border-gray-800 dark:text-gray-300 dark:hover:bg-gray-800',
440+
: 'border-slate-200/80 bg-slate-50/70 text-slate-700 hover:border-slate-300 hover:bg-slate-100 dark:border-gray-800 dark:bg-gray-800/60 dark:text-gray-300 dark:hover:bg-gray-800',
359441
]"
360442
:title="isReacted ? 'রিঅ্যাক্ট সরান' : 'লাভ রিঅ্যাক্ট দিন'"
361443
>
@@ -372,7 +454,7 @@ const copyLink = async () => {
372454

373455
<Link
374456
:href="`/blogs/${blog.slug}#comments`"
375-
class="dark:bg-gray-850 inline-flex items-center gap-1.5 rounded-xl border border-slate-200/80 bg-slate-50/70 px-2.5 py-1 text-xs font-semibold text-slate-700 transition hover:border-slate-300 hover:bg-slate-100 dark:border-gray-800 dark:text-gray-300 dark:hover:bg-gray-800"
457+
class="inline-flex items-center gap-1.5 rounded-xl border border-slate-200/80 bg-slate-50/70 px-2.5 py-1 text-xs font-semibold text-slate-700 transition hover:border-slate-300 hover:bg-slate-100 dark:border-gray-800 dark:bg-gray-800/60 dark:text-gray-300 dark:hover:bg-gray-800"
376458
>
377459
<MessageSquare
378460
class="h-3.5 w-3.5 text-purple-600 dark:text-purple-400"
@@ -392,19 +474,26 @@ const copyLink = async () => {
392474
<div class="flex items-center gap-2" @click.stop>
393475
<button
394476
type="button"
395-
@click="copyLink"
396-
class="dark:bg-gray-850 inline-flex cursor-pointer items-center gap-1.5 rounded-xl border border-slate-200/80 bg-slate-50/70 px-3 py-1.5 text-xs font-semibold text-slate-600 transition hover:border-slate-300 hover:bg-slate-100 dark:border-gray-800 dark:text-gray-300 dark:hover:bg-gray-800"
477+
@click="shareBlog"
478+
:disabled="isSharing"
479+
class="inline-flex cursor-pointer items-center gap-1.5 rounded-xl border border-slate-200/80 bg-slate-50/70 px-3 py-1.5 text-xs font-semibold text-slate-600 transition hover:border-slate-300 hover:bg-slate-100 disabled:cursor-wait disabled:opacity-75 dark:border-gray-800 dark:bg-gray-800/60 dark:text-gray-300 dark:hover:bg-gray-800"
397480
title="Share blog"
398481
>
482+
<Loader2
483+
v-if="isSharing"
484+
class="h-3.5 w-3.5 animate-spin text-indigo-600 dark:text-indigo-400"
485+
/>
399486
<Check
400-
v-if="copied"
487+
v-else-if="copied"
401488
class="h-3.5 w-3.5 text-emerald-600 dark:text-emerald-400"
402489
/>
403490
<Share2
404491
v-else
405492
class="h-3.5 w-3.5 text-slate-500 dark:text-gray-400"
406493
/>
407-
<span>{{ copied ? 'Copied' : 'Share' }}</span>
494+
<span>{{
495+
isSharing ? 'Copying...' : copied ? 'Copied' : 'Share'
496+
}}</span>
408497
</button>
409498
</div>
410499
</div>

‎resources/js/components/forum/ForumFeedCard.vue‎

Lines changed: 56 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,34 @@ const sharePost = async () => {
182182
}
183183
184184
try {
185-
await navigator.clipboard.writeText(finalUrl);
185+
if (navigator.clipboard && window.isSecureContext) {
186+
await navigator.clipboard.writeText(finalUrl);
187+
} else {
188+
throw new Error('Clipboard API unavailable');
189+
}
190+
186191
copied.value = true;
187192
setTimeout(() => {
188193
copied.value = false;
189194
}, 2500);
190195
} catch {
191-
// silent fail
196+
try {
197+
const textarea = document.createElement('textarea');
198+
textarea.value = finalUrl;
199+
textarea.style.position = 'fixed';
200+
textarea.style.opacity = '0';
201+
document.body.appendChild(textarea);
202+
textarea.focus();
203+
textarea.select();
204+
document.execCommand('copy');
205+
document.body.removeChild(textarea);
206+
copied.value = true;
207+
setTimeout(() => {
208+
copied.value = false;
209+
}, 2500);
210+
} catch {
211+
// silent fail
212+
}
192213
}
193214
};
194215
</script>
@@ -306,26 +327,32 @@ const sharePost = async () => {
306327
</div>
307328
</div>
308329
</div>
309-
310-
<!-- Subject Pill -->
311-
<div v-if="post.subject" class="shrink-0" @click.stop>
312-
<Link
313-
:href="`/forum?subject_id=${post.subject.id}`"
314-
class="dark:hover:bg-gray-750 rounded-lg bg-slate-100/90 px-2.5 py-1 text-xs font-medium text-slate-600 transition hover:bg-slate-200 hover:text-slate-900 dark:bg-gray-800 dark:text-gray-300"
315-
>
316-
{{ post.subject.name }}
317-
</Link>
318-
</div>
319330
</div>
320331

321332
<!-- 2. Body: Content with preserved newlines -->
322333
<div class="mt-3">
323-
<!-- Chapter subtitle above question body -->
334+
<!-- Chapter & Subject Subtitle above question body -->
324335
<div
325-
v-if="post.node"
326-
class="mb-1.5 truncate text-xs font-medium text-slate-500 dark:text-gray-400"
336+
v-if="post.node || post.subject"
337+
class="mb-1.5 flex items-center gap-1.5 truncate text-xs font-medium text-slate-500 dark:text-gray-400"
327338
>
328-
{{ post.node.name }}
339+
<span
340+
v-if="post.node"
341+
class="truncate font-medium text-slate-600 dark:text-gray-300"
342+
>
343+
{{ post.node.name }}
344+
</span>
345+
<template v-if="post.node && post.subject">
346+
<span class="text-slate-300 dark:text-gray-600">•</span>
347+
</template>
348+
<Link
349+
v-if="post.subject"
350+
:href="`/forum?subject_id=${post.subject.id}`"
351+
@click.stop
352+
class="shrink-0 transition hover:text-indigo-600 dark:hover:text-indigo-400"
353+
>
354+
{{ post.subject.name }}
355+
</Link>
329356
</div>
330357

331358
<p
@@ -337,7 +364,7 @@ const sharePost = async () => {
337364
<!-- Optional Attached Image -->
338365
<div
339366
v-if="post.image_url || post.image_path"
340-
class="dark:bg-gray-850 mt-3 max-h-80 overflow-hidden rounded-xl border border-slate-200/80 bg-slate-50 dark:border-gray-800"
367+
class="mt-3 max-h-80 overflow-hidden rounded-xl border border-slate-200/80 bg-slate-50 dark:border-gray-800 dark:bg-gray-800/50"
341368
>
342369
<img
343370
:src="post.image_url || '/storage/' + post.image_path"
@@ -353,25 +380,21 @@ const sharePost = async () => {
353380
class="mt-4 flex flex-wrap items-center justify-between gap-2.5 border-t border-slate-100 pt-3 dark:border-gray-800/80"
354381
>
355382
<div class="flex flex-wrap items-center gap-2" @click.stop>
356-
<!-- Horizontal Vote Pill -->
357-
<div
358-
class="dark:ring-gray-750 inline-flex items-center rounded-xl bg-slate-50 p-0.5 ring-1 ring-slate-200/70 dark:bg-gray-800/80"
359-
>
360-
<ForumVoteButtons
361-
votableType="post"
362-
:votableId="post.id"
363-
:initialUpvotes="post.upvotes_count || 0"
364-
:initialDownvotes="post.downvotes_count || 0"
365-
:initialUserVote="post.user_vote"
366-
direction="horizontal"
367-
size="sm"
368-
/>
369-
</div>
383+
<ForumVoteButtons
384+
votableType="post"
385+
:votableId="post.id"
386+
:initialUpvotes="post.upvotes_count || 0"
387+
:initialDownvotes="post.downvotes_count || 0"
388+
:initialUserVote="post.user_vote"
389+
direction="horizontal"
390+
size="sm"
391+
variant="boxed"
392+
/>
370393

371394
<!-- Answer Count Button -->
372395
<Link
373396
:href="`/forum/questions/${post.slug}#answers`"
374-
class="dark:bg-gray-850 inline-flex items-center gap-1.5 rounded-xl border border-slate-200/80 bg-slate-50/70 px-3 py-1.5 text-xs font-semibold text-slate-700 transition hover:border-slate-300 hover:bg-slate-100 dark:border-gray-800 dark:text-gray-300 dark:hover:bg-gray-800"
397+
class="inline-flex items-center gap-1.5 rounded-xl border border-slate-200/80 bg-slate-50/70 px-3 py-1.5 text-xs font-semibold text-slate-700 transition hover:border-slate-300 hover:bg-slate-100 dark:border-gray-800 dark:bg-gray-800/60 dark:text-gray-300 dark:hover:bg-gray-800"
375398
>
376399
<MessageSquare
377400
class="h-3.5 w-3.5 text-purple-600 dark:text-purple-400"
@@ -386,7 +409,7 @@ const sharePost = async () => {
386409
type="button"
387410
@click="sharePost"
388411
:disabled="isSharing"
389-
class="dark:bg-gray-850 inline-flex cursor-pointer items-center gap-1.5 rounded-xl border border-slate-200/80 bg-slate-50/70 px-3 py-1.5 text-xs font-semibold text-slate-600 transition hover:border-slate-300 hover:bg-slate-100 disabled:cursor-wait disabled:opacity-75 dark:border-gray-800 dark:text-gray-300 dark:hover:bg-gray-800"
412+
class="inline-flex cursor-pointer items-center gap-1.5 rounded-xl border border-slate-200/80 bg-slate-50/70 px-3 py-1.5 text-xs font-semibold text-slate-600 transition hover:border-slate-300 hover:bg-slate-100 disabled:cursor-wait disabled:opacity-75 dark:border-gray-800 dark:bg-gray-800/60 dark:text-gray-300 dark:hover:bg-gray-800"
390413
title="Share question"
391414
>
392415
<Loader2

0 commit comments

Comments
 (0)