Merge pull request 'asynchronous-porridger' (#49) from asynchronous-porridger into main

Reviewed-on: dm1sh/porridger#49
This commit is contained in:
2023-09-13 22:46:16 +03:00
29 changed files with 344 additions and 2938 deletions

View File

@ -6,7 +6,7 @@ const composePutAnnouncementURL = () => (
)
const processPutAnnouncement = (data: PutAnnouncementResponse): PutAnnouncement => {
return data.Answer
return data.Success
}
export { composePutAnnouncementURL, processPutAnnouncement }

View File

@ -1,12 +1,12 @@
import { isObject } from '../../utils/types'
type PutAnnouncementResponse = {
Answer: boolean,
Success: boolean,
}
const isPutAnnouncementResponse = (obj: unknown): obj is PutAnnouncementResponse => (
isObject(obj, {
'Answer': 'boolean',
'Success': 'boolean',
})
)

View File

@ -6,11 +6,11 @@ const composeRemoveAnnouncementURL = () => (
)
function processRemoveAnnouncement(data: RemoveAnnouncementResponse): RemoveAnnouncement {
if (!data.Answer) {
if (!data.Success) {
throw new Error('Не удалось закрыть объявление')
}
return data.Answer
return data.Success
}
export { composeRemoveAnnouncementURL, processRemoveAnnouncement }

View File

@ -1,12 +1,12 @@
import { isObject } from '../../utils/types'
type RemoveAnnouncementResponse = {
Answer: boolean,
Success: boolean,
}
const isRemoveAnnouncementResponse = (obj: unknown): obj is RemoveAnnouncementResponse => (
isObject(obj, {
'Answer': 'boolean',
'Success': 'boolean',
})
)

View File

@ -14,8 +14,8 @@ function useAddAnnouncement() {
processPutAnnouncement
)
function handleAdd(formData: FormData) {
void doSend({}, {
async function handleAdd(formData: FormData) {
await doSend({}, {
body: formData,
})
}

View File

@ -15,8 +15,8 @@ function useBook() {
processBook,
)
const handleBook = useCallback((id: number) => {
void doSend({}, {
const handleBook = useCallback(async (id: number) => {
await doSend({}, {
body: JSON.stringify({
id,
}),

View File

@ -12,7 +12,7 @@ function useSendButtonCaption(
const [title, setTitle] = useState(initial)
const update = useCallback(<T extends NonNullable<unknown>>(data: T | null | undefined) => {
if (data !== undefined) { // not loading
if (data !== undefined && data !== null) { // not loading or error
setCaption(result)
setTitle('Отправить ещё раз')