frontend: Format and lint

This commit is contained in:
Paul Bienkowski 2021-02-26 20:09:52 +01:00
parent 6a1b193e06
commit eef5deca70
3 changed files with 37 additions and 27 deletions

View file

@ -60,6 +60,7 @@ export function Layer({layerClass, getDefaultOptions, children, ...props}) {
...(getDefaultOptions ? getDefaultOptions() : {}), ...(getDefaultOptions ? getDefaultOptions() : {}),
...props, ...props,
}), }),
// eslint-disable-next-line react-hooks/exhaustive-deps
[] []
) )
@ -111,6 +112,7 @@ function View({...options}) {
new OlView({ new OlView({
...options, ...options,
}), }),
// eslint-disable-next-line react-hooks/exhaustive-deps
[] []
) )

View file

@ -18,7 +18,7 @@ import TrackMap from './TrackMap'
function useTriggerSubject() { function useTriggerSubject() {
const subject$ = React.useMemo(() => new Subject(), []) const subject$ = React.useMemo(() => new Subject(), [])
const trigger = React.useCallback(() => subject$.next(null), []) const trigger = React.useCallback(() => subject$.next(null), [subject$])
return [trigger, subject$] return [trigger, subject$]
} }
@ -68,12 +68,12 @@ const TrackPage = connect((state) => ({login: state.login}))(function TrackPage(
body: {comment: {body}}, body: {comment: {body}},
}) })
reloadComments() reloadComments()
}, []) }, [slug, reloadComments])
const onDeleteComment = React.useCallback(async (id) => { const onDeleteComment = React.useCallback(async (id) => {
await api.delete(`/tracks/${slug}/comments/${id}`) await api.delete(`/tracks/${slug}/comments/${id}`)
reloadComments() reloadComments()
}, []) }, [slug, reloadComments])
const isAuthor = login?.username === data?.track?.author?.username const isAuthor = login?.username === data?.track?.author?.username

View file

@ -51,33 +51,37 @@ function FileUploadStatus({
}) { }) {
const [progress, setProgress] = React.useState(0) const [progress, setProgress] = React.useState(0)
React.useEffect(() => { React.useEffect(
const formData = new FormData() () => {
formData.append('body', file) const formData = new FormData()
formData.append('body', file)
const xhr = new XMLHttpRequest() const xhr = new XMLHttpRequest()
const onProgress = (e) => { const onProgress = (e) => {
const progress = (e.loaded || 0) / (e.total || 1) const progress = (e.loaded || 0) / (e.total || 1)
setProgress(progress) setProgress(progress)
} }
const onLoad = (e) => { const onLoad = (e) => {
onComplete(id, xhr.response) onComplete(id, xhr.response)
} }
xhr.responseType = 'json' xhr.responseType = 'json'
xhr.onload = onLoad xhr.onload = onLoad
xhr.upload.onprogress = onProgress xhr.upload.onprogress = onProgress
xhr.open('POST', '/api/tracks') xhr.open('POST', '/api/tracks')
api.getValidAccessToken().then((accessToken) => { api.getValidAccessToken().then((accessToken) => {
xhr.setRequestHeader('Authorization', accessToken) xhr.setRequestHeader('Authorization', accessToken)
xhr.send(formData) xhr.send(formData)
}) })
return () => xhr.abort() return () => xhr.abort()
}, [file]) },
// eslint-disable-next-line react-hooks/exhaustive-deps
[file]
)
return ( return (
<span> <span>
@ -107,9 +111,13 @@ export default function UploadPage() {
[setFiles] [setFiles]
) )
React.useLayoutEffect(() => { React.useLayoutEffect(
setLabelRefState(labelRef.current) () => {
}, [labelRef.current]) setLabelRefState(labelRef.current)
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[labelRef.current]
)
function onSelectFiles(fileList) { function onSelectFiles(fileList) {
const newFiles = Array.from(fileList).map((file) => ({ const newFiles = Array.from(fileList).map((file) => ({