Skip to content

Commit

Permalink
Fix lint and type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
zichongkao committed May 17, 2023
1 parent 0de8660 commit b35c3ab
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
13 changes: 6 additions & 7 deletions src/components/edit/AreaCRUD.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { AreaSummaryType } from '../crag/cragSummary'
import { DeleteAreaTrigger, AddAreaTrigger, AddAreaTriggerButtonMd, AddAreaTriggerButtonSm, DeleteAreaTriggerButtonSm } from './Triggers'
import { AreaEntityIcon } from '../EntityIcons'
import NetworkSquareIcon from '../../assets/icons/network-square-icon.svg'
import React, { useEffect, useState } from 'react'
import React, { useState } from 'react'
import { DragDropContext, Draggable, Droppable } from 'react-beautiful-dnd'
import useUpdateAreasCmd from '../../js/hooks/useUpdateAreasCmd'
import { useSession } from 'next-auth/react'

export type AreaCRUDProps = Pick<AreaType, 'uuid' | 'areaName'> & {
childAreas: any
childAreas: AreaType[]
editMode: boolean
onChange: () => void
}
Expand All @@ -24,14 +24,14 @@ export const AreaCRUD = ({ uuid: parentUuid, areaName: parentName, childAreas, e
const session = useSession()
const areaCount = childAreas.length

const [childAreasState, setChildAreasState] = useState<Array<AreaType>>(childAreas)
const [childAreasState, setChildAreasState] = useState<AreaType[]>(childAreas)

const { updateAreasSortingOrderCmd } = useUpdateAreasCmd({
areaId: parentUuid,
accessToken: session?.data?.accessToken as string ?? '',
accessToken: session?.data?.accessToken as string ?? ''
})

function reorder<T>(list: Array<T>, startIndex: number, endIndex: number): Array<T> {
function reorder<T> (list: T[], startIndex: number, endIndex: number): T[] {
const result = Array.from(list)
const [removed] = result.splice(startIndex, 1)
result.splice(endIndex, 0, removed)
Expand All @@ -53,7 +53,7 @@ export const AreaCRUD = ({ uuid: parentUuid, areaName: parentName, childAreas, e
result.destination.index
)

updateAreasSortingOrderCmd(reorderedChildAreas.map((area, idx) => ({ areaId: area.uuid, leftRightIndex: idx })))
void updateAreasSortingOrderCmd(reorderedChildAreas.map((area, idx) => ({ areaId: area.uuid, leftRightIndex: idx })))
setChildAreasState(reorderedChildAreas)
}

Expand Down Expand Up @@ -108,7 +108,6 @@ export const AreaCRUD = ({ uuid: parentUuid, areaName: parentName, childAreas, e
{...provided.dragHandleProps}
>
<AreaItem
ref={provided.innerRef}
{...provided.draggableProps}
key={i.uuid}
index={idx}
Expand Down
6 changes: 3 additions & 3 deletions src/js/hooks/useUpdateAreasCmd.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type UpdateOneAreaCmdType = (input: UpdateOneAreaInputType) => Promise<void>
type AddOneAreCmdType = ({ name, parentUuid }: AddAreaProps) => Promise<void>
type DeleteOneAreaCmdType = ({ uuid }: DeleteOneAreaInputType) => Promise<void>
type GetAreaByIdCmdType = ({ skip }: { skip?: boolean }) => QueryResult<{ area: AreaType}>
type UpdateAreasSortingOrderCmdType = (input: Array<AreaSortingInput>) => Promise<void>
type UpdateAreasSortingOrderCmdType = (input: AreaSortingInput[]) => Promise<void>

interface CallbackProps {
onUpdateCompleted?: (data: any) => void
Expand Down Expand Up @@ -91,7 +91,7 @@ export default function useUpdateAreasCmd ({ areaId, accessToken = '', ...props
})
}

const [updateAreasSortingOrder] = useMutation<{ updateAreaSortingOrder: any }, { input: Array<AreaSortingInput> }>(
const [updateAreasSortingOrder] = useMutation<{ updateAreaSortingOrder: any }, { input: AreaSortingInput[] }>(
MUTATION_UPDATE_AREAS_SORTING_ORDER, {
client: graphqlClient,
onCompleted: async (data) => {
Expand All @@ -104,7 +104,7 @@ export default function useUpdateAreasCmd ({ areaId, accessToken = '', ...props
}
)

const updateAreasSortingOrderCmd: UpdateAreasSortingOrderCmdType = async (input: Array<AreaSortingInput>) => {
const updateAreasSortingOrderCmd: UpdateAreasSortingOrderCmdType = async (input: AreaSortingInput[]) => {
console.log('updateAreasSortingOrderCmd input', input)
await updateAreasSortingOrder({
variables: { input },
Expand Down

0 comments on commit b35c3ab

Please sign in to comment.