-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f625a7a
commit 56b3efd
Showing
35 changed files
with
446 additions
and
435 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 23 additions & 23 deletions
46
src/components/domains/ContentModal/hooks/useFetchData.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,59 @@ | ||
import { useState } from 'react'; | ||
import { useState } from 'react' | ||
|
||
import type { ActivityType, Course } from '@/types'; | ||
import type { ActivityType, Course } from '@/types' | ||
|
||
import { getActivities, getCourses } from '@/services'; | ||
import { allProgress } from '@/utils'; | ||
import { getActivities, getCourses } from '@/services' | ||
import { allProgress } from '@/utils' | ||
|
||
type dataType = { | ||
courseList: Course[]; | ||
activityList: ActivityType[]; | ||
updateAt: number; | ||
}; | ||
courseList: Course[] | ||
activityList: ActivityType[] | ||
updateAt: number | ||
} | ||
|
||
const useFetchData = () => { | ||
const [pos, setPos] = useState(0); | ||
const [pos, setPos] = useState(0) | ||
const [data, setData] = useState<dataType>({ | ||
courseList: [{ id: '-1', title: '전체' }], | ||
activityList: [], | ||
updateAt: 0, | ||
}); | ||
}) | ||
|
||
const getData = async () => { | ||
const courses = await getCourses(); | ||
const courses = await getCourses() | ||
const activities = await allProgress( | ||
courses.map(course => getActivities(course.id)), | ||
progress => setPos(progress), | ||
).then(activities => activities.flat()); | ||
).then(activities => activities.flat()) | ||
|
||
const updateAt = new Date().getTime(); | ||
const updateAt = new Date().getTime() | ||
|
||
setData({ | ||
courseList: [{ id: '-1', title: '전체' }, ...courses], | ||
activityList: activities, | ||
updateAt, | ||
}); | ||
}) | ||
|
||
setPos(0); | ||
setPos(0) | ||
|
||
chrome.storage.local.set({ | ||
courses, | ||
activities, | ||
updateAt, | ||
}); | ||
}; | ||
}) | ||
} | ||
|
||
const getLocalData = () => { | ||
chrome.storage.local.get(({ updateAt, courses, activities }) => { | ||
setData({ | ||
courseList: [{ id: '-1', title: '전체' }, ...courses], | ||
activityList: activities, | ||
updateAt, | ||
}); | ||
}); | ||
}; | ||
}) | ||
}) | ||
} | ||
|
||
return [getData, getLocalData, data, pos] as const; | ||
}; | ||
return [getData, getLocalData, data, pos] as const | ||
} | ||
|
||
export default useFetchData; | ||
export default useFetchData |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,25 @@ | ||
import { useState } from 'react'; | ||
import { useState } from 'react' | ||
|
||
import Toggle from '@/components/uis/Toggle'; | ||
import Toggle from '@/components/uis/Toggle' | ||
|
||
interface OptionItemProps { | ||
text: string; | ||
text: string | ||
} | ||
|
||
const OptionItem = ({ text }: OptionItemProps) => { | ||
const [isOn, setIsOn] = useState(false); | ||
const [isOn, setIsOn] = useState(false) | ||
|
||
const toggleSwitch = () => { | ||
setIsOn(prev => !prev); | ||
setIsOn(prev => !prev) | ||
// TODO: Save the option to the local storage | ||
}; | ||
} | ||
|
||
return ( | ||
<li className="flex items-center"> | ||
<p>{text}</p> | ||
<Toggle isOn={isOn} toggleSwitch={toggleSwitch} /> | ||
</li> | ||
); | ||
}; | ||
) | ||
} | ||
|
||
export default OptionItem; | ||
export default OptionItem |
Oops, something went wrong.