Skip to content
Snippets Groups Projects
Commit 67d3d663 authored by brunoravera's avatar brunoravera
Browse files

animations list

parent 7235b3ad
No related branches found
No related tags found
No related merge requests found
...@@ -23,16 +23,18 @@ import { FaPlay, FaTrash } from 'react-icons/fa' ...@@ -23,16 +23,18 @@ import { FaPlay, FaTrash } from 'react-icons/fa'
import { Animation, Pattern } from 'src/models' import { Animation, Pattern } from 'src/models'
import { GetPatternQuery } from '../patterns/query-builder' import { GetPatternQuery } from '../patterns/query-builder'
import { AddAnimationModal } from './add-animation' import { AddAnimationModal } from './add-animation'
import { GetAnimationsQuery } from './query-builder'
const tableHeaders = ['Titulo', 'Descripcion', 'Fecha de creacion', ''] const tableHeaders = ['Nombre', 'Descripcion', '']
export type AnimationsProps = { export type AnimationsProps = {
patternId: Pattern['id'] patternId: Pattern['id']
} }
export const Animations: React.FC<AnimationsProps> = ({ patternId }) => { export const Animations: React.FC<AnimationsProps> = ({ patternId }) => {
const patternQuery = GetPatternQuery.useQuery({ id: patternId }) const patternQuery = GetPatternQuery.useQuery({ id: patternId })
const animationsQuery = GetAnimationsQuery.useQuery({ patternId })
const addAnimationDisclosure = useDisclosure() const addAnimationDisclosure = useDisclosure()
const animations = [] const animations = animationsQuery.data ?? []
const tableCaption = const tableCaption =
animations.length === 0 animations.length === 0
...@@ -53,8 +55,8 @@ export const Animations: React.FC<AnimationsProps> = ({ patternId }) => { ...@@ -53,8 +55,8 @@ export const Animations: React.FC<AnimationsProps> = ({ patternId }) => {
</Thead> </Thead>
<Tbody> <Tbody>
{animations.map((animation, index) => ( {animations.map((animation, index) => (
<Tr key={`animation-${animation.title}-${index}`}> <Tr key={`animation-${animation.name}-${index}`}>
<Td>{animation.title}</Td> <Td>{animation.name}</Td>
<Td> <Td>
<Tooltip label={animation.description} hasArrow> <Tooltip label={animation.description} hasArrow>
<Text isTruncated maxW="sm"> <Text isTruncated maxW="sm">
...@@ -62,7 +64,6 @@ export const Animations: React.FC<AnimationsProps> = ({ patternId }) => { ...@@ -62,7 +64,6 @@ export const Animations: React.FC<AnimationsProps> = ({ patternId }) => {
</Text> </Text>
</Tooltip> </Tooltip>
</Td> </Td>
<Td>{new Date(animation.creationDate).toUTCString()}</Td>
<Td> <Td>
<ActionsRow _animation={animation} /> <ActionsRow _animation={animation} />
</Td> </Td>
......
import { AxiosError } from 'axios'
import { useQuery as useRQ, UseQueryOptions } from 'react-query'
import { Animation, Pattern } from 'src/models'
import axiosService from 'src/services/axios-service'
export namespace GetAnimationsQuery {
export type Params = { patternId: Pattern['id'] }
export type Response = Animation[]
export const key = ['animations']
export const getKey = (params: Params) => [...key, params]
export const queryFn = (params: Params) =>
axiosService
.get<Response>(`/patterns/${params.patternId}/animations`)
.then((res) => res.data)
export const useQuery = <Select = Response>(
params: Params,
options: UseQueryOptions<Response, AxiosError, Select> = {}
) => {
return useRQ(getKey(params), () => queryFn(params), {
...options,
})
}
}
export * from './create-animation-mutation' export * from './create-animation-mutation'
export * from './get-animations-query'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment