v0.1.17 - 목표 패널 및 D-DAY 선택 추가

This commit is contained in:
2026-04-21 18:37:06 +09:00
parent 440f0f46a1
commit 4355185203
11 changed files with 429 additions and 21 deletions

View File

@@ -12,6 +12,7 @@ import {
readAuthState,
signup,
} from './lib/authClient'
import { createGoal, fetchGoals } from './lib/goalsApi'
import { deletePlannerEntry, fetchPlannerEntries, savePlannerEntry } from './lib/plannerApi'
import {
createInitialPlannerRecords,
@@ -29,6 +30,10 @@ const authBusy = ref(false)
const authMessage = ref('')
const authToken = ref('')
const currentUser = ref(null)
const goals = ref([])
const goalQuery = ref('')
const goalBusy = ref(false)
const goalMessage = ref('')
const syncStatus = ref('local')
const syncMessage = ref('')
const syncToastVisible = ref(false)
@@ -41,6 +46,10 @@ const authForm = reactive({
email: '',
password: '',
})
const goalForm = reactive({
title: '',
targetDate: '',
})
const hours = [
'6', '7', '8', '9', '10', '11', '12',
@@ -178,8 +187,9 @@ function startOfDay(date) {
function buildFallbackRecord(date) {
return {
dday: 'D-00 FOCUS',
comment: '',
goalEnabled: false,
selectedGoalId: null,
tasks: Array.from({ length: 15 }, (_, index) => ({
label: '',
title: '',
@@ -198,6 +208,8 @@ function buildFallbackRecord(date) {
function normalizeRecord(record) {
return {
...record,
goalEnabled: Boolean(record.goalEnabled),
selectedGoalId: record.selectedGoalId ?? null,
tasks: record.tasks.map((task, index) => ({
label: task.label ?? task.id ?? '',
title: task.title ?? '',
@@ -300,6 +312,36 @@ const markedDateKeys = computed(() =>
)
const isAuthenticated = computed(() => Boolean(authToken.value && currentUser.value))
const filteredGoals = computed(() => {
const query = goalQuery.value.trim().toLowerCase()
if (!query) {
return goals.value
}
return goals.value.filter((goal) =>
goal.title.toLowerCase().includes(query),
)
})
const plannerGoal = computed(() =>
goals.value.find((goal) => goal.id === planner.value.selectedGoalId) ?? null,
)
const plannerDday = computed(() => {
if (!planner.value.goalEnabled || !plannerGoal.value) {
return ''
}
const targetDate = startOfDay(toDateValue(plannerGoal.value.targetDate))
const currentDate = startOfDay(selectedDate.value)
const diffDays = Math.round((targetDate.getTime() - currentDate.getTime()) / (24 * 60 * 60 * 1000))
const badge =
diffDays === 0 ? 'D-DAY' : diffDays > 0 ? `D-${diffDays}` : `D+${Math.abs(diffDays)}`
return `${badge} ${plannerGoal.value.title}`
})
const showPlannerDday = computed(() =>
planner.value.goalEnabled && Boolean(plannerGoal.value),
)
const filledTasks = computed(() =>
planner.value.tasks.filter((task) => task.title.trim()),
@@ -368,6 +410,22 @@ function updateComment(record, value) {
schedulePlannerSyncForRecord(record)
}
function updateGoalEnabled(record, value) {
record.goalEnabled = value
if (!value) {
record.selectedGoalId = null
}
schedulePlannerSyncForRecord(record)
}
function selectGoalForPlanner(record, goalId) {
record.goalEnabled = true
record.selectedGoalId = goalId
schedulePlannerSyncForRecord(record)
}
function updateTaskLabel(record, { index, value }) {
record.tasks[index].label = value
schedulePlannerSyncForRecord(record)
@@ -609,6 +667,11 @@ function resetAuthForm() {
authForm.password = ''
}
function resetGoalForm() {
goalForm.title = ''
goalForm.targetDate = ''
}
function openAuthDialog(mode = 'login') {
authMode.value = mode
authMessage.value = ''
@@ -633,6 +696,7 @@ async function applyAuthSuccess(data) {
token: data.token,
user: data.user,
})
await loadGoals()
await hydratePlannerRecordsFromApi()
closeAuthDialog()
}
@@ -680,6 +744,7 @@ async function restoreAuthSession() {
token: savedAuth.token,
user: result.user,
})
await loadGoals()
await hydratePlannerRecordsFromApi()
} catch (error) {
authToken.value = ''
@@ -695,6 +760,9 @@ function logout() {
clearPendingSyncTimers()
authToken.value = ''
currentUser.value = null
goals.value = []
goalQuery.value = ''
goalMessage.value = ''
setSyncFeedback('local', '로그인 후 클라우드 저장을 사용할 수 있습니다.', {
visible: false,
})
@@ -702,6 +770,56 @@ function logout() {
restoreLocalPlannerRecords()
}
async function loadGoals() {
if (!authToken.value) {
return
}
goalBusy.value = true
try {
const result = await fetchGoals(authToken.value, {
status: 'active',
})
goals.value = result.goals
goalMessage.value = ''
} catch (error) {
goalMessage.value = error.message || '목표를 불러오지 못했습니다.'
} finally {
goalBusy.value = false
}
}
async function submitGoal() {
if (!goalForm.title.trim() || !goalForm.targetDate) {
goalMessage.value = '목표 이름과 날짜를 입력해 주세요.'
return
}
goalBusy.value = true
goalMessage.value = ''
try {
const result = await createGoal(authToken.value, {
title: goalForm.title.trim(),
targetDate: goalForm.targetDate,
})
goals.value = [...goals.value, result.goal].sort((left, right) =>
left.targetDate.localeCompare(right.targetDate),
)
selectGoalForPlanner(planner.value, result.goal.id)
resetGoalForm()
goalQuery.value = ''
goalMessage.value = '목표가 추가되었습니다.'
} catch (error) {
goalMessage.value = error.message || '목표를 추가하지 못했습니다.'
} finally {
goalBusy.value = false
}
}
function replacePlannerRecords(nextRecords) {
Object.keys(plannerRecords).forEach((key) => {
delete plannerRecords[key]
@@ -1065,7 +1183,8 @@ onMounted(() => {
:date-main="selectedDateDisplay.main"
:date-weekday="selectedDateDisplay.weekday"
:date-weekday-tone="selectedDateDisplay.weekdayTone"
:dday="planner.dday"
:dday="plannerDday"
:show-dday="showPlannerDday"
:comment="planner.comment"
:total-time="formatTotalTime(planner)"
:tasks="planner.tasks"
@@ -1132,6 +1251,96 @@ onMounted(() => {
</div>
</section>
<section class="border border-stone-200 bg-white/80 p-5">
<div class="flex items-start justify-between gap-3">
<div>
<p class="text-[11px] font-bold tracking-[0.22em] text-ink">D-DAY 사용</p>
<p class="mt-2 text-[11px] font-semibold leading-5 tracking-[0.06em] text-stone-600">
목표를 검색해서 오늘의 대표 목표로 선택하면 본문 상단 D-DAY에 표시됩니다.
</p>
</div>
<button
type="button"
class="rounded-full border px-3 py-2 text-[10px] font-bold tracking-[0.16em] transition"
:class="planner.goalEnabled ? 'border-stone-900 bg-stone-900 text-white' : 'border-stone-300 text-stone-500'"
@click="updateGoalEnabled(planner, !planner.goalEnabled)"
>
{{ planner.goalEnabled ? 'ON' : 'OFF' }}
</button>
</div>
<div class="mt-4 space-y-3">
<div v-if="planner.goalEnabled && plannerGoal" class="rounded-2xl border border-stone-200 bg-white px-4 py-3">
<p class="text-[10px] font-bold tracking-[0.16em] text-stone-500">현재 목표</p>
<p class="mt-2 text-sm font-semibold tracking-[0.02em] text-stone-900">{{ plannerGoal.title }}</p>
<p class="mt-1 text-[11px] font-semibold tracking-[0.06em] text-stone-500">
목표일 {{ plannerGoal.targetDate }} / {{ plannerDday }}
</p>
</div>
<div v-if="goals.length > 0" class="space-y-2">
<input
v-model="goalQuery"
type="text"
class="w-full rounded-2xl border border-stone-300 bg-white px-4 py-3 text-sm font-semibold text-stone-800 outline-none transition focus:border-stone-500"
placeholder="목표 검색"
/>
<div class="max-h-52 space-y-2 overflow-y-auto pr-1">
<button
v-for="goal in filteredGoals"
:key="goal.id"
type="button"
class="w-full rounded-2xl border px-4 py-3 text-left transition"
:class="planner.selectedGoalId === goal.id ? 'border-stone-900 bg-stone-900 text-white' : 'border-stone-200 bg-white text-stone-800 hover:border-stone-400'"
@click="selectGoalForPlanner(planner, goal.id)"
>
<p class="text-sm font-semibold tracking-[0.02em]">{{ goal.title }}</p>
<p
class="mt-1 text-[11px] font-semibold tracking-[0.06em]"
:class="planner.selectedGoalId === goal.id ? 'text-stone-200' : 'text-stone-500'"
>
목표일 {{ goal.targetDate }}
</p>
</button>
</div>
</div>
<div v-else class="rounded-2xl border border-dashed border-stone-300 bg-white/70 px-4 py-4">
<p class="text-[11px] font-semibold leading-5 tracking-[0.06em] text-stone-500">
아직 목표가 없습니다. 아래에서 목표를 추가해 주세요.
</p>
</div>
<div class="rounded-2xl border border-stone-200 bg-[#fbf7f0] p-4">
<p class="text-[10px] font-bold tracking-[0.16em] text-stone-500"> 목표 추가</p>
<div class="mt-3 space-y-2">
<input
v-model="goalForm.title"
type="text"
class="w-full rounded-2xl border border-stone-300 bg-white px-4 py-3 text-sm font-semibold text-stone-800 outline-none transition focus:border-stone-500"
placeholder="예: 자격증 시험 / 런칭 / 프로젝트 마감"
/>
<input
v-model="goalForm.targetDate"
type="date"
class="w-full rounded-2xl border border-stone-300 bg-white px-4 py-3 text-sm font-semibold text-stone-800 outline-none transition focus:border-stone-500"
/>
<button
type="button"
class="w-full rounded-full bg-stone-900 px-4 py-3 text-[10px] font-bold tracking-[0.18em] text-white transition hover:bg-stone-700 disabled:cursor-not-allowed disabled:bg-stone-400"
:disabled="goalBusy"
@click="submitGoal"
>
{{ goalBusy ? '추가 중...' : 'GOAL ADD' }}
</button>
</div>
<p v-if="goalMessage" class="mt-3 text-[11px] font-semibold leading-5 tracking-[0.06em] text-stone-600">
{{ goalMessage }}
</p>
</div>
</div>
</section>
<MiniCalendar
:month-label="monthLabel"
:year-label="yearLabel"
@@ -1185,7 +1394,8 @@ onMounted(() => {
:date-main="selectedDateDisplay.main"
:date-weekday="selectedDateDisplay.weekday"
:date-weekday-tone="selectedDateDisplay.weekdayTone"
:dday="planner.dday"
:dday="plannerDday"
:show-dday="showPlannerDday"
:comment="planner.comment"
:total-time="formatTotalTime(planner)"
:tasks="planner.tasks"
@@ -1206,7 +1416,8 @@ onMounted(() => {
:date-main="secondaryDateDisplay.main"
:date-weekday="secondaryDateDisplay.weekday"
:date-weekday-tone="secondaryDateDisplay.weekdayTone"
:dday="secondaryPlanner.dday"
:dday="''"
:show-dday="false"
:comment="secondaryPlanner.comment"
:total-time="formatTotalTime(secondaryPlanner)"
:tasks="secondaryPlanner.tasks"
@@ -1246,7 +1457,8 @@ onMounted(() => {
:date-main="selectedDateDisplay.main"
:date-weekday="selectedDateDisplay.weekday"
:date-weekday-tone="selectedDateDisplay.weekdayTone"
:dday="planner.dday"
:dday="plannerDday"
:show-dday="showPlannerDday"
:comment="planner.comment"
:total-time="formatTotalTime(planner)"
:tasks="planner.tasks"
@@ -1270,7 +1482,8 @@ onMounted(() => {
:date-main="selectedDateDisplay.main"
:date-weekday="selectedDateDisplay.weekday"
:date-weekday-tone="selectedDateDisplay.weekdayTone"
:dday="planner.dday"
:dday="plannerDday"
:show-dday="showPlannerDday"
:comment="planner.comment"
:total-time="formatTotalTime(planner)"
:tasks="planner.tasks"
@@ -1291,7 +1504,8 @@ onMounted(() => {
:date-main="secondaryDateDisplay.main"
:date-weekday="secondaryDateDisplay.weekday"
:date-weekday-tone="secondaryDateDisplay.weekdayTone"
:dday="secondaryPlanner.dday"
:dday="''"
:show-dday="false"
:comment="secondaryPlanner.comment"
:total-time="formatTotalTime(secondaryPlanner)"
:tasks="secondaryPlanner.tasks"

View File

@@ -16,7 +16,11 @@ const props = defineProps({
},
dday: {
type: String,
required: true,
default: '',
},
showDday: {
type: Boolean,
default: true,
},
comment: {
type: String,
@@ -119,14 +123,14 @@ onBeforeUnmount(() => {
>
<div class="flex flex-col gap-4 py-[18px]">
<div class="flex gap-4">
<div class="relative h-[90px] w-[394px] flex-1 border-t border-ink px-[10px] pt-[10px]">
<div class="relative h-[90px] border-t border-ink px-[10px] pt-[10px]" :class="props.showDday ? 'w-[394px] flex-1' : 'w-full flex-1'">
<span class="absolute -top-2 left-0 bg-paper px-[2px] text-muted">YEAR / MONTH / DAY</span>
<p class="pt-6 text-xs tracking-[0.24em] text-ink sm:text-sm">
<span>{{ dateMain }}</span>
<span class="ml-1" :class="dateWeekdayTone">{{ dateWeekday }}</span>
</p>
</div>
<div class="relative h-[90px] w-[210px] border-t border-ink px-[10px] pt-[10px]">
<div v-if="props.showDday" class="relative h-[90px] w-[210px] border-t border-ink px-[10px] pt-[10px]">
<span class="absolute -top-2 left-0 bg-paper px-[2px] text-muted">D-DAY</span>
<p class="pt-6 text-xs tracking-[0.24em] text-ink sm:text-sm">{{ dday }}</p>
</div>

49
src/lib/goalsApi.js Normal file
View File

@@ -0,0 +1,49 @@
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL ?? 'http://localhost:3001'
function buildHeaders(token) {
return {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
}
}
async function request(path, { method = 'GET', token, body } = {}) {
const response = await fetch(`${API_BASE_URL}${path}`, {
method,
headers: buildHeaders(token),
body: body ? JSON.stringify(body) : undefined,
})
const data = await response.json().catch(() => ({}))
if (!response.ok) {
throw new Error(data.message || '목표 데이터를 처리하지 못했습니다.')
}
return data
}
export async function fetchGoals(token, { query = '', status = 'active' } = {}) {
const searchParams = new URLSearchParams()
if (query) {
searchParams.set('query', query)
}
if (status) {
searchParams.set('status', status)
}
const queryString = searchParams.toString()
return request(`/api/goals${queryString ? `?${queryString}` : ''}`, {
token,
})
}
export async function createGoal(token, payload) {
return request('/api/goals', {
method: 'POST',
token,
body: payload,
})
}