Skip to content
Merged
Show file tree
Hide file tree
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
48 changes: 36 additions & 12 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,23 +154,47 @@ private function getFeed(string $course, string $group, string $sort, int $page
}
}

$posts = $postsQuery->forPage($page, 6)->get()->map(function ($p) {
$p->feed_type = 'forum_post';
// For guests (public traffic), cache base query results for 3 minutes to avoid computing time-decay on every load
if (! $currentUserId) {
$cacheKey = "home_feed_base:{$course}:{$group}:{$sort}:{$page}";
[$posts, $resources, $blogs] = Cache::remember($cacheKey, now()->addMinutes(3), function () use ($postsQuery, $resourcesQuery, $blogsQuery, $page) {
$p = $postsQuery->forPage($page, 6)->get()->map(function ($item) {
$item->feed_type = 'forum_post';

return $item;
});
$r = $resourcesQuery->forPage($page, 4)->get()->map(function ($item) {
$item->feed_type = 'resource';

return $p;
});
return $item;
});
$b = $blogsQuery->forPage($page, 2)->get()->map(function ($item) {
$item->feed_type = 'blog';

$resources = $resourcesQuery->forPage($page, 4)->get()->map(function ($r) {
$r->feed_type = 'resource';
return $item;
});

return $r;
});
return [$p, $r, $b];
});
} else {
$posts = $postsQuery->forPage($page, 6)->get()->map(function ($p) {
$p->feed_type = 'forum_post';

$blogs = $blogsQuery->forPage($page, 2)->get()->map(function ($b) {
$b->feed_type = 'blog';
return $p;
});

return $b;
});
$resources = $resourcesQuery->forPage($page, 4)->get()->map(function ($r) {
$r->feed_type = 'resource';

return $r;
});

$blogs = $blogsQuery->forPage($page, 2)->get()->map(function ($b) {
$b->feed_type = 'blog';

return $b;
});
}

// Compute is_appreciated and user_vote if logged in
$userId = Auth::id();
Expand Down
53 changes: 31 additions & 22 deletions app/Http/Controllers/UserProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,28 @@ public function show(string $username)
? $user->appreciationsReceived()->where('appreciator_id', auth()->id())->exists()
: false;

// Suggested members: 1 contributors + 3 general users
$contributorUsers = User::where('id', '!=', $user->id)
->whereNotNull('username')
->where('is_verified', true)
->select(['id', 'name', 'username', 'institution', 'image_path', 'about', 'is_verified'])
->inRandomOrder()
->take(1)
->get();

$excludedIds = $contributorUsers->pluck('id')->push($user->id)->all();
$remainingNeeded = 4 - $contributorUsers->count();

$randomUsers = User::whereNotIn('id', $excludedIds)
->whereNotNull('username')
->select(['id', 'name', 'username', 'institution', 'image_path', 'about', 'is_verified'])
->inRandomOrder()
->take($remainingNeeded)
->get();

$suggestedUsers = $contributorUsers->concat($randomUsers)->shuffle()->values();
// Suggested members: 1 contributor + 3 general users (cached for 10 minutes to avoid expensive inRandomOrder queries)
$suggestedUsers = Cache::remember("suggested_users_profile_{$user->id}", now()->addMinutes(10), function () use ($user) {
$contributorUsers = User::where('id', '!=', $user->id)
->whereNotNull('username')
->where('is_verified', true)
->select(['id', 'name', 'username', 'institution', 'image_path', 'about', 'is_verified'])
->inRandomOrder()
->take(1)
->get();

$excludedIds = $contributorUsers->pluck('id')->push($user->id)->all();
$remainingNeeded = 4 - $contributorUsers->count();

$randomUsers = User::whereNotIn('id', $excludedIds)
->whereNotNull('username')
->select(['id', 'name', 'username', 'institution', 'image_path', 'about', 'is_verified'])
->inRandomOrder()
->take($remainingNeeded)
->get();

return $contributorUsers->concat($randomUsers)->shuffle()->values();
});

$isOwner = auth()->id() === $user->id;
$activityPrivacy = $user->activity_privacy ?? 'public';
Expand Down Expand Up @@ -174,7 +176,14 @@ public function show(string $username)
->take(5)
->get();

$syllabusProgress = $this->getSyllabusProgress($user);
// Cache the heavy analytical stats (heatmap & syllabus progress) for 5 minutes per user
$studyHeatmap = Cache::remember("user_heatmap_{$user->id}", now()->addMinutes(5), function () use ($user) {
return DailyStudyLog::getHeatmapAndStatsForUser($user);
});

