232 lines
5.3 KiB
Vue
232 lines
5.3 KiB
Vue
<script setup>
|
|
import { onMounted, ref } from 'vue'
|
|
import { useRouter } from 'vue-router'
|
|
import { api } from '../lib/api'
|
|
import { toApiUrl } from '../lib/runtime'
|
|
|
|
const router = useRouter()
|
|
const myLists = ref([])
|
|
const error = ref('')
|
|
|
|
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) : ''
|
|
}
|
|
|
|
onMounted(async () => {
|
|
try {
|
|
const data = await api.listMyTierLists()
|
|
myLists.value = data.tierLists || []
|
|
} catch (e) {
|
|
error.value = '로그인이 필요해요.'
|
|
}
|
|
})
|
|
|
|
function openList(t) {
|
|
router.push(`/editor/${t.gameId}/${t.id}`)
|
|
}
|
|
|
|
async function removeList(t) {
|
|
error.value = ''
|
|
try {
|
|
const ok = window.confirm(`"${t.title}" 티어표를 삭제할까요?`)
|
|
if (!ok) return
|
|
await api.deleteTierList(t.id)
|
|
myLists.value = myLists.value.filter((entry) => entry.id !== t.id)
|
|
} catch (e) {
|
|
error.value = '티어표 삭제에 실패했어요.'
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<section class="wrap">
|
|
<h2 class="title">내 티어표</h2>
|
|
<div class="card">
|
|
<div v-if="error" class="error">
|
|
{{ error }}
|
|
<button class="link" @click="$router.push('/login')">로그인 하러가기</button>
|
|
</div>
|
|
<div v-if="myLists.length === 0" class="empty">아직 저장한 티어표가 없어요.</div>
|
|
<div v-else class="list">
|
|
<article v-for="t in myLists" :key="t.id" class="row">
|
|
<button class="row__body" @click="openList(t)">
|
|
<div class="row__thumbWrap">
|
|
<img v-if="tierListThumbnailUrl(t)" class="row__thumb" :src="tierListThumbnailUrl(t)" :alt="t.title" />
|
|
<div v-else class="row__thumbPlaceholder"></div>
|
|
</div>
|
|
<div class="row__head">
|
|
<div class="row__title">{{ t.title }}</div>
|
|
<div class="row__author">
|
|
<img v-if="avatarSrcOf(t)" class="row__avatar" :src="avatarSrcOf(t)" :alt="displayNameOf(t)" />
|
|
<div v-else class="row__avatar row__avatar--fallback">{{ avatarFallbackOf(t) }}</div>
|
|
<span>by {{ displayNameOf(t) }}</span>
|
|
</div>
|
|
</div>
|
|
<div class="row__meta">{{ fmt(t.updatedAt) }}</div>
|
|
</button>
|
|
<button class="link link--danger" @click="removeList(t)">삭제</button>
|
|
</article>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
</template>
|
|
|
|
<style scoped>
|
|
.wrap {
|
|
padding: 10px 2px;
|
|
}
|
|
.title {
|
|
margin: 0 0 10px;
|
|
font-size: 26px;
|
|
letter-spacing: -0.02em;
|
|
}
|
|
.card {
|
|
border: 1px solid rgba(255, 255, 255, 0.12);
|
|
background: rgba(255, 255, 255, 0.04);
|
|
border-radius: 16px;
|
|
padding: 14px;
|
|
}
|
|
.error {
|
|
margin-bottom: 12px;
|
|
padding: 10px 12px;
|
|
border-radius: 12px;
|
|
border: 1px solid rgba(239, 68, 68, 0.3);
|
|
background: rgba(239, 68, 68, 0.12);
|
|
display: flex;
|
|
gap: 10px;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
}
|
|
.link {
|
|
padding: 8px 10px;
|
|
border-radius: 10px;
|
|
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;
|
|
}
|
|
.empty {
|
|
opacity: 0.75;
|
|
}
|
|
.list {
|
|
display: grid;
|
|
grid-template-columns: repeat(3, minmax(0, 1fr));
|
|
gap: 14px;
|
|
}
|
|
.row {
|
|
display: grid;
|
|
gap: 10px;
|
|
border-radius: 14px;
|
|
border: 1px solid rgba(255, 255, 255, 0.10);
|
|
background: rgba(0, 0, 0, 0.16);
|
|
color: rgba(255, 255, 255, 0.92);
|
|
overflow: hidden;
|
|
}
|
|
.row__body {
|
|
flex: 1 1 auto;
|
|
min-width: 0;
|
|
text-align: left;
|
|
cursor: pointer;
|
|
border: 0;
|
|
background: transparent;
|
|
color: inherit;
|
|
padding: 0;
|
|
display: grid;
|
|
gap: 10px;
|
|
}
|
|
.row__thumbWrap {
|
|
width: 100%;
|
|
aspect-ratio: 16 / 9;
|
|
background: rgba(255, 255, 255, 0.03);
|
|
}
|
|
.row__thumb {
|
|
width: 100%;
|
|
height: 100%;
|
|
object-fit: cover;
|
|
display: block;
|
|
}
|
|
.row__thumbPlaceholder {
|
|
width: 100%;
|
|
height: 100%;
|
|
background:
|
|
linear-gradient(135deg, rgba(255,255,255,0.06), rgba(255,255,255,0.02));
|
|
}
|
|
.row__title {
|
|
font-weight: 900;
|
|
min-width: 0;
|
|
}
|
|
.row__head {
|
|
padding: 0 14px;
|
|
display: flex;
|
|
gap: 12px;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
flex-wrap: wrap;
|
|
}
|
|
.row__author {
|
|
display: inline-flex;
|
|
gap: 8px;
|
|
align-items: center;
|
|
font-size: 13px;
|
|
opacity: 0.84;
|
|
}
|
|
.row__avatar {
|
|
width: 28px;
|
|
height: 28px;
|
|
border-radius: 999px;
|
|
object-fit: cover;
|
|
border: 1px solid rgba(255, 255, 255, 0.12);
|
|
background: rgba(255, 255, 255, 0.08);
|
|
}
|
|
.row__avatar--fallback {
|
|
display: grid;
|
|
place-items: center;
|
|
font-size: 12px;
|
|
font-weight: 900;
|
|
}
|
|
.row__meta {
|
|
padding: 0 14px;
|
|
margin-top: 6px;
|
|
opacity: 0.76;
|
|
font-size: 13px;
|
|
}
|
|
.link--danger {
|
|
background: rgba(239, 68, 68, 0.14);
|
|
border-color: rgba(239, 68, 68, 0.28);
|
|
margin: 0 14px 14px;
|
|
}
|
|
@media (max-width: 1100px) {
|
|
.list {
|
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
}
|
|
}
|
|
@media (max-width: 720px) {
|
|
.list {
|
|
grid-template-columns: 1fr;
|
|
}
|
|
}
|
|
</style>
|