forked from polka_billy/porridger
Code styling
Added brackets for const lambdas Converted const lambdas with multiple instructions to functions
This commit is contained in:
@ -7,7 +7,9 @@ import { handleHTTPErrors } from '../../utils'
|
||||
const addErrors = ['Не удалось опубликовать объявление', 'Неверный ответ от сервера', 'Неизвестная ошибка'] as const
|
||||
type AddError = typeof addErrors[number]
|
||||
|
||||
const isAddError = (obj: unknown): obj is AddError => isLiteralUnion(obj, addErrors)
|
||||
const isAddError = (obj: unknown): obj is AddError => (
|
||||
isLiteralUnion(obj, addErrors)
|
||||
)
|
||||
|
||||
const buttonStates = ['Опубликовать', 'Загрузка...', 'Опубликовано', 'Отменено'] as const
|
||||
type ButtonState = typeof buttonStates[number] | AddError
|
||||
@ -16,9 +18,9 @@ type AddResponse = {
|
||||
Answer: boolean
|
||||
}
|
||||
|
||||
const isAddResponse = (obj: unknown): obj is AddResponse =>
|
||||
const isAddResponse = (obj: unknown): obj is AddResponse => (
|
||||
typeof obj === 'object' && obj !== null && typeof Reflect.get(obj, 'Answer') === 'boolean'
|
||||
|
||||
)
|
||||
|
||||
const useAddAnnouncement = () => {
|
||||
const [status, setStatus] = useState<ButtonState>('Опубликовать')
|
||||
|
@ -4,7 +4,7 @@ import { composeAnnouncementsURL, initialAnnouncements, processAnnouncements } f
|
||||
|
||||
import { isAnnouncementsResponse } from '../../api/announcements/types'
|
||||
|
||||
const useAnnouncements = (filters: FiltersType) =>
|
||||
const useAnnouncements = (filters: FiltersType) => (
|
||||
useFetch(
|
||||
composeAnnouncementsURL(filters),
|
||||
'GET',
|
||||
@ -13,6 +13,6 @@ const useAnnouncements = (filters: FiltersType) =>
|
||||
processAnnouncements,
|
||||
initialAnnouncements
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
export default useAnnouncements
|
||||
|
@ -38,16 +38,18 @@ interface LogInResponse {
|
||||
token_type: 'bearer'
|
||||
}
|
||||
|
||||
const isLogInResponse = (obj: unknown): obj is LogInResponse => isObject(obj, {
|
||||
'access_token': 'string',
|
||||
'token_type': isConst('bearer')
|
||||
})
|
||||
const isLogInResponse = (obj: unknown): obj is LogInResponse => (
|
||||
isObject(obj, {
|
||||
'access_token': 'string',
|
||||
'token_type': isConst('bearer')
|
||||
})
|
||||
)
|
||||
|
||||
function useAuth() {
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [error, setError] = useState('')
|
||||
|
||||
const doAuth = async (data: AuthData, newAccount: boolean) => {
|
||||
async function doAuth(data: AuthData, newAccount: boolean) {
|
||||
setLoading(true)
|
||||
|
||||
if (newAccount) {
|
||||
|
@ -10,9 +10,11 @@ type BookResponse = {
|
||||
Success: boolean
|
||||
}
|
||||
|
||||
const isBookResponse = (obj: unknown): obj is BookResponse => isObject(obj, {
|
||||
'Success': 'boolean'
|
||||
})
|
||||
const isBookResponse = (obj: unknown): obj is BookResponse => (
|
||||
isObject(obj, {
|
||||
'Success': 'boolean'
|
||||
})
|
||||
)
|
||||
|
||||
type BookStatus = '' | 'Загрузка...' | 'Забронировано' | 'Ошибка бронирования'
|
||||
|
||||
|
@ -20,11 +20,13 @@ type UseFetchErrored = {
|
||||
data: undefined
|
||||
} & UseFetchShared
|
||||
|
||||
const gotError = <T>(res: UseFetchErrored | UseFetchSucced<T>): res is UseFetchErrored =>
|
||||
const gotError = <T>(res: UseFetchErrored | UseFetchSucced<T>): res is UseFetchErrored => (
|
||||
typeof res.error === 'string'
|
||||
)
|
||||
|
||||
const fallbackError = <T>(res: UseFetchSucced<T> | UseFetchErrored) =>
|
||||
const fallbackError = <T>(res: UseFetchSucced<T> | UseFetchErrored) => (
|
||||
gotError(res) ? res.error : res.data
|
||||
)
|
||||
|
||||
type UseFetchReturn<T> = ({
|
||||
error: null,
|
||||
|
@ -4,7 +4,7 @@ import useFetch from './useFetch'
|
||||
import { composeOsmAddressURL, processOsmAddress } from '../../api/osmAddress'
|
||||
import { isOsmAddressResponse } from '../../api/osmAddress/types'
|
||||
|
||||
const useOsmAddresses = (addressPosition: LatLng) =>
|
||||
const useOsmAddresses = (addressPosition: LatLng) => (
|
||||
useFetch(
|
||||
composeOsmAddressURL(addressPosition),
|
||||
'GET',
|
||||
@ -13,5 +13,6 @@ const useOsmAddresses = (addressPosition: LatLng) =>
|
||||
processOsmAddress,
|
||||
''
|
||||
)
|
||||
)
|
||||
|
||||
export default useOsmAddresses
|
||||
|
@ -4,7 +4,7 @@ import useFetch from './useFetch'
|
||||
import { composeTrashboxURL } from '../../api/trashbox'
|
||||
import { isTrashboxResponse } from '../../api/trashbox/types'
|
||||
|
||||
const useTrashboxes = (position: LatLng) =>
|
||||
const useTrashboxes = (position: LatLng) => (
|
||||
useFetch(
|
||||
composeTrashboxURL(position),
|
||||
'GET',
|
||||
@ -13,6 +13,6 @@ const useTrashboxes = (position: LatLng) =>
|
||||
(data) => data,
|
||||
[]
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
export default useTrashboxes
|
||||
|
Reference in New Issue
Block a user