Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c602393c95 |
@@ -5,6 +5,7 @@ namespace App\Http\Controllers;
|
|||||||
use App\Models\Aircraft;
|
use App\Models\Aircraft;
|
||||||
use App\Models\Airline;
|
use App\Models\Airline;
|
||||||
use App\Models\Airport;
|
use App\Models\Airport;
|
||||||
|
use App\Models\User;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
class SearchController extends Controller
|
class SearchController extends Controller
|
||||||
@@ -82,4 +83,23 @@ class SearchController extends Controller
|
|||||||
])
|
])
|
||||||
->values();
|
->values();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public function users()
|
||||||
|
{
|
||||||
|
$q = request('q', '');
|
||||||
|
|
||||||
|
if (strlen($q) < 2) return [];
|
||||||
|
|
||||||
|
return User::where('name', 'ilike', "%{$q}%")
|
||||||
|
->orderBy('name')
|
||||||
|
->limit(50)
|
||||||
|
->get(['id', 'name'])
|
||||||
|
->map(fn($user) => [
|
||||||
|
'value' => $user->id,
|
||||||
|
'title' => $user->name,
|
||||||
|
])
|
||||||
|
->values();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import type { SharedProps } from '@/Types/types'
|
|||||||
import { ref, onMounted, onUnmounted } from 'vue'
|
import { ref, onMounted, onUnmounted } from 'vue'
|
||||||
import NotificationMenu from "@/Components/FlightsGoneBy/NotificationMenu.vue";
|
import NotificationMenu from "@/Components/FlightsGoneBy/NotificationMenu.vue";
|
||||||
import Logo from "@/Components/FlightsGoneBy/Logo.vue";
|
import Logo from "@/Components/FlightsGoneBy/Logo.vue";
|
||||||
|
import UserSearchBox from "@/Components/UserSearchBox.vue";
|
||||||
|
|
||||||
const page = usePage<SharedProps>()
|
const page = usePage<SharedProps>()
|
||||||
const menuOpen = ref(false)
|
const menuOpen = ref(false)
|
||||||
@@ -30,6 +31,7 @@ onUnmounted(() => document.removeEventListener('click', handleClickOutside))
|
|||||||
<Logo variant="color" />
|
<Logo variant="color" />
|
||||||
</Link>
|
</Link>
|
||||||
|
|
||||||
|
<UserSearchBox density="compact" style="max-width:400px; width: 400px;" />
|
||||||
<NotificationMenu v-if="page.props.auth?.user" :unread-count="page.props.unread_notification_count" />
|
<NotificationMenu v-if="page.props.auth?.user" :unread-count="page.props.unread_notification_count" />
|
||||||
|
|
||||||
<!-- Desktop nav -->
|
<!-- Desktop nav -->
|
||||||
|
|||||||
@@ -0,0 +1,83 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, watch } from 'vue'
|
||||||
|
import { Link } from '@inertiajs/vue3'
|
||||||
|
|
||||||
|
defineProps<{
|
||||||
|
density?: null | 'default' | 'comfortable' | 'compact';
|
||||||
|
}>()
|
||||||
|
|
||||||
|
interface UserOption {
|
||||||
|
value: number
|
||||||
|
title: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const search = ref('')
|
||||||
|
const selectedUser = ref<UserOption | null>(null)
|
||||||
|
const items = ref<UserOption[]>([])
|
||||||
|
const loading = ref(false)
|
||||||
|
|
||||||
|
let debounceTimeout: ReturnType<typeof setTimeout> | undefined
|
||||||
|
|
||||||
|
async function fetchUsers(query: string) {
|
||||||
|
if (!query) {
|
||||||
|
items.value = []
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
loading.value = true
|
||||||
|
try {
|
||||||
|
const response = await fetch(`/search/users?q=${encodeURIComponent(query)}`)
|
||||||
|
if (!response.ok) throw new Error('Failed to fetch users')
|
||||||
|
items.value = await response.json()
|
||||||
|
} catch (error) {
|
||||||
|
console.error('User search failed:', error)
|
||||||
|
items.value = []
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(search, (newQuery) => {
|
||||||
|
clearTimeout(debounceTimeout)
|
||||||
|
debounceTimeout = setTimeout(() => {
|
||||||
|
fetchUsers(newQuery)
|
||||||
|
}, 300)
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="user-search-box">
|
||||||
|
<v-autocomplete
|
||||||
|
v-model="selectedUser"
|
||||||
|
v-model:search="search"
|
||||||
|
:items="items"
|
||||||
|
:loading="loading"
|
||||||
|
item-title="title"
|
||||||
|
item-value="value"
|
||||||
|
return-object
|
||||||
|
label="Search users"
|
||||||
|
placeholder="Type a name..."
|
||||||
|
prepend-inner-icon="mdi-magnify"
|
||||||
|
:density="density ?? 'default'"
|
||||||
|
variant="outlined"
|
||||||
|
no-filter
|
||||||
|
clearable
|
||||||
|
hide-details
|
||||||
|
autocomplete="off"
|
||||||
|
>
|
||||||
|
<template #item="{ item }">
|
||||||
|
<Link :href="`/u/${item.title}`" class="user-search-result">
|
||||||
|
<v-list-item :title="item.title" />
|
||||||
|
</Link>
|
||||||
|
</template>
|
||||||
|
</v-autocomplete>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.user-search-box {
|
||||||
|
display: block;
|
||||||
|
align-self: center;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -9,6 +9,7 @@ import PlaneLoader from "@/Components/FlightsGoneBy/PlaneLoader.vue";
|
|||||||
import { useFlights } from "@/Composables/useFlights";
|
import { useFlights } from "@/Composables/useFlights";
|
||||||
import { useApiResource } from "@/Composables/useApiResource";
|
import { useApiResource } from "@/Composables/useApiResource";
|
||||||
import Avatar from "@/Components/FlightsGoneBy/Feed/Avatar.vue";
|
import Avatar from "@/Components/FlightsGoneBy/Feed/Avatar.vue";
|
||||||
|
import UserSearchBox from "@/Components/UserSearchBox.vue";
|
||||||
|
|
||||||
defineOptions({ layout: MainLayout })
|
defineOptions({ layout: MainLayout })
|
||||||
|
|
||||||
@@ -46,8 +47,9 @@ const { data: following, loading: followingLoading } = useApiResource<User[]>('/
|
|||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<UserSearchBox />
|
||||||
|
|
||||||
<div class="feed-grid">
|
<div class="feed-grid">
|
||||||
<!-- FOLLOWING: secondary, supporting content -->
|
|
||||||
<aside class="following-box">
|
<aside class="following-box">
|
||||||
<h2>Following</h2>
|
<h2>Following</h2>
|
||||||
<div v-if="followingLoading" class="following-loading">
|
<div v-if="followingLoading" class="following-loading">
|
||||||
|
|||||||
+2
-1
@@ -103,10 +103,11 @@ Route::middleware(['auth'])->group(function () {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Search Routes
|
//Search Routes
|
||||||
Route::get('/search/airlines', [SearchController::class, 'airlines'])->name('search.airlines');
|
Route::get('/search/airlines', [SearchController::class, 'airlines'])->name('search.airlines');
|
||||||
Route::get('/search/aircraft', [SearchController::class, 'aircraft'])->name('search.aircraft');
|
Route::get('/search/aircraft', [SearchController::class, 'aircraft'])->name('search.aircraft');
|
||||||
Route::get('/search/airports', [SearchController::class, 'airports'])->name('search.airports');
|
Route::get('/search/airports', [SearchController::class, 'airports'])->name('search.airports');
|
||||||
|
Route::get('/search/users', [SearchController::class, 'users'])->name('search.users');
|
||||||
|
|
||||||
Route::get('/u/{user}', [UserProfileController::class, 'view'])->name('profile.view');
|
Route::get('/u/{user}', [UserProfileController::class, 'view'])->name('profile.view');
|
||||||
Route::get('/u/{user}/map', [UserProfileController::class, 'map'])->name('profile.map');
|
Route::get('/u/{user}/map', [UserProfileController::class, 'map'])->name('profile.map');
|
||||||
|
|||||||
Reference in New Issue
Block a user