-
Notifications
You must be signed in to change notification settings - Fork 195
feat: settings tab in sidebar #2968
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 38 commits
6b75429
c73592f
de603d0
6589d41
282f413
eb1d263
9f8cf07
2f35b4f
dc80c6b
7437997
a451570
e4d319b
f98c070
cb84690
5e5494d
b1a76cd
80fed93
0fc2392
7270d10
d459c08
66db837
f457cf7
ee779ee
9b79bf9
b20509e
5f9442b
6fe15b5
06038c1
f6e9d97
6e4a438
f9461a9
a28b7ea
df741fd
4a86b2f
cab1c5c
03993ab
d82b781
dbb2458
cada6a7
df98f8a
b85ba7e
e919cf1
dd99aef
72edea9
421bd7b
d628cd1
6080bbb
cc52c35
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,12 +6,13 @@ import { | |
| ConfigureUnitData, | ||
| StaticFileNotices, | ||
| } from '@src/course-outline/data/types'; | ||
| import { useToastContext } from '@src/generic/toast-context'; | ||
| import { NOTIFICATION_MESSAGES } from '@src/constants'; | ||
| import { getNotificationMessage } from '@src/course-unit/data/utils'; | ||
| import { createGlobalState } from '@src/data/apiHooks'; | ||
| import type { XBlockBase, XblockChildInfo } from '@src/data/types'; | ||
| import { getBlockType, getCourseKey } from '@src/generic/key-utils'; | ||
| import { useMutationWithProcessingNotification } from '@src/generic/processing-notification/data/apiHooks'; | ||
| import { handleResponseErrors } from '@src/generic/saving-error-alert'; | ||
| import { useToastContext } from '@src/generic/toast-context'; | ||
| import { ParentIds } from '@src/generic/types'; | ||
| import { | ||
| QueryClient, | ||
|
|
@@ -85,7 +86,7 @@ export const useScrollState = createGlobalState<ScrollState>(courseOutlineQueryK | |
| * 1. If sectionId exists, invalidate section data which also updates all children block data | ||
| * 2. Else If subsectionId exists, invalidate subsection data | ||
| */ | ||
| const invalidateParentQueries = async (queryClient: QueryClient, variables: ParentIds) => { | ||
| export const invalidateParentQueries = async (queryClient: QueryClient, variables: ParentIds) => { | ||
| if (variables.sectionId) { | ||
| await queryClient.invalidateQueries({ queryKey: courseOutlineQueryKeys.courseItemId(variables.sectionId) }); | ||
| } else if (variables.subsectionId) { | ||
|
|
@@ -108,20 +109,12 @@ export const useCreateCourseBlock = ( | |
| courseKey: string, | ||
| callback?: ((locator: string, parentLocator: string) => Promise<void>), | ||
| ) => { | ||
| const { | ||
| showToast, | ||
| closeToast, | ||
| } = useToastContext(); | ||
| const queryClient = useQueryClient(); | ||
| const { setData } = useScrollState(courseKey); | ||
| const dispatch = useDispatch(); | ||
| return useMutation({ | ||
| return useMutationWithProcessingNotification({ | ||
| mutationFn: (variables: CreateCourseXBlockMutationProps) => createCourseXblock(variables), | ||
| onMutate: () => { | ||
| showToast(NOTIFICATION_MESSAGES.saving, undefined, 15000); | ||
| }, | ||
| onSuccess: async (data: { locator: string; }, variables) => { | ||
| closeToast(); | ||
| await callback?.(data.locator, variables.parentLocator); | ||
| queryClient.invalidateQueries({ | ||
| queryKey: courseOutlineQueryKeys.courseDetails(getCourseKey(data.locator)), | ||
|
|
@@ -136,9 +129,6 @@ export const useCreateCourseBlock = ( | |
| dispatch(addSection(newBlock)); | ||
| } | ||
| }, | ||
| onError: () => { | ||
| closeToast(); | ||
| }, | ||
| }); | ||
| }; | ||
|
|
||
|
|
@@ -198,7 +188,7 @@ export const useCourseDetails = (courseId?: string, enabled: boolean = true) => | |
| */ | ||
| export const useUpdateCourseBlockName = (courseId: string) => { | ||
| const queryClient = useQueryClient(); | ||
| return useMutation({ | ||
| return useMutationWithProcessingNotification({ | ||
| mutationFn: (variables:{ | ||
| itemId: string; | ||
| displayName: string; | ||
|
|
@@ -213,7 +203,7 @@ export const useUpdateCourseBlockName = (courseId: string) => { | |
|
|
||
| export const usePublishCourseItem = () => { | ||
| const queryClient = useQueryClient(); | ||
| return useMutation({ | ||
| return useMutationWithProcessingNotification({ | ||
| mutationFn: (variables:{ | ||
| itemId: string; | ||
| } & ParentIds) => publishCourseItem(variables.itemId), | ||
|
|
@@ -226,7 +216,7 @@ export const usePublishCourseItem = () => { | |
|
|
||
| export const useDeleteCourseItem = () => { | ||
| const queryClient = useQueryClient(); | ||
| return useMutation({ | ||
| return useMutationWithProcessingNotification({ | ||
| mutationFn: (variables:{ | ||
| itemId: string; | ||
| } & ParentIds) => deleteCourseItem(variables.itemId), | ||
|
|
@@ -239,17 +229,9 @@ export const useDeleteCourseItem = () => { | |
|
|
||
| export const useConfigureSection = () => { | ||
| const queryClient = useQueryClient(); | ||
| const { | ||
| showToast, | ||
| closeToast, | ||
| } = useToastContext(); | ||
| return useMutation({ | ||
| return useMutationWithProcessingNotification({ | ||
| mutationFn: (variables: ConfigureSectionData & ParentIds) => configureCourseSection(variables), | ||
| onMutate: () => { | ||
| showToast(NOTIFICATION_MESSAGES.saving, undefined, 15000); | ||
| }, | ||
| onSettled: (_data, _err, variables) => { | ||
| closeToast(); | ||
| queryClient.invalidateQueries({ | ||
| queryKey: courseOutlineQueryKeys.courseDetails(getCourseKey(variables.sectionId)), | ||
| }); | ||
|
|
@@ -260,17 +242,9 @@ export const useConfigureSection = () => { | |
|
|
||
| export const useConfigureSubsection = () => { | ||
| const queryClient = useQueryClient(); | ||
| const { | ||
| showToast, | ||
| closeToast, | ||
| } = useToastContext(); | ||
| return useMutation({ | ||
| return useMutationWithProcessingNotification({ | ||
| mutationFn: (variables: ConfigureSubsectionData & ParentIds) => configureCourseSubsection(variables), | ||
| onMutate: () => { | ||
| showToast(NOTIFICATION_MESSAGES.saving, undefined, 15000); | ||
| }, | ||
| onSettled: (_data, _err, variables) => { | ||
| closeToast(); | ||
| queryClient.invalidateQueries({ queryKey: courseOutlineQueryKeys.courseDetails(getCourseKey(variables.itemId)) }); | ||
| invalidateParentQueries(queryClient, variables).catch((e) => handleResponseErrors(e)); | ||
| }, | ||
|
|
@@ -279,39 +253,30 @@ export const useConfigureSubsection = () => { | |
|
|
||
| export const useConfigureUnit = () => { | ||
| const queryClient = useQueryClient(); | ||
| const { | ||
| showToast, | ||
| closeToast, | ||
| } = useToastContext(); | ||
| const { showToast, closeToast } = useToastContext(); | ||
| return useMutation({ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we use the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, we have special message to display here. i'll add a comment |
||
| mutationFn: (variables: ConfigureUnitData & ParentIds) => configureCourseUnit(variables), | ||
| onMutate: () => { | ||
| showToast(NOTIFICATION_MESSAGES.saving, undefined, 15000); | ||
| onMutate: (variables) => { | ||
| const msg = getNotificationMessage(variables.type, variables.isVisibleToStaffOnly, true); | ||
| // Show processing notification | ||
| showToast(msg, undefined, 15000); | ||
| }, | ||
| onSettled: (_data, _err, variables) => { | ||
| closeToast(); | ||
| queryClient.invalidateQueries({ queryKey: courseOutlineQueryKeys.courseDetails(getCourseKey(variables.unitId)) }); | ||
| invalidateParentQueries(queryClient, variables).catch((e) => handleResponseErrors(e)); | ||
| closeToast(); | ||
| }, | ||
| }); | ||
| }; | ||
|
|
||
| export const useUpdateCourseSectionHighlights = () => { | ||
| const { | ||
| showToast, | ||
| closeToast, | ||
| } = useToastContext(); | ||
| const queryClient = useQueryClient(); | ||
| return useMutation({ | ||
| return useMutationWithProcessingNotification({ | ||
| mutationFn: (variables: { | ||
| sectionId: string; | ||
| highlights: string[]; | ||
| } & ParentIds) => updateCourseSectionHighlights(variables.sectionId, variables.highlights), | ||
| onMutate: () => { | ||
| showToast(NOTIFICATION_MESSAGES.saving, undefined, 15000); | ||
| }, | ||
| onSettled: (_data, _err, variables) => { | ||
| closeToast(); | ||
| queryClient.invalidateQueries({ | ||
| queryKey: courseOutlineQueryKeys.courseDetails(getCourseKey(variables.sectionId)), | ||
| }); | ||
|
|
@@ -321,21 +286,14 @@ export const useUpdateCourseSectionHighlights = () => { | |
| }; | ||
|
|
||
| export const useDuplicateItem = (courseKey: string) => { | ||
| const { | ||
| showToast, | ||
| closeToast, | ||
| } = useToastContext(); | ||
| const queryClient = useQueryClient(); | ||
| const dispatch = useDispatch(); | ||
| const { setData } = useScrollState(courseKey); | ||
| return useMutation({ | ||
| return useMutationWithProcessingNotification({ | ||
| mutationFn: (variables: { | ||
| itemId: string; | ||
| parentId: string; | ||
| } & ParentIds) => duplicateCourseItem(variables.itemId, variables.parentId), | ||
| onMutate: () => { | ||
| showToast(NOTIFICATION_MESSAGES.saving, undefined, 15000); | ||
| }, | ||
| onSuccess: async (data, variables) => { | ||
| await invalidateParentQueries(queryClient, variables); | ||
| // add duplicated section to store, subsection and unit are handled by invalidateParentQueries | ||
|
|
@@ -346,9 +304,6 @@ export const useDuplicateItem = (courseKey: string) => { | |
| // scroll to newly added block | ||
| setData({ id: data.locator }); | ||
| }, | ||
| onSettled: () => { | ||
| closeToast(); | ||
| }, | ||
| }); | ||
| }; | ||
|
|
||
|
|
@@ -362,29 +317,19 @@ export const usePasteFileNotices = createGlobalState<StaticFileNotices>( | |
| ); | ||
|
|
||
| export const usePasteItem = (courseId?: string) => { | ||
| const { | ||
| showToast, | ||
| closeToast, | ||
| } = useToastContext(); | ||
| const queryClient = useQueryClient(); | ||
| const { setData: setScrollState } = useScrollState(courseId); | ||
| const { setData } = usePasteFileNotices(courseId); | ||
| return useMutation({ | ||
| return useMutationWithProcessingNotification({ | ||
| mutationFn: (variables: { | ||
| parentLocator: string; | ||
| } & ParentIds) => pasteBlock(variables.parentLocator), | ||
| onMutate: () => { | ||
| showToast(NOTIFICATION_MESSAGES.saving, undefined, 15000); | ||
| }, | ||
| onSuccess: async (data, variables) => { | ||
| await invalidateParentQueries(queryClient, variables); | ||
| // set pasteFileNotices | ||
| setData(data.staticFileNotices); | ||
| // scroll to pasted block | ||
| setScrollState({ id: data.locator }); | ||
| }, | ||
| onSettled: () => { | ||
| closeToast(); | ||
| }, | ||
| }); | ||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice clean-up! 👍