Merge pull request #354 from chrishollandaise/fix/activity-chapter-elements

Fixing various bugs in the `ActivityElement` component
This commit is contained in:
Badr B. 2024-10-20 23:37:32 +02:00 committed by GitHub
commit 19cc3ea0d7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 97 additions and 112 deletions

View file

@ -88,7 +88,7 @@ function ActivityElement(props: ActivitiyElementProps) {
modifiedActivity?.activityId === activityId && modifiedActivity?.activityId === activityId &&
selectedActivity !== undefined selectedActivity !== undefined
) { ) {
setSelectedActivity(undefined)
let modifiedActivityCopy = { let modifiedActivityCopy = {
...props.activity, ...props.activity,
name: modifiedActivity.activityName, name: modifiedActivity.activityName,
@ -99,6 +99,7 @@ function ActivityElement(props: ActivitiyElementProps) {
await revalidateTags(['courses'], props.orgslug) await revalidateTags(['courses'], props.orgslug)
router.refresh() router.refresh()
} }
setSelectedActivity(undefined)
} }
return ( return (
@ -109,7 +110,7 @@ function ActivityElement(props: ActivitiyElementProps) {
> >
{(provided, snapshot) => ( {(provided, snapshot) => (
<div <div
className="flex flex-row py-2 my-2 w-full rounded-md bg-gray-50 text-gray-500 hover:bg-gray-100 hover:scale-102 hover:shadow space-x-1 items-center ring-1 ring-inset ring-gray-400/10 shadow-sm transition-all delay-100 duration-75 ease-linear" className="flex flex-row py-2 my-2 w-full rounded-md bg-gray-50 text-gray-500 hover:bg-gray-100 hover:scale-102 hover:shadow space-x-1 items-center ring-1 ring-inset ring-gray-400/10 shadow-sm"
key={props.activity.id} key={props.activity.id}
{...provided.draggableProps} {...provided.draggableProps}
{...provided.dragHandleProps} {...provided.dragHandleProps}
@ -143,8 +144,7 @@ function ActivityElement(props: ActivitiyElementProps) {
className="bg-transparent text-neutral-700 hover:cursor-pointer hover:text-neutral-900" className="bg-transparent text-neutral-700 hover:cursor-pointer hover:text-neutral-900"
> >
<Save <Save
size={11} size={12}
onClick={() => updateActivityName(props.activity.id)}
/> />
</button> </button>
</div> </div>
@ -153,13 +153,13 @@ function ActivityElement(props: ActivitiyElementProps) {
)} )}
<Pencil <Pencil
onClick={() => setSelectedActivity(props.activity.id)} onClick={() => setSelectedActivity(props.activity.id)}
size={12} className="text-neutral-400 hover:cursor-pointer size-3 min-w-3"
className="text-neutral-400 hover:cursor-pointer"
/> />
</div> </div>
{/* Edit and View Button */} {/* Edit and View Button */}
<div className="flex basis-1/2 justify-end">
<div className="flex flex-row space-x-2"> <div className="flex flex-row space-x-2">
<ActivityElementOptions activity={props.activity} /> <ActivityElementOptions activity={props.activity} />
{/* Publishing */} {/* Publishing */}
@ -217,58 +217,42 @@ function ActivityElement(props: ActivitiyElementProps) {
></ConfirmationModal> ></ConfirmationModal>
</div> </div>
</div> </div>
</div>
)} )}
</Draggable> </Draggable>
) )
} }
const ActivityTypeIndicator = (props: { activityType: string }) => { const ACTIVITIES = {
'TYPE_VIDEO': {
displayName: 'Video',
Icon: Video
},
'TYPE_DOCUMENT': {
displayName: 'Document',
Icon: File
},
'TYPE_ASSIGNMENT': {
displayName: 'Assignment',
Icon: Backpack
},
'TYPE_DYNAMIC': {
displayName: 'Dynamic',
Icon: Sparkles
}
}
const ActivityTypeIndicator = ({activityType} : { activityType: keyof typeof ACTIVITIES}) => {
const {displayName, Icon} = ACTIVITIES[activityType]
return ( return (
<div className="px-3 text-gray-300 space-x-1 w-28"> <div className="px-3 text-gray-300 space-x-1 w-28 flex">
{props.activityType === 'TYPE_VIDEO' && (
<>
<div className="flex space-x-2 items-center"> <div className="flex space-x-2 items-center">
<Video size={16} />{' '} <Icon className="size-4" />{' '}
<div className="text-xs bg-gray-200 text-gray-400 font-bold px-2 py-1 rounded-full mx-auto justify-center align-middle"> <div className="text-xs bg-gray-200 text-gray-400 font-bold px-2 py-1 rounded-full mx-auto justify-center align-middle">
Video {displayName}
</div>{' '} </div>{' '}
</div> </div>
</>
)}
{props.activityType === 'TYPE_DOCUMENT' && (
<>
<div className="flex space-x-2 items-center">
<div className="w-[30px]">
<File size={16} />{' '}
</div>
<div className="text-xs bg-gray-200 text-gray-400 font-bold px-2 py-1 rounded-full">
Document
</div>{' '}
</div>
</>
)}
{props.activityType === 'TYPE_ASSIGNMENT' && (
<>
<div className="flex space-x-2 items-center">
<div className="w-[30px]">
<Backpack size={16} />{' '}
</div>
<div className="text-xs bg-gray-200 text-gray-400 font-bold px-2 py-1 rounded-full">
Assignment
</div>{' '}
</div>
</>
)}
{props.activityType === 'TYPE_DYNAMIC' && (
<>
<div className="flex space-x-2 items-center">
<Sparkles size={16} />{' '}
<div className="text-xs bg-gray-200 text-gray-400 font-bold px-2 py-1 rounded-full">
Dynamic
</div>{' '}
</div>
</>
)}
</div> </div>
) )
} }
@ -280,7 +264,7 @@ const ActivityElementOptions = ({ activity }: any) => {
const session = useLHSession() as any; const session = useLHSession() as any;
const access_token = session?.data?.tokens?.access_token; const access_token = session?.data?.tokens?.access_token;
async function getAssignmentUUIDFromActivityUUID(activityUUID: string) { async function getAssignmentUUIDFromActivityUUID(activityUUID: string): Promise<string | undefined> {
const activity = await getAssignmentFromActivityUUID(activityUUID, access_token); const activity = await getAssignmentFromActivityUUID(activityUUID, access_token);
if (activity) { if (activity) {
return activity.data.assignment_uuid; return activity.data.assignment_uuid;
@ -290,6 +274,7 @@ const ActivityElementOptions = ({ activity }: any) => {
const fetchAssignmentUUID = async () => { const fetchAssignmentUUID = async () => {
if (activity.activity_type === 'TYPE_ASSIGNMENT') { if (activity.activity_type === 'TYPE_ASSIGNMENT') {
const assignment_uuid = await getAssignmentUUIDFromActivityUUID(activity.activity_uuid); const assignment_uuid = await getAssignmentUUIDFromActivityUUID(activity.activity_uuid);
if(assignment_uuid)
setAssignmentUUID(assignment_uuid.replace('assignment_', '')); setAssignmentUUID(assignment_uuid.replace('assignment_', ''));
} }
}; };
@ -323,7 +308,7 @@ const ActivityElementOptions = ({ activity }: any) => {
</Link> </Link>
</> </>
)} )}
{activity.activity_type === 'TYPE_ASSIGNMENT' && assignmentUUID && ( {activity.activity_type === 'TYPE_ASSIGNMENT' && (
<> <>
<Link <Link
href={ href={

View file

@ -52,7 +52,6 @@ function ChapterElement(props: ChapterElementProps) {
async function updateChapterName(chapterId: string) { async function updateChapterName(chapterId: string) {
if (modifiedChapter?.chapterId === chapterId) { if (modifiedChapter?.chapterId === chapterId) {
setSelectedChapter(undefined)
let modifiedChapterCopy = { let modifiedChapterCopy = {
name: modifiedChapter.chapterName, name: modifiedChapter.chapterName,
} }
@ -61,6 +60,7 @@ function ChapterElement(props: ChapterElementProps) {
await revalidateTags(['courses'], props.orgslug) await revalidateTags(['courses'], props.orgslug)
router.refresh() router.refresh()
} }
setSelectedChapter(undefined)
} }
return ( return (
@ -155,7 +155,7 @@ function ChapterElement(props: ChapterElementProps) {
<div className="flex flex-col"> <div className="flex flex-col">
{activities.map((activity: any, index: any) => { {activities.map((activity: any, index: any) => {
return ( return (
<div key={index} className="flex items-center "> <div key={activity.activity_uuid} className="flex items-center ">
<ActivityElement <ActivityElement
orgslug={props.orgslug} orgslug={props.orgslug}
course_uuid={props.course_uuid} course_uuid={props.course_uuid}

View file

@ -46,7 +46,6 @@ function Activity(props: any) {
modifiedActivity?.activityId === activityId && modifiedActivity?.activityId === activityId &&
selectedActivity !== undefined selectedActivity !== undefined
) { ) {
setSelectedActivity(undefined)
let modifiedActivityCopy = { let modifiedActivityCopy = {
...props.activity, ...props.activity,
name: modifiedActivity.activityName, name: modifiedActivity.activityName,
@ -57,6 +56,7 @@ function Activity(props: any) {
await revalidateTags(['courses'], props.orgslug) await revalidateTags(['courses'], props.orgslug)
router.refresh() router.refresh()
} }
setSelectedActivity(undefined)
} }
return ( return (

View file

@ -28,7 +28,6 @@ function Chapter(props: any) {
async function updateChapterName(chapterId: string) { async function updateChapterName(chapterId: string) {
if (modifiedChapter?.chapterId === chapterId) { if (modifiedChapter?.chapterId === chapterId) {
setSelectedChapter(undefined)
let modifiedChapterCopy = { let modifiedChapterCopy = {
name: modifiedChapter.chapterName, name: modifiedChapter.chapterName,
} }
@ -37,6 +36,7 @@ function Chapter(props: any) {
await revalidateTags(['courses'], props.orgslug) await revalidateTags(['courses'], props.orgslug)
router.refresh() router.refresh()
} }
setSelectedChapter(undefined)
} }
return ( return (