Remove unused code. Add utils.ts

This commit is contained in:
schooltechx 2023-04-10 14:41:43 +07:00
parent 0348e6b72e
commit ea07766fd8
9 changed files with 34 additions and 112 deletions

View file

@ -1,6 +1,7 @@
import {qualifyingBase} from '$lib/data/CMSDataType'
import { error } from '@sveltejs/kit';
import type {CalendarEvent,Exam} from '$lib/data/CMSDataType'
import {getBgColorDict} from '$lib/utils'
import dayjs from 'dayjs'
import type { PageServerLoad } from './$types'
export const load: PageServerLoad = async ({fetch}) => {
@ -8,28 +9,20 @@ export const load: PageServerLoad = async ({fetch}) => {
if(!res.ok)
throw error(res.status, 'ไม่สามารถอ่านข้อมูลการสอบได้');
const exams:Exam[] = await res.json()
const catColor = {};
const events:CalendarEvent[]=[]
exams.forEach((ex)=>{
const {id,title,start,end,category_id} = ex
let backgroundColor ="#23ccef"
switch (String(category_id)) {
case "1":
backgroundColor="rgba(251,64,75,.2)"
break;
case "2":
backgroundColor="#23ccef"
break;
case "3":
backgroundColor="rgba(68,125,247,.2)"
break;
default:
break;
}
const {id,title,start,end,category} = ex
if(!category)
return
const backgroundColor = getBgColorDict(category,catColor)
const url = "/qualifying/"+id
if(start){
ex.date = dayjs(start).format("DD MMM BBBB")
events.push({id,title,start,end,url,backgroundColor})
console.log({id,title,start,end,url,backgroundColor})
events.push({id,title,start,url,backgroundColor})
}
if(ex.exam_date){
events.push({id,"title":"วันสอบคัดเลือก","start":ex.exam_date,url,backgroundColor})