303 lines
7.2 KiB
Vue
303 lines
7.2 KiB
Vue
<script setup>
|
|
import { computed, onMounted, ref, watch } from 'vue'
|
|
import { useRoute, useRouter } from 'vue-router'
|
|
import { api } from '../lib/api'
|
|
import { toApiUrl } from '../lib/runtime'
|
|
|
|
const route = useRoute()
|
|
const router = useRouter()
|
|
|
|
const tierLists = ref([])
|
|
const loading = ref(false)
|
|
const error = ref('')
|
|
const query = ref('')
|
|
|
|
const normalizedQuery = computed(() => (query.value || '').trim())
|
|
|
|
function fmt(ts) {
|
|
return new Date(ts).toLocaleString(undefined, {
|
|
year: 'numeric',
|
|
month: '2-digit',
|
|
day: '2-digit',
|
|
hour: '2-digit',
|
|
minute: '2-digit',
|
|
})
|
|
}
|
|
|
|
function displayNameOf(tierList) {
|
|
return tierList.authorName || '알 수 없음'
|
|
}
|
|
|
|
function avatarSrcOf(tierList) {
|
|
return tierList.authorAvatarSrc ? toApiUrl(tierList.authorAvatarSrc) : ''
|
|
}
|
|
|
|
function avatarFallbackOf(tierList) {
|
|
return (tierList.authorAccountName || 'u').trim().charAt(0).toUpperCase() || '?'
|
|
}
|
|
|
|
function tierListThumbnailUrl(tierList) {
|
|
return tierList.thumbnailSrc ? toApiUrl(tierList.thumbnailSrc) : ''
|
|
}
|
|
|
|
function openTierList(tierList) {
|
|
router.push(`/editor/${tierList.gameId}/${tierList.id}`)
|
|
}
|
|
|
|
async function loadResults() {
|
|
loading.value = true
|
|
error.value = ''
|
|
try {
|
|
const data = await api.searchAllPublicTierLists(query.value)
|
|
tierLists.value = data.tierLists || []
|
|
} catch (e) {
|
|
error.value = '검색 결과를 불러오지 못했어요.'
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
function submitSearch() {
|
|
router.push(normalizedQuery.value ? `/search?q=${encodeURIComponent(normalizedQuery.value)}` : '/search')
|
|
}
|
|
|
|
watch(
|
|
() => route.query.q,
|
|
async (nextQuery) => {
|
|
query.value = typeof nextQuery === 'string' ? nextQuery : ''
|
|
await loadResults()
|
|
},
|
|
{ immediate: true }
|
|
)
|
|
|
|
onMounted(() => {
|
|
query.value = typeof route.query.q === 'string' ? route.query.q : ''
|
|
})
|
|
</script>
|
|
|
|
<template>
|
|
<section class="wrap">
|
|
<div class="head">
|
|
<div>
|
|
<div class="head__eyebrow">Search</div>
|
|
<h2 class="title">전체 티어표 검색</h2>
|
|
<div class="desc">공개된 모든 티어표를 제목과 작성자 기준으로 찾아볼 수 있어요.</div>
|
|
</div>
|
|
<!-- <form class="toolbar" @submit.prevent="submitSearch">
|
|
<input v-model="query" class="input" placeholder="제목 또는 작성자 검색" />
|
|
<button class="btn" type="submit">검색</button>
|
|
</form> -->
|
|
</div>
|
|
|
|
<div v-if="error" class="error">{{ error }}</div>
|
|
<div v-else-if="loading" class="empty">검색 중이에요.</div>
|
|
<div v-else-if="tierLists.length === 0" class="empty">검색 결과가 없어요.</div>
|
|
<div v-else class="list">
|
|
<article v-for="tierList in tierLists" :key="tierList.id" class="boardCard">
|
|
<button class="boardCard__body" @click="openTierList(tierList)">
|
|
<div class="boardCard__thumbWrap">
|
|
<img v-if="tierListThumbnailUrl(tierList)" class="boardCard__thumb" :src="tierListThumbnailUrl(tierList)" :alt="tierList.title" />
|
|
<div v-else class="boardCard__thumbPlaceholder">대표 썸네일</div>
|
|
</div>
|
|
<div class="boardCard__head">
|
|
<div class="boardCard__title">{{ tierList.title }}</div>
|
|
<div class="boardCard__author">
|
|
<img v-if="avatarSrcOf(tierList)" class="boardCard__avatar" :src="avatarSrcOf(tierList)" :alt="displayNameOf(tierList)" />
|
|
<div v-else class="boardCard__avatar boardCard__avatar--fallback">{{ avatarFallbackOf(tierList) }}</div>
|
|
<span>by {{ displayNameOf(tierList) }}</span>
|
|
</div>
|
|
</div>
|
|
</button>
|
|
<div class="boardCard__foot">
|
|
<div class="boardCard__meta">
|
|
<div>{{ tierList.gameId }}</div>
|
|
<div>{{ fmt(tierList.updatedAt) }}</div>
|
|
</div>
|
|
<div class="favoriteStat" :title="tierList.isFavorited ? '이미 즐겨찾기한 티어표' : '즐겨찾기 수'">
|
|
{{ tierList.isFavorited ? '★' : '☆' }} {{ tierList.favoriteCount || 0 }}
|
|
</div>
|
|
</div>
|
|
</article>
|
|
</div>
|
|
</section>
|
|
</template>
|
|
|
|
<style scoped>
|
|
.wrap {
|
|
display: grid;
|
|
gap: 18px;
|
|
}
|
|
.head {
|
|
display: flex;
|
|
gap: 14px;
|
|
justify-content: space-between;
|
|
align-items: flex-end;
|
|
flex-wrap: wrap;
|
|
padding: 6px 2px 8px;
|
|
}
|
|
.head__eyebrow {
|
|
font-size: 11px;
|
|
letter-spacing: 0.12em;
|
|
text-transform: uppercase;
|
|
color: rgba(255, 255, 255, 0.42);
|
|
}
|
|
.title {
|
|
margin: 4px 0 0;
|
|
font-size: 32px;
|
|
color: rgba(255, 255, 255, 0.96);
|
|
letter-spacing: -0.04em;
|
|
}
|
|
.desc {
|
|
margin-top: 6px;
|
|
color: rgba(255, 255, 255, 0.58);
|
|
}
|
|
.toolbar {
|
|
display: flex;
|
|
gap: 10px;
|
|
flex-wrap: wrap;
|
|
}
|
|
.input {
|
|
min-width: 280px;
|
|
padding: 11px 13px;
|
|
border-radius: 14px;
|
|
border: 1px solid rgba(255, 255, 255, 0.08);
|
|
background: rgba(255, 255, 255, 0.05);
|
|
color: rgba(255, 255, 255, 0.92);
|
|
}
|
|
.btn {
|
|
padding: 11px 13px;
|
|
border-radius: 14px;
|
|
border: 1px solid rgba(255, 255, 255, 0.08);
|
|
background: rgba(255, 255, 255, 0.06);
|
|
color: rgba(255, 255, 255, 0.92);
|
|
font-weight: 800;
|
|
cursor: pointer;
|
|
}
|
|
.error {
|
|
margin: 0 0 8px;
|
|
padding: 10px 12px;
|
|
border-radius: 12px;
|
|
border: 1px solid rgba(239, 68, 68, 0.18);
|
|
background: rgba(239, 68, 68, 0.1);
|
|
}
|
|
.empty {
|
|
opacity: 0.76;
|
|
}
|
|
.list {
|
|
display: grid;
|
|
grid-template-columns: repeat(3, minmax(0, 1fr));
|
|
gap: 18px;
|
|
}
|
|
.boardCard {
|
|
border-radius: 22px;
|
|
border: 1px solid rgba(255, 255, 255, 0.16);
|
|
background: rgba(62, 62, 62, 0.82);
|
|
overflow: hidden;
|
|
display: grid;
|
|
gap: 10px;
|
|
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
|
|
transition: transform 0.16s ease, background 0.16s ease;
|
|
}
|
|
.boardCard:hover {
|
|
transform: translateY(-2px);
|
|
background: rgba(70, 70, 70, 0.96);
|
|
}
|
|
.boardCard__body {
|
|
border: 0;
|
|
background: transparent;
|
|
color: inherit;
|
|
padding: 0;
|
|
text-align: left;
|
|
cursor: pointer;
|
|
display: grid;
|
|
gap: 10px;
|
|
}
|
|
.boardCard__thumbWrap {
|
|
width: 100%;
|
|
aspect-ratio: 16 / 9;
|
|
background: #555;
|
|
display: grid;
|
|
place-items: center;
|
|
}
|
|
.boardCard__thumb,
|
|
.boardCard__thumbPlaceholder {
|
|
width: 100%;
|
|
height: 100%;
|
|
display: block;
|
|
}
|
|
.boardCard__thumb {
|
|
object-fit: cover;
|
|
}
|
|
.boardCard__thumbPlaceholder {
|
|
background: #555;
|
|
display: grid;
|
|
place-items: center;
|
|
color: rgba(255, 255, 255, 0.4);
|
|
font-size: 13px;
|
|
font-weight: 700;
|
|
}
|
|
.boardCard__head {
|
|
padding: 14px 14px 0;
|
|
display: grid;
|
|
gap: 10px;
|
|
}
|
|
.boardCard__title {
|
|
font-weight: 800;
|
|
font-size: 18px;
|
|
}
|
|
.boardCard__author {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
font-size: 13px;
|
|
opacity: 0.86;
|
|
}
|
|
.boardCard__avatar {
|
|
width: 28px;
|
|
height: 28px;
|
|
border-radius: 999px;
|
|
object-fit: cover;
|
|
background: rgba(255, 255, 255, 0.08);
|
|
}
|
|
.boardCard__avatar--fallback {
|
|
display: grid;
|
|
place-items: center;
|
|
font-size: 12px;
|
|
font-weight: 900;
|
|
}
|
|
.boardCard__foot {
|
|
padding: 0 14px 14px;
|
|
display: flex;
|
|
gap: 12px;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
}
|
|
.boardCard__meta {
|
|
display: grid;
|
|
gap: 4px;
|
|
opacity: 0.78;
|
|
font-size: 13px;
|
|
}
|
|
.favoriteStat {
|
|
font-size: 13px;
|
|
color: rgba(255, 255, 255, 0.74);
|
|
}
|
|
@media (max-width: 1200px) {
|
|
.list {
|
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
}
|
|
}
|
|
@media (max-width: 720px) {
|
|
.input {
|
|
min-width: 0;
|
|
width: 100%;
|
|
}
|
|
.toolbar {
|
|
width: 100%;
|
|
}
|
|
.list {
|
|
grid-template-columns: 1fr;
|
|
}
|
|
}
|
|
</style>
|