diff options
| author | Ivan Chen <ivan@tagg.id> | 2021-06-08 14:20:57 -0400 |
|---|---|---|
| committer | Ivan Chen <ivan@tagg.id> | 2021-06-08 16:18:34 -0400 |
| commit | f8dd6b8ef033039278e2931876488c307f5d5adc (patch) | |
| tree | 3303e77f4a8991b8ff9c95b638849efa23b32b7b /src/services | |
| parent | 96a80c53fcc0b5815b56f0ed0b48d152a6c6e2a4 (diff) | |
Create MomentPostType
Diffstat (limited to 'src/services')
| -rw-r--r-- | src/services/MomentService.ts | 21 |
1 files changed, 6 insertions, 15 deletions
diff --git a/src/services/MomentService.ts b/src/services/MomentService.ts index af602dc7..e227bc9e 100644 --- a/src/services/MomentService.ts +++ b/src/services/MomentService.ts @@ -6,7 +6,7 @@ import { MOMENT_TAGS_ENDPOINT, MOMENT_THUMBNAIL_ENDPOINT, } from '../constants'; -import {MomentTagType, MomentType} from '../types'; +import {MomentPostType, MomentTagType, MomentType} from '../types'; import {checkImageUploadStatus} from '../utils'; export const postMoment = async ( @@ -54,11 +54,7 @@ export const postMoment = async ( return undefined; }; -export const loadMoments: ( - userId: string, - token: string, -) => Promise<MomentType[]> = async (userId, token) => { - let moments: MomentType[] = []; +export const loadMoments = async (userId: string, token: string) => { try { const response = await fetch(MOMENTS_ENDPOINT + '?user_id=' + userId, { method: 'GET', @@ -66,19 +62,14 @@ export const loadMoments: ( Authorization: 'Token ' + token, }, }); - const status = response.status; - if (status === 200) { - const data = await response.json(); - moments = data; - } else { - console.log('Could not load moments!'); - return []; + if (response.status === 200) { + const typedData: MomentPostType[] = await response.json(); + return typedData; } } catch (err) { console.log(err); - return []; } - return moments; + return []; }; export const deleteMoment = async (momentId: string) => { |