$syllabusProgress = Cache::remember("user_syllabus_{$user->id}", now()->addMinutes(5), function () use ($user) {
return $this->getSyllabusProgress($user);
});

return Inertia::render('User/Show', [
'profileUser' => $profileUser,
Expand All @@ -192,7 +201,7 @@ public function show(string $username)
'notes' => $notes,
'suggestedUsers' => $suggestedUsers,
'pokeData' => $pokeData,
'studyHeatmap' => DailyStudyLog::getHeatmapAndStatsForUser($user),
'studyHeatmap' => $studyHeatmap,
'syllabusProgress' => $syllabusProgress,
]);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Spatie\Permission\Models\Permission;
use Spatie\Permission\Models\Role;
use Spatie\Permission\PermissionRegistrar;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
app()[PermissionRegistrar::class]->forgetCachedPermissions();

$permission = Permission::findOrCreate('manage reports', 'web');

$admin = Role::where('name', 'admin')->where('guard_name', 'web')->first();
if ($admin) {
$admin->givePermissionTo($permission);
}
}

/**
* Reverse the migrations.
*/
public function down(): void
{
app()[PermissionRegistrar::class]->forgetCachedPermissions();

$permission = Permission::where('name', 'manage reports')->where('guard_name', 'web')->first();
if ($permission) {
$permission->delete();
}
}
};
2 changes: 1 addition & 1 deletion resources/js/components/Footer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ import AppLogo from './AppLogo.vue';
<BookOpen
class="h-4 w-4 text-indigo-500 dark:text-indigo-400"
/>
<span>Documentation</span>
<span>User Guide</span>
</Link>
</li>
<li>
Expand Down
66 changes: 38 additions & 28 deletions resources/js/components/navigation/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -600,31 +600,6 @@ export const SiteRail = defineComponent({
<span class="ml-auto h-1.5 w-1.5 shrink-0 rounded-full bg-indigo-600 dark:bg-indigo-400" />
)}
</Link>
<Link
href="/join"
class={[
'group flex h-10 items-center gap-3 rounded-[10px] px-3 text-[13px] font-medium tracking-tight transition-colors duration-150',
isActive('/join')
? 'bg-indigo-50 text-indigo-700 ring-1 ring-indigo-200/60 dark:bg-indigo-500/10 dark:text-indigo-200 dark:ring-indigo-500/20'
: 'text-slate-600 hover:bg-slate-100/80 hover:text-slate-900 dark:text-slate-400 dark:hover:bg-slate-800/70 dark:hover:text-slate-100',
]}
>
<MaterialIcon
name="person_add"
size={22}
class={`shrink-0 transition-colors duration-150 ${
isActive('/join')
? 'text-indigo-600 dark:text-indigo-300'
: 'text-slate-500 group-hover:text-slate-700 dark:text-slate-500 dark:group-hover:text-slate-300'
}`}
/>
<span class="truncate">
Join Our Team
</span>
{isActive('/join') && (
<span class="ml-auto h-1.5 w-1.5 shrink-0 rounded-full bg-indigo-600 dark:bg-indigo-400" />
)}
</Link>
<Link
href="/products"
class={[
Expand All @@ -651,6 +626,28 @@ export const SiteRail = defineComponent({
)}
</Link>
</div>
<div class="mt-3 flex flex-wrap items-center gap-x-2 gap-y-1 px-3 text-[11px] font-medium text-slate-400 dark:text-slate-500">
<Link
href="/guide"
class="transition-colors hover:text-indigo-600 dark:hover:text-indigo-400"
>
নির্দেশিকা
</Link>
<span>·</span>
<Link
href="/support"
class="transition-colors hover:text-indigo-600 dark:hover:text-indigo-400"
>
সহায়তা
</Link>
<span>·</span>
<Link
href="/donate"
class="transition-colors hover:text-rose-600 dark:hover:text-rose-400"
>
ডোনেট
</Link>
</div>
</div>
</nav>
)}
Expand Down Expand Up @@ -1088,9 +1085,22 @@ export const SiteDrawer = defineComponent({
?.has_unread_blogs,
),
);
const drawerNavItems = computed(() =>
allNavItems.filter((item) => !item.showInBottom),
);
const drawerNavItems = computed(() => {
const items = allNavItems.filter((item) => !item.showInBottom);

// Ensure Platform Guide is first in the phone drawer
return items.sort((a, b) => {
if (a.href === '/guide') {
return -1;
}

if (b.href === '/guide') {
return 1;
}

return 0;
});
});

const showLogoutModal = ref(false);
const isProfileMenuOpen = ref(false);
Expand Down
13 changes: 4 additions & 9 deletions resources/js/layouts/AppLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ const showBottomNav = computed(() =>
isHydrated.value ? isMobile.value || !isLandscape.value : false,
);

// Whitelisted pages that show the marketing footer on desktop
const DESKTOP_FOOTER_COMPONENTS = new Set([
// Whitelisted pages that show the marketing footer (static and discovery pages)
const STATIC_FOOTER_COMPONENTS = new Set([
'Blog/Index',
'Donate',
'Projects',
Expand All @@ -49,13 +49,8 @@ const DESKTOP_FOOTER_COMPONENTS = new Set([
]);

const showFooter = computed(() => {
// Never show full-width footer on mobile / bottom nav viewports
if (showBottomNav.value) {
return false;
}

// Desktop: only show on finite content pages, not infinite scroll feeds
return DESKTOP_FOOTER_COMPONENTS.has(page.component);
// Only show footer on finite/static pages (never on infinite-scroll feeds: Feed, Notes, Forum)
return STATIC_FOOTER_COMPONENTS.has(page.component);
});

const railCollapsed = ref(false);
Expand Down
36 changes: 20 additions & 16 deletions resources/js/lib/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export const primaryNavItems: NavItem[] = [
labelBn: 'হোম',
href: '/',
icon: 'home',
match: (url) => url === '/' || url.startsWith('/feed'),
match: (url) =>
url === '/' || url.startsWith('/?') || url.startsWith('/feed'),
showInBottom: true,
},
{
Expand Down Expand Up @@ -43,13 +44,6 @@ export const primaryNavItems: NavItem[] = [
match: (url) => url.startsWith('/leaderboard'),
showInBottom: true,
},
{
label: 'Blogs',
href: '/blogs',
icon: 'menu_book',
match: (url) => url.startsWith('/blogs'),
showInBottom: false,
},
{
label: 'Forum',
href: '/forum',
Expand All @@ -65,6 +59,13 @@ export const primaryNavItems: NavItem[] = [
match: (url) => url.startsWith('/chat'),
showInBottom: true,
},
{
label: 'Blogs',
href: '/blogs',
icon: 'menu_book',
match: (url) => url.startsWith('/blogs'),
showInBottom: false,
},
{
label: 'Peers',
labelBn: 'সহপাঠী (Peers)',
Expand All @@ -75,13 +76,21 @@ export const primaryNavItems: NavItem[] = [
showInNavRail: false,
},
{
label: 'AI',
label: 'HSCStack AI',
labelBn: 'HSCStack AI',
href: '/ai',
icon: 'smart_toy',
match: (url) => url.startsWith('/ai'),
showInBottom: false,
},
{
label: 'Donate',
labelBn: 'ডোনেট করুন',
href: '/donate',
icon: 'volunteer_activism',
match: (url) => url.startsWith('/donate'),
showInBottom: false,
},
];

export const overflowNavItems: NavItem[] = [
Expand All @@ -91,20 +100,15 @@ export const overflowNavItems: NavItem[] = [
href: '/guide',
icon: 'menu_book',
match: (url) => url.startsWith('/guide'),
showInNavRail: false,
},
{
label: 'Support Center',
labelBn: 'সাপোর্ট সেন্টার',
href: '/support',
icon: 'help',
match: (url) => url.startsWith('/support'),
},
{
label: 'Donate',
labelBn: 'ডোনেট করুন',
href: '/donate',
icon: 'volunteer_activism',
match: (url) => url.startsWith('/donate'),
showInNavRail: false,
},
];

Expand Down
4 changes: 2 additions & 2 deletions resources/js/pages/ContributorGuide.vue
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ onUnmounted(() => {
<h3
class="text-xs font-bold tracking-wide text-slate-900 uppercase sm:text-sm dark:text-white"
>
📱 অ্যান্ড্রয়েড (Chrome):
অ্যান্ড্রয়েড (Chrome):
</h3>
<p
class="text-xs leading-relaxed text-slate-500 dark:text-gray-400"
Expand All @@ -937,7 +937,7 @@ onUnmounted(() => {
<h3
class="text-xs font-bold tracking-wide text-slate-900 uppercase sm:text-sm dark:text-white"
>
🍏 আইফোন (Safari):
আইফোন (Safari):
</h3>
<p
class="text-xs leading-relaxed text-slate-500 dark:text-gray-400"
Expand Down
Loading
Loading