Skip to content

Commit

Permalink
fix: Ordered imports properly
Browse files Browse the repository at this point in the history
  • Loading branch information
luan0ap committed Nov 15, 2022
1 parent 97e5483 commit eaa68cc
Show file tree
Hide file tree
Showing 13 changed files with 85 additions and 27 deletions.
3 changes: 3 additions & 0 deletions src/components/AudioPlayer/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { AudioPlayer } from './AudioPlayer'

export { AudioPlayer }
3 changes: 1 addition & 2 deletions src/components/InfiniteScrollGrid/InfiniteScrollGrid.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { useEffect } from 'react'

import { Grid, GridProps } from '@chakra-ui/react'
import { useInView } from 'react-intersection-observer'

Expand All @@ -10,7 +9,7 @@ export interface InfiniteScrollGridProps extends GridProps {
export function InfiniteScrollGrid({
onViewChange = () => void 0,
children,
maxHeight = 'md',
maxHeight = 'xl',
templateColumns = ['repeat(3, 1fr)', 'repeat(4, 1fr)', 'repeat(5, 1fr)'],
gap = 0,
...props
Expand Down
12 changes: 7 additions & 5 deletions src/contexts/Words.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import React, { createContext, ReactNode, useEffect, useState } from 'react'
import { QueryStatus } from '@tanstack/react-query'
import { AxiosResponse } from 'axios'

import useLocalStorage from 'hooks/useLocalStorage'
import { Dictionary as DictionaryService } from 'services/Dictionary'
import { IWordDefinition } from 'models/WordDefinition'
import { useFetch } from 'hooks/useQuery'
import { IWord } from 'models/Word'
import { IApiResponse } from 'lib/api'

import { Dictionary as DictionaryService } from 'services/Dictionary'

import useLocalStorage from 'hooks/useLocalStorage'
import { useFetch } from 'hooks/useQuery'

const useFavoriteWord = () => {
const [storage, setStorage] = useLocalStorage('@word-meaning/favorites')
Expand Down Expand Up @@ -40,7 +42,7 @@ interface WordsContextInterface {
selectedWord: IWord
setSelectedWord: React.Dispatch<React.SetStateAction<IWord>>
fetchWordDefinitionStatus: QueryStatus
wordDefinition: AxiosResponse<IWordDefinition[]> | undefined
wordDefinition: IApiResponse<IWordDefinition[]> | undefined
}

const WordsContext = createContext({} as WordsContextInterface)
Expand Down
23 changes: 23 additions & 0 deletions src/features/worddefinition/components/Meaning/Meaning.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React, { useMemo } from 'react'
import { Box, BoxProps } from '@chakra-ui/react'

import useWordContext from 'hooks/useWordContext'

interface Props extends BoxProps {
children: React.ReactNode
}

export function Meaning({ ...props }: Props) {
const { wordDefinition = { data: [] } } = useWordContext()
const [word] = wordDefinition.data

return (
<Box {...props}>
{word.meanings.map(meaning => {
return meaning.partOfSpeech
})}
</Box>
)
}

export default Meaning
3 changes: 3 additions & 0 deletions src/features/worddefinition/components/Meaning/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Meaning } from './Meaning'

export { Meaning }
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React, { useMemo } from 'react'
import { Box, BoxProps } from '@chakra-ui/react'

import useWordContext from 'hooks/useWordContext'

interface Props extends BoxProps {
children: React.ReactNode
}

export function MeaningNavigation({ ...props }: Props) {
const { wordDefinition = { data: [] } } = useWordContext()
const [word] = wordDefinition.data

return (
<Box {...props}>
{word.meanings.map(meaning => {
return meaning.partOfSpeech
})}
</Box>
)
}

export default MeaningNavigation
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { MeaningNavigation } from './MeaningNavigation'

export { MeaningNavigation }
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import React, { useState } from 'react'

import { Item } from 'features/wordslist/components/Item'
import { useWordContext } from 'hooks/useWordContext'
import { InfiniteScrollGrid } from 'components/InfiniteScrollGrid'
import { useWordContext } from 'hooks/useWordContext'

interface Props {}

export function FavoritesList({}: Props) {
export function FavoritesList() {
const { favoriteWord } = useWordContext()
const [favorites] = useState(favoriteWord.getAll())

Expand Down
12 changes: 6 additions & 6 deletions src/hooks/useQuery.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import {
QueryCache,
useInfiniteQuery,
useQuery,
UseQueryOptions,
} from '@tanstack/react-query'
import { AxiosResponse } from 'axios'

type QueryKeyT = string[] | String[]
import { IApiResponse } from 'lib/api'

type QueryKeyT = string[]

export const useFetch = <T>(
params: UseQueryOptions<AxiosResponse<T>, Error, AxiosResponse<T>, QueryKeyT>
params: UseQueryOptions<IApiResponse<T>, Error, IApiResponse<T>, QueryKeyT>
) => {
return useQuery<AxiosResponse<T>, Error, AxiosResponse<T>, QueryKeyT>({
return useQuery<IApiResponse<T>, Error, IApiResponse<T>, QueryKeyT>({
...params,
})
}

export const useLoadMore = <T>(params: object) => {
return useInfiniteQuery<AxiosResponse<T>, Error, AxiosResponse<T>>({
return useInfiniteQuery<IApiResponse<T>, Error, IApiResponse<T>>({
...params,
getNextPageParam: (page: any) => page.headers.link.next || false,
})
Expand Down
4 changes: 3 additions & 1 deletion src/lib/api.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import axios, { AxiosRequestConfig, AxiosResponse } from 'axios'

export interface IApiResponse<T = any, D = any> extends AxiosResponse<T, D> {}

export function api(axiosDefauls: AxiosRequestConfig) {
const axiosInstance = axios.create(axiosDefauls)

return {
get<TResponse>(
url: string,
config?: AxiosRequestConfig
): Promise<AxiosResponse<TResponse>> {
): Promise<IApiResponse<TResponse>> {
return axiosInstance.get<TResponse>(url, config)
},

Expand Down
2 changes: 1 addition & 1 deletion src/models/WordDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export interface Phonetic {

export interface Definition {
definition: string
example: string
example?: string
synonyms: string[]
antonyms: string[]
}
Expand Down
10 changes: 6 additions & 4 deletions src/services/Dictionary.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { AxiosResponse } from 'axios'
import { dictionaryAPI } from 'lib/dictionaryAPI'
import { IApiResponse } from 'lib/api'
import { IWord } from 'models/Word'

import { IWordDefinition } from 'models/WordDefinition'

import { dictionaryAPI } from 'lib/dictionaryAPI'

const serviceURL: string = '/entries/en'

export const Dictionary = {
findOne({ word = '' }: IWord): Promise<AxiosResponse<IWordDefinition[]>> {
findOne({
word = '',
}: IWord): Promise<IApiResponse<IWordDefinition[]>> {
return dictionaryAPI.get<IWordDefinition[]>(`${serviceURL}/${word}`)
},
}
Expand Down
8 changes: 4 additions & 4 deletions src/services/Words.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { AxiosResponse } from 'axios'
import { localAPI } from 'lib/localAPI'

import { IApiResponse } from 'lib/api'
import { IWord } from 'models/Word'

import { localAPI } from 'lib/localAPI'

const serviceURL: string = '/words'

export const Words = {
getAll({
params = { _page: 1, _limit: 15 },
}: {
params?: { _page: number; _limit?: number }
}): Promise<AxiosResponse<IWord[]>> {
}): Promise<IApiResponse<IWord[]>> {
return localAPI.get<IWord[]>(serviceURL, { params })
},
}
Expand Down

0 comments on commit eaa68cc

Please sign in to comment.