230 lines
5.4 KiB
Vue
230 lines
5.4 KiB
Vue
<script setup>
|
|
import { computed, onMounted, ref } from 'vue'
|
|
import { useRouter } from 'vue-router'
|
|
import { api } from '../lib/api'
|
|
import { toApiUrl } from '../lib/runtime'
|
|
|
|
const router = useRouter()
|
|
|
|
const items = ref([])
|
|
const error = ref('')
|
|
const games = computed(() => items.value)
|
|
const suggestOpen = ref(false)
|
|
const suggestName = ref('')
|
|
const suggestError = ref('')
|
|
|
|
onMounted(async () => {
|
|
try {
|
|
const data = await api.listGames()
|
|
items.value = data.games || []
|
|
} catch (e) {
|
|
error.value = '백엔드에 연결할 수 없어요. backend 서버가 실행 중인지 확인해주세요.'
|
|
}
|
|
})
|
|
|
|
function goGame(gameId) {
|
|
router.push(`/games/${gameId}`)
|
|
}
|
|
|
|
function thumbUrl(g) {
|
|
if (!g.thumbnailSrc) return ''
|
|
return toApiUrl(g.thumbnailSrc)
|
|
}
|
|
|
|
async function submitSuggest() {
|
|
suggestError.value = ''
|
|
const name = (suggestName.value || '').trim()
|
|
if (!name) {
|
|
suggestError.value = '게임 이름을 입력해주세요.'
|
|
return
|
|
}
|
|
try {
|
|
await api.suggestGame(name)
|
|
suggestName.value = ''
|
|
suggestOpen.value = false
|
|
} catch (e) {
|
|
suggestError.value = '제안 전송에 실패했어요.'
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<section class="hero">
|
|
<h1 class="hero__title">티어표 메이커</h1>
|
|
<p class="hero__desc">
|
|
게임을 선택하면 새 티어표를 만들거나, 다른 사람들이 올린 티어표를 볼 수 있어요.
|
|
</p>
|
|
<div class="hero__actions">
|
|
<button class="smallBtn" @click="suggestOpen = true">새로운 게임 제안</button>
|
|
</div>
|
|
</section>
|
|
|
|
<div v-if="error" class="error">{{ error }}</div>
|
|
<section class="grid">
|
|
<button v-for="g in games" :key="g.id" class="card" @click="goGame(g.id)">
|
|
<div class="thumbWrap">
|
|
<img v-if="thumbUrl(g)" class="thumb" :src="thumbUrl(g)" :alt="g.name" />
|
|
<div v-else class="thumbFallback">{{ g.name[0] }}</div>
|
|
</div>
|
|
<div class="card__title">{{ g.name }}</div>
|
|
</button>
|
|
</section>
|
|
|
|
<div v-if="suggestOpen" class="modalBack" @click.self="suggestOpen = false">
|
|
<div class="modal">
|
|
<div class="modal__title">새로운 게임 제안</div>
|
|
<div class="modal__desc">목록에 없는 게임을 입력해 주세요. (관리자가 확인 후 추가)</div>
|
|
<input v-model="suggestName" class="modal__input" placeholder="게임 이름" @keydown.enter.prevent="submitSuggest" />
|
|
<div v-if="suggestError" class="modal__error">{{ suggestError }}</div>
|
|
<div class="modal__actions">
|
|
<button class="smallBtn" @click="suggestOpen = false">닫기</button>
|
|
<button class="smallBtn smallBtn--primary" @click="submitSuggest">제안하기</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<style scoped>
|
|
.hero {
|
|
padding: 18px 2px 14px;
|
|
}
|
|
.hero__title {
|
|
font-size: 34px;
|
|
letter-spacing: -0.03em;
|
|
margin: 0 0 8px;
|
|
}
|
|
.hero__desc {
|
|
margin: 0;
|
|
opacity: 0.86;
|
|
line-height: 1.5;
|
|
}
|
|
.hero__actions {
|
|
margin-top: 12px;
|
|
}
|
|
.smallBtn {
|
|
padding: 8px 10px;
|
|
border-radius: 12px;
|
|
border: 1px solid rgba(255, 255, 255, 0.14);
|
|
background: rgba(255, 255, 255, 0.06);
|
|
color: rgba(255, 255, 255, 0.92);
|
|
cursor: pointer;
|
|
font-weight: 800;
|
|
}
|
|
.smallBtn:hover {
|
|
background: rgba(255, 255, 255, 0.08);
|
|
}
|
|
.smallBtn--primary {
|
|
background: rgba(96, 165, 250, 0.18);
|
|
}
|
|
.smallBtn--primary:hover {
|
|
background: rgba(96, 165, 250, 0.24);
|
|
}
|
|
.grid {
|
|
display: grid;
|
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
gap: 14px;
|
|
margin-top: 14px;
|
|
}
|
|
.error {
|
|
margin-top: 12px;
|
|
padding: 10px 12px;
|
|
border-radius: 12px;
|
|
border: 1px solid rgba(239, 68, 68, 0.3);
|
|
background: rgba(239, 68, 68, 0.12);
|
|
color: rgba(255, 255, 255, 0.92);
|
|
}
|
|
.card {
|
|
text-align: left;
|
|
padding: 14px;
|
|
border-radius: 16px;
|
|
border: 1px solid rgba(255, 255, 255, 0.12);
|
|
background: rgba(255, 255, 255, 0.05);
|
|
color: rgba(255, 255, 255, 0.92);
|
|
cursor: pointer;
|
|
display: grid;
|
|
gap: 10px;
|
|
}
|
|
.card:hover {
|
|
background: rgba(255, 255, 255, 0.07);
|
|
border-color: rgba(255, 255, 255, 0.18);
|
|
}
|
|
.thumbWrap {
|
|
width: 100%;
|
|
height: 140px;
|
|
border-radius: 14px;
|
|
border: 1px solid rgba(255, 255, 255, 0.12);
|
|
background: rgba(0, 0, 0, 0.18);
|
|
overflow: hidden;
|
|
display: grid;
|
|
place-items: center;
|
|
}
|
|
.thumb {
|
|
width: 100%;
|
|
height: 100%;
|
|
object-fit: cover;
|
|
}
|
|
.thumbFallback {
|
|
font-weight: 900;
|
|
font-size: 28px;
|
|
opacity: 0.85;
|
|
}
|
|
.card__title {
|
|
font-weight: 800;
|
|
letter-spacing: -0.02em;
|
|
}
|
|
.modalBack {
|
|
position: fixed;
|
|
inset: 0;
|
|
background: rgba(0, 0, 0, 0.55);
|
|
display: grid;
|
|
place-items: center;
|
|
z-index: 50;
|
|
}
|
|
.modal {
|
|
width: min(520px, 92vw);
|
|
border-radius: 16px;
|
|
border: 1px solid rgba(255, 255, 255, 0.14);
|
|
background: rgba(11, 18, 32, 0.92);
|
|
backdrop-filter: blur(10px);
|
|
padding: 14px;
|
|
}
|
|
.modal__title {
|
|
font-weight: 900;
|
|
font-size: 18px;
|
|
}
|
|
.modal__desc {
|
|
margin-top: 6px;
|
|
opacity: 0.78;
|
|
font-size: 13px;
|
|
}
|
|
.modal__input {
|
|
margin-top: 12px;
|
|
width: 100%;
|
|
padding: 10px 12px;
|
|
border-radius: 12px;
|
|
border: 1px solid rgba(255, 255, 255, 0.12);
|
|
background: rgba(0, 0, 0, 0.18);
|
|
color: rgba(255, 255, 255, 0.92);
|
|
outline: none;
|
|
box-sizing: border-box;
|
|
}
|
|
.modal__error {
|
|
margin-top: 10px;
|
|
padding: 10px 12px;
|
|
border-radius: 12px;
|
|
border: 1px solid rgba(239, 68, 68, 0.3);
|
|
background: rgba(239, 68, 68, 0.12);
|
|
}
|
|
.modal__actions {
|
|
margin-top: 12px;
|
|
display: flex;
|
|
justify-content: flex-end;
|
|
gap: 8px;
|
|
}
|
|
@media (max-width: 720px) {
|
|
.grid {
|
|
grid-template-columns: 1fr;
|
|
}
|
|
}
|
|
</style>
|