Skip to content

Commit

Permalink
fix(edit-course): display all lessons under block
Browse files Browse the repository at this point in the history
  • Loading branch information
danilych committed Feb 12, 2024
1 parent dfa1df3 commit 3b8d9c7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/features/hidden-list-component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export function HiddenListComponent({
<div
className={clsx(
' duration-1400 transition-all ease-in-out flex flex-col gap-2',
isVisibly ? 'max-h-72' : 'max-h-0 overflow-hidden'
isVisibly ? '' : 'max-h-0 overflow-hidden'
)}
>
{items.map((item: any, index: number) => (
Expand Down
25 changes: 25 additions & 0 deletions app/redux/slices/course.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ export const fetchCourse = createAsyncThunk(
}
)

export const fetchFullCourse = createAsyncThunk(
'course/fetchFullCourse',
async (params: any) => {
const { data } = await instance.post('/Course/GetCourseInfoList', params)

return data
}
)

export const updateBlock = createAsyncThunk(
'course/updateBlock',
async (params: any) => {
Expand Down Expand Up @@ -75,6 +84,22 @@ const courseSlice = createSlice({
// @ts-ignore
state.course.data = null
})
builder.addCase(fetchFullCourse.pending, (state, action) => {
state.course.status = 'loading'

// @ts-ignore
state.course.data = null
})
builder.addCase(fetchFullCourse.fulfilled, (state, action) => {
state.course.status = 'loaded'
state.course.data = action.payload
})
builder.addCase(fetchFullCourse.rejected, (state, action) => {
state.course.status = 'error'

// @ts-ignore
state.course.data = null
})
builder.addCase(updateBlock.fulfilled, (state, action) => {
state.course.status = 'loaded'
state.course.isError = action.payload.isError
Expand Down
6 changes: 3 additions & 3 deletions app/routes/edit-course.$course.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useForm } from 'react-hook-form'
import toast from 'react-hot-toast'
import { useDispatch, useSelector } from 'react-redux'
import { HiddenListComponent } from '~/features'
import { fetchCourse, updateBlock } from '~/redux/slices/course'
import { fetchCourse, fetchFullCourse, updateBlock } from '~/redux/slices/course'

Check failure on line 9 in app/routes/edit-course.$course.tsx

View workflow job for this annotation

GitHub Actions / pipeline (21.x)

'fetchCourse' is defined but never used

Check failure on line 9 in app/routes/edit-course.$course.tsx

View workflow job for this annotation

GitHub Actions / pipeline (21.x)

'fetchCourse' is defined but never used
import {
Header3,
Header4,
Expand Down Expand Up @@ -38,11 +38,11 @@ export default function Course() {

useEffect(() => {
let formData = new FormData()
formData.append('CourseID', params.course as string)
formData.append('ID', params.course as string)
console.log(params.course)
// formData.append('UserID', window.localStorage.getItem("userId") as string)

dispatch(fetchCourse(formData))
dispatch(fetchFullCourse(formData))
}, [])

Check warning on line 46 in app/routes/edit-course.$course.tsx

View workflow job for this annotation

GitHub Actions / pipeline (21.x)

React Hook useEffect has missing dependencies: 'dispatch' and 'params.course'. Either include them or remove the dependency array

useEffect(() => {

Check warning on line 48 in app/routes/edit-course.$course.tsx

View workflow job for this annotation

GitHub Actions / pipeline (21.x)

React Hook useEffect contains a call to 'setIsPostLoading'. Without a list of dependencies, this can lead to an infinite chain of updates. To fix this, pass [course.status] as a second argument to the useEffect Hook
Expand Down

0 comments on commit 3b8d9c7

Please sign in to comment.