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
6 changes: 5 additions & 1 deletion app/Http/Controllers/Admin/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ public function handleGoogleCallback(Request $request)
Auth::login($user, remember: true);
$request->session()->regenerate();

$redirect = redirect()->intended(route('profile.edit'));
$defaultUrl = $user->username
? route('user.profile', $user->username)
: route('profile.edit');

$redirect = redirect()->intended($defaultUrl);

if ($isNewUser) {
$redirect->with('success', 'Account not found. New account created.');
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/BlogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function show(Blog $blog)
$reactionsCount = $blog->reactions()->count();

$reactors = $blog->reactions()
->with(['user:id,name,username,image_path,institution', 'user.roles:id,name'])
->with(['user:id,name,username,image_path,institution'])
->latest('id')
->limit(50)
->get()
Expand All @@ -71,7 +71,7 @@ public function show(Blog $blog)
->values();

$comments = $blog->comments()
->with(['user:id,name,username,image_path,institution', 'user.roles:id,name'])
->with(['user:id,name,username,image_path,institution'])
->latest()
->get();

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/ResourceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function show($id)
$completionsCount = ResourceCompletion::where('resource_id', $id)->count();

$completers = ResourceCompletion::where('resource_id', $id)
->with(['user:id,name,username,image_path,institution', 'user.roles:id,name'])
->with(['user:id,name,username,image_path,institution'])
->latest()
->take(10)
->get()
Expand Down
67 changes: 46 additions & 21 deletions app/Http/Controllers/UserProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ public function show(string $username)
$user = User::where('username', $username)
->firstOrFail();

$user->load('roles:id,name');

// Study Completions
$completedResourcesCount = $user->completedResources()->count();
$recentCompletions = $user->completedResources()
Expand All @@ -40,7 +38,7 @@ public function show(string $username)
->get();
$blogsCount = $user->blogs()->where('is_published', true)->count();
$totalBlogViews = (int) $user->blogs()->where('is_published', true)->sum('views');
$totalBlogLikes = BlogReaction::whereIn('blog_id', $user->blogs()->where('is_published', true)->select('id'))->count();
$upvotesCount = NodeVote::where('user_id', $user->id)->where('type', 'up')->count();
$sharedResourcesCount = Resource::where('user_id', $user->id)->count();

// Appreciations (Received & Given)
Expand All @@ -52,23 +50,45 @@ public function show(string $username)

$appreciators = $user->appreciators()
->select(['users.id', 'users.name', 'users.username', 'users.image_path', 'users.institution', 'users.title'])
->with('roles:id,name')
->latest('user_appreciations.id')
->take(50)
->inRandomOrder()
->take(30)
->get();

$appreciating = $user->appreciatingUsers()
->select(['users.id', 'users.name', 'users.username', 'users.image_path', 'users.institution', 'users.title'])
->with('roles:id,name')
->latest('user_appreciations.id')
->take(50)
->inRandomOrder()
->take(30)
->get();

// Recent Community Activities (Uploads, completed topics, comments made, reactions given, upvoted folders, appreciations given)
// Recent Community Activities (Folders created, uploads, completed topics, comments made, reactions given, upvoted folders, appreciations given)
$recentFolders = Node::where('user_id', $user->id)
->with([
'subject:id,name,slug',
'parent:id,name,slug',
'parent.parent:id,name,slug',
])
->latest('id')
->take(3)
->get()
->map(function ($node) {
$url = $this->buildNodeUrl($node);

return [
'type' => 'folder',
'title' => $node->name,
'subtitle' => $node->subject?->name.($node->parent ? ' · '.$node->parent->name : ''),
'url' => $url,
'created_at' => $node->created_at?->diffForHumans(),
'timestamp' => $node->created_at?->timestamp ?? 0,
];
})
->filter()
->values();

$recentUploads = Resource::where('user_id', $user->id)
->with(['node:id,name,subject_id', 'node.subject:id,name'])
->latest()
->take(4)
->take(3)
->get()
->map(fn ($item) => [
'type' => 'upload',
Expand All @@ -77,46 +97,50 @@ public function show(string $username)
'resource_type' => $item->resource_type,
'url' => "/resources/{$item->id}",
'created_at' => $item->created_at?->diffForHumans(),
'timestamp' => $item->created_at?->timestamp ?? 0,
]);

$recentCompleted = ResourceCompletion::where('user_id', $user->id)
->with(['resource:id,title,node_id', 'resource.node:id,name,subject_id', 'resource.node.subject:id,name'])
->latest()
->take(4)
->take(3)
->get()
->map(fn ($item) => [
'type' => 'completion',
'title' => $item->resource?->title,
'subtitle' => $item->resource?->node?->subject?->name.' · '.$item->resource?->node?->name,
'url' => $item->resource ? "/resources/{$item->resource->id}" : null,
'created_at' => $item->created_at?->diffForHumans(),
'timestamp' => $item->created_at?->timestamp ?? 0,
])
->filter(fn ($item) => $item['title'] !== null);

$recentReactions = BlogReaction::where('user_id', $user->id)
->with('blog:id,title,slug')
->latest()
->take(4)
->take(3)
->get()
->map(fn ($item) => [
'type' => 'reaction',
'title' => $item->blog?->title,
'url' => $item->blog ? "/blogs/{$item->blog->slug}" : null,
'created_at' => $item->created_at?->diffForHumans(),
'timestamp' => $item->created_at?->timestamp ?? 0,
])
->filter(fn ($item) => $item['title'] !== null);

$recentComments = BlogComment::where('user_id', $user->id)
->with('blog:id,title,slug')
->latest()
->take(4)
->take(3)
->get()
->map(fn ($item) => [
'type' => 'comment',
'title' => $item->blog?->title,
'content' => $item->content,
'url' => $item->blog ? "/blogs/{$item->blog->slug}" : null,
'created_at' => $item->created_at?->diffForHumans(),
'timestamp' => $item->created_at?->timestamp ?? 0,
])
->filter(fn ($item) => $item['title'] !== null);

Expand All @@ -128,7 +152,7 @@ public function show(string $username)
'node.parent.parent:id,name,slug',
])
->latest('id')
->take(4)
->take(3)
->get()
->map(function ($item) {
$node = $item->node;
Expand All @@ -144,6 +168,7 @@ public function show(string $username)
'subtitle' => $node->subject?->name.($node->parent ? ' · '.$node->parent->name : ''),
'url' => $url,
'created_at' => $item->created_at?->diffForHumans(),
'timestamp' => $item->created_at?->timestamp ?? 0,
];
})
->filter()
Expand All @@ -152,14 +177,15 @@ public function show(string $username)
$recentAppreciations = UserAppreciation::where('appreciator_id', $user->id)
->with('user:id,name,username')
->latest('id')
->take(4)
->take(3)
->get()
->map(fn ($item) => [
'type' => 'appreciation',
'title' => $item->user?->name,
'username' => $item->user?->username,
'url' => $item->user ? "/u/{$item->user->username}" : null,
'created_at' => $item->created_at?->diffForHumans(),
'timestamp' => $item->created_at?->timestamp ?? 0,
])
->filter(fn ($item) => $item['title'] !== null)
->values();
Expand All @@ -169,7 +195,6 @@ public function show(string $username)
->whereNotNull('username')
->whereHas('roles')
->select(['id', 'name', 'username', 'title', 'institution', 'image_path', 'about'])
->with('roles:id,name')
->inRandomOrder()
->take(2)
->get();
Expand All @@ -180,7 +205,6 @@ public function show(string $username)
$randomUsers = User::whereNotIn('id', $excludedIds)
->whereNotNull('username')
->select(['id', 'name', 'username', 'title', 'institution', 'image_path', 'about'])
->with('roles:id,name')
->inRandomOrder()
->take($remainingNeeded)
->get();
Expand All @@ -200,13 +224,13 @@ public function show(string $username)
'instagram' => $user->instagram,
'github' => $user->github,
'created_at' => $user->created_at?->format('M Y') ?? '2026',
'roles' => $user->roles->pluck('name'),
'is_staff' => $user->roles->isNotEmpty(),
'is_verified' => $user->is_verified,
'is_staff' => $user->is_verified,
],
'stats' => [
'completedResourcesCount' => $completedResourcesCount,
'blogsCount' => $blogsCount,
'totalBlogLikes' => (int) $totalBlogLikes,
'upvotesCount' => $upvotesCount,
'totalBlogViews' => (int) $totalBlogViews,
'sharedResourcesCount' => $sharedResourcesCount,
],
Expand All @@ -218,6 +242,7 @@ public function show(string $username)
'recentCompletions' => $recentCompletions,
'blogs' => $publishedBlogs,
'recentActivities' => [
'folders' => $recentFolders->values(),
'uploads' => $recentUploads->values(),
'completions' => $recentCompleted->values(),
'reactions' => $recentReactions->values(),
Expand Down
8 changes: 8 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,16 @@ protected static function booted(): void

protected $appends = [
'image_url',
'is_verified',
];

public function getIsVerifiedAttribute(): bool
{
return $this->relationLoaded('roles')
? $this->roles->isNotEmpty()
: $this->roles()->exists();
}

public function getImageUrlAttribute()
{
if (! $this->image_path) {
Expand Down
14 changes: 7 additions & 7 deletions resources/js/components/UserListItem.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { Link } from '@inertiajs/vue3';
import { BadgeCheck } from 'lucide-vue-next';
import VerifiedBadge from '@/components/VerifiedBadge.vue';
import { computed } from 'vue';

const props = withDefaults(
Expand All @@ -13,6 +13,7 @@ const props = withDefaults(
image_path?: string | null;
institution?: string | null;
title?: string | null;
is_verified?: boolean;
roles?: Array<{ id?: number; name: string }>;
};
theme?: 'indigo' | 'emerald' | 'rose';
Expand All @@ -29,7 +30,10 @@ const profileUrl = computed(() => {
});

const isVerified = computed(() => {
return Boolean(props.user.roles && props.user.roles.length > 0);
return Boolean(
props.user.is_verified ??
(props.user.roles && props.user.roles.length > 0),
);
});

const avatarBgClass = computed(() => {
Expand Down Expand Up @@ -71,11 +75,7 @@ const avatarBgClass = computed(() => {
>
{{ user.name }}
</p>
<BadgeCheck
v-if="isVerified"
class="h-3.5 w-3.5 shrink-0 fill-blue-50 stroke-[2.2] text-blue-600 dark:fill-blue-950/60 dark:text-blue-400"
title="Verified Contributor"
/>
<VerifiedBadge v-if="isVerified" />
</div>
<p
v-if="subtitle || user.institution || user.title"
Expand Down
24 changes: 24 additions & 0 deletions resources/js/components/VerifiedBadge.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<script setup lang="ts">
import { BadgeCheck } from 'lucide-vue-next';

withDefaults(
defineProps<{
size?: string;
title?: string;
}>(),
{
size: 'h-3.5 w-3.5',
title: 'Verified Contributor',
},
);
</script>

<template>
<BadgeCheck
:class="[
size,
'shrink-0 fill-blue-50 stroke-[2.2] text-blue-600 dark:fill-blue-950/60 dark:text-blue-400',
]"
:title="title"
/>
</template>
20 changes: 6 additions & 14 deletions resources/js/pages/Blog/Show.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import {
LogIn,
X,
Loader2,
BadgeCheck,
} from 'lucide-vue-next';
import { computed, ref, watch } from 'vue';
import UserListItem from '@/components/UserListItem.vue';
import VerifiedBadge from '@/components/VerifiedBadge.vue';

const props = defineProps({
blog: {
Expand Down Expand Up @@ -638,13 +638,8 @@ const goBack = () => {
<span>{{
comment.user?.name || 'Anonymous'
}}</span>
<BadgeCheck
v-if="
comment.user?.roles &&
comment.user.roles.length > 0
"
class="h-3.5 w-3.5 fill-blue-50 stroke-[2.2] text-blue-600 dark:fill-blue-950/60 dark:text-blue-400"
title="Verified Contributor"
<VerifiedBadge
v-if="comment.user?.is_verified"
/>
</Link>
<span
Expand Down Expand Up @@ -716,12 +711,9 @@ const goBack = () => {
class="mt-1 inline-flex items-center gap-1.5 text-lg font-semibold text-slate-900 underline transition dark:text-gray-100"
>
<span>{{ blog.user?.name }}</span>
<BadgeCheck
v-if="
blog.user?.roles && blog.user.roles.length > 0
"
class="h-4.5 w-4.5 fill-blue-50 stroke-[2.2] text-blue-600 dark:fill-blue-950/60 dark:text-blue-400"
title="Verified Contributor"
<VerifiedBadge
v-if="blog.user?.is_verified"
size="h-4.5 w-4.5"
/>
</Link>

Expand Down
4 changes: 4 additions & 0 deletions resources/js/pages/Profile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ const page = usePage();
const user = computed(() => props.user || page.props.auth?.user);

const hasNoRole = computed(() => {
if (typeof user.value?.is_verified === 'boolean') {
return !user.value.is_verified;
}

const roles = user.value?.roles;

return !roles || roles.length === 0;
Expand Down
Loading
Loading