봇 관리 UI 개선

- 카드 그리드 레이아웃으로 변경
- 통계 분리: 총 추가 / 마지막 추가 / 업데이트 간격
- DB에 last_added_count 컬럼 추가
- 업데이트 시간을 봇 이름 아래에 표시
- 마지막 추가된 개수 초록색 강조
This commit is contained in:
caadiq 2026-01-06 11:42:47 +09:00
parent 89cd2d7965
commit 217746af3e
4 changed files with 110 additions and 88 deletions

View file

@ -433,14 +433,15 @@ export async function syncNewVideos(botId) {
}
}
// 봇 상태 업데이트
// 봇 상태 업데이트 (전체 추가 수 + 마지막 추가 수)
await pool.query(
`UPDATE bots SET
last_check_at = DATE_ADD(NOW(), INTERVAL 9 HOUR),
schedules_added = schedules_added + ?,
last_added_count = ?,
error_message = NULL
WHERE id = ?`,
[addedCount, botId]
[addedCount, addedCount, botId]
);
return { addedCount, total: videos.length };
@ -536,14 +537,15 @@ export async function syncAllVideos(botId) {
}
}
// 봇 상태 업데이트
// 봇 상태 업데이트 (전체 추가 수 + 마지막 추가 수)
await pool.query(
`UPDATE bots SET
last_check_at = DATE_ADD(NOW(), INTERVAL 9 HOUR),
schedules_added = schedules_added + ?,
last_added_count = ?,
error_message = NULL
WHERE id = ?`,
[addedCount, botId]
[addedCount, addedCount, botId]
);
return { addedCount, total: videos.length };

View file

@ -163,8 +163,16 @@ function AdminSchedule() {
//
fetchCategories();
// sessionStorage ( / )
const savedToast = sessionStorage.getItem('scheduleToast');
if (savedToast) {
setToast(JSON.parse(savedToast));
sessionStorage.removeItem('scheduleToast');
}
}, [navigate]);
//
useEffect(() => {
fetchSchedules();

View file

@ -280,106 +280,113 @@ function AdminScheduleBots() {
<p className="text-sm mt-1">위의 버튼을 클릭하여 봇을 추가하세요</p>
</div>
) : (
<div className="divide-y divide-gray-100">
<div className="p-6 grid grid-cols-1 lg:grid-cols-2 gap-4">
{bots.map((bot, index) => {
const statusInfo = getStatusInfo(bot.status);
return (
<motion.div
key={bot.id}
initial={{ opacity: 0, y: 10 }}
animate={{ opacity: 1, y: 0 }}
initial={{ opacity: 0, scale: 0.95 }}
animate={{ opacity: 1, scale: 1 }}
transition={{ delay: index * 0.05 }}
className="p-6 hover:bg-gray-50 transition-colors"
className="relative bg-gradient-to-br from-gray-50 to-white rounded-xl border border-gray-200 overflow-hidden hover:shadow-md transition-all"
>
<div className="flex items-start gap-4">
{/* 아이콘 */}
<div className={`w-12 h-12 rounded-xl ${statusInfo.bg} flex items-center justify-center flex-shrink-0`}>
<Youtube size={24} className="text-red-500" />
</div>
{/* 정보 */}
<div className="flex-1 min-w-0">
<div className="flex items-center gap-3 mb-1">
{/* 상단 헤더 */}
<div className="flex items-center justify-between p-4 border-b border-gray-100">
<div className="flex items-center gap-3">
<div className="w-10 h-10 rounded-lg bg-red-50 flex items-center justify-center">
<Youtube size={20} className="text-red-500" />
</div>
<div>
<h3 className="font-bold text-gray-900">{bot.name}</h3>
<span className={`flex items-center gap-1 text-xs font-medium ${statusInfo.color}`}>
<span className={`w-1.5 h-1.5 rounded-full ${statusInfo.dot} ${bot.status === 'running' ? 'animate-pulse' : ''}`}></span>
{statusInfo.text}
</span>
<span className="px-2 py-0.5 text-xs font-medium bg-red-50 text-red-600 rounded-full">
YouTube
</span>
<p className="text-xs text-gray-400">
{bot.last_check_at ? `${formatTime(bot.last_check_at)}에 업데이트됨` : '아직 업데이트 없음'}
</p>
</div>
<p className="text-sm text-gray-500 mb-3">
채널: {bot.channel_name || bot.channel_id} | {formatInterval(bot.check_interval)} 간격
</p>
{/* 메타 정보 */}
<div className="flex items-center gap-6 text-xs text-gray-400">
<span className="flex items-center gap-1">
<Clock size={12} />
마지막 체크: {formatTime(bot.last_check_at)}
</span>
<span className="flex items-center gap-1">
<Calendar size={12} />
추가된 일정: {bot.schedules_added}
</span>
</div>
{/* 오류 메시지 */}
{bot.status === 'error' && bot.error_message && (
<div className="mt-3 px-3 py-2 bg-red-50 text-red-600 text-xs rounded-lg">
{bot.error_message}
</div>
)}
</div>
<span className={`flex items-center gap-1.5 px-2.5 py-1 text-xs font-medium rounded-full ${statusInfo.bg} ${statusInfo.color}`}>
<span className={`w-1.5 h-1.5 rounded-full ${statusInfo.dot} ${bot.status === 'running' ? 'animate-pulse' : ''}`}></span>
{statusInfo.text}
</span>
</div>
{/* 액션 버튼 */}
<div className="flex items-center gap-2 flex-shrink-0">
<button
onClick={() => syncAllVideos(bot.id)}
disabled={syncing === bot.id}
className="flex items-center gap-2 px-4 py-2 bg-blue-500 text-white rounded-lg font-medium transition-colors hover:bg-blue-600 disabled:opacity-50"
>
{syncing === bot.id ? (
<>
<RefreshCw size={16} className="animate-spin" />
동기화 ...
</>
) : (
<>
<Download size={16} />
전체 동기화
</>
)}
</button>
<button
onClick={() => toggleBot(bot.id, bot.status, bot.name)}
className={`flex items-center gap-2 px-4 py-2 rounded-lg font-medium transition-colors ${
bot.status === 'running'
? 'bg-gray-100 text-gray-600 hover:bg-gray-200'
: 'bg-green-500 text-white hover:bg-green-600'
}`}
>
{bot.status === 'running' ? (
<>
<Square size={16} />
정지
</>
) : (
<>
<Play size={16} />
시작
</>
)}
</button>
{/* 통계 정보 */}
<div className="grid grid-cols-3 divide-x divide-gray-100 bg-gray-50/50">
<div className="p-3 text-center">
<div className="text-lg font-bold text-gray-900">{bot.schedules_added}</div>
<div className="text-xs text-gray-400"> 추가</div>
</div>
<div className="p-3 text-center">
<div className={`text-lg font-bold ${bot.last_added_count > 0 ? 'text-green-500' : 'text-gray-400'}`}>
+{bot.last_added_count || 0}
</div>
<div className="text-xs text-gray-400">마지막</div>
</div>
<div className="p-3 text-center">
<div className="text-lg font-bold text-gray-900">{formatInterval(bot.check_interval)}</div>
<div className="text-xs text-gray-400">업데이트 간격</div>
</div>
</div>
{/* 오류 메시지 */}
{bot.status === 'error' && bot.error_message && (
<div className="px-4 py-2 bg-red-50 text-red-600 text-xs border-t border-red-100">
{bot.error_message}
</div>
)}
{/* 액션 버튼 */}
<div className="p-4 border-t border-gray-100">
<div className="flex gap-2">
<button
onClick={() => syncAllVideos(bot.id)}
disabled={syncing === bot.id}
className="flex-1 flex items-center justify-center gap-2 px-4 py-2.5 bg-blue-500 text-white rounded-lg font-medium transition-colors hover:bg-blue-600 disabled:opacity-50"
>
{syncing === bot.id ? (
<>
<RefreshCw size={16} className="animate-spin" />
<span>동기화 ...</span>
</>
) : (
<>
<Download size={16} />
<span>전체 동기화</span>
</>
)}
</button>
<button
onClick={() => toggleBot(bot.id, bot.status, bot.name)}
className={`flex items-center justify-center gap-2 px-4 py-2.5 rounded-lg font-medium transition-colors ${
bot.status === 'running'
? 'bg-gray-100 text-gray-600 hover:bg-gray-200'
: 'bg-green-500 text-white hover:bg-green-600'
}`}
>
{bot.status === 'running' ? (
<>
<Square size={16} />
<span>정지</span>
</>
) : (
<>
<Play size={16} />
<span>시작</span>
</>
)}
</button>
</div>
</div>
</motion.div>
);
})}
</div>
)}
</div>
</main>
</div>

View file

@ -1031,8 +1031,13 @@ function AdminScheduleForm() {
throw new Error(error.error || (isEditMode ? '일정 수정에 실패했습니다.' : '일정 생성에 실패했습니다.'));
}
setToast({ type: 'success', message: isEditMode ? '일정이 수정되었습니다.' : '일정이 추가되었습니다.' });
setTimeout(() => navigate('/admin/schedule'), 1500);
// sessionStorage
sessionStorage.setItem('scheduleToast', JSON.stringify({
type: 'success',
message: isEditMode ? '일정이 수정되었습니다.' : '일정이 추가되었습니다.'
}));
navigate('/admin/schedule');
} catch (error) {
console.error('일정 저장 오류:', error);
setToast({ type: 'error', message: error.message || '일정 저장 중 오류가 발생했습니다.' });