Skip to content

Preparando revisão do código#1

Open
ElderGr wants to merge 1 commit intoNotye1K:mainfrom
ElderGr:main
Open

Preparando revisão do código#1
ElderGr wants to merge 1 commit intoNotye1K:mainfrom
ElderGr:main

Conversation

@ElderGr
Copy link
Copy Markdown

@ElderGr ElderGr commented Jan 13, 2022

No description provided.

Copy link
Copy Markdown
Author

@ElderGr ElderGr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fala Kleyton, tudo bem? Bora pra mais um code review!

Numa visão geral o projeto ficou com uma boa concisão, semântica e arquitetura geral do projeto. Tiveram alguns pontos que de melhoria que comentei e que caso tenha alguma dúvida fico a disposição para falar sobre 😀.

Comment thread src/App.js
const [counter, setCounter] = useState(0)

useEffect(() => {
let c = 0
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

É legal deixar nomes de variaveis e parâmetros o mais descritivas possível, de forma que ao ler seja possível identificar oque a variável/parâmetro faz.

Esse comentário se aplica a outras situações.

Comment on lines -104 to -115
function formatDate(date) {
let string = ''
if (date.getDate().toString().length === 1) string += '0'
string += date.getDate().toString()
string += '/'
let month = date.getMonth() + 1
if (month.toString().length === 1) string += '0'
string += month.toString()
string += '/'
string += date.getFullYear().toString()
return string
} No newline at end of file
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Achei maneiro separar a formatação da data numa função dedicada a isso. Dessa forma conseguimos reaproveitar em outras partes do código e se necessário, mudar sem muita dor de cabeça.

Comment on lines -33 to -42
promise.then(response => {
setLoading(0)
setApi(response.data)
localStorage.setItem('user', JSON.stringify(response.data))
navigate('/hoje')
})
promise.catch(erro => {
setLoading(0)
alert(erro.response.data.details)
})
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Para evitar repetir o setLoading(0) tanto no .then quanto no .catch, podemos usar o .finally

promise.finally(() => setLoading(0))

O que estiver dentro do .finally é executado no final do then ou do catch (depende de qual for disparado).

Comment on lines -3 to -10
export default function getHabits(setHabitsToday, api){
const promise = axios.get('https://mock-api.bootcamp.respondeai.com.br/api/v2/trackit/habits/today',
{ headers: { Authorization: `Bearer ${api.token}` } })
promise.then(response => {
setHabitsToday(response.data)
})
promise.catch(erro => alert(erro.response.data.details))
} No newline at end of file
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Achei bem maneiro você separar a chamada da API numa função separada num único arquivo. Mais pra frente, vocês vão ver técnicas de arquitetura e reaproveitamento de código em que esse conceito de deixar a função fazendo uma única ação torna-se muito vantajoso, quando pensamos em manutenção de código.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant