diff options
-rw-r--r-- | src/components/moments/MomentPost.tsx | 22 | ||||
-rw-r--r-- | src/screens/profile/IndividualMoment.tsx | 6 | ||||
-rw-r--r-- | src/services/MomentService.ts | 21 | ||||
-rw-r--r-- | src/store/initialStates.ts | 11 | ||||
-rw-r--r-- | src/types/types.ts | 10 |
5 files changed, 38 insertions, 32 deletions
diff --git a/src/components/moments/MomentPost.tsx b/src/components/moments/MomentPost.tsx index 1f363052..4f8bb63f 100644 --- a/src/components/moments/MomentPost.tsx +++ b/src/components/moments/MomentPost.tsx @@ -4,16 +4,20 @@ import {useSelector} from 'react-redux'; import {MomentPostContent, MomentPostHeader} from '.'; import {deleteMomentTag, loadMomentTags} from '../../services'; import {RootState} from '../../store/rootReducer'; -import {MomentTagType, MomentType, ScreenType} from '../../types'; +import {MomentPostType, MomentTagType, ScreenType} from '../../types'; import {SCREEN_HEIGHT} from '../../utils'; interface MomentPostProps { - item: MomentType; + moment: MomentPostType; userXId: string | undefined; screenType: ScreenType; } -const MomentPost: React.FC<MomentPostProps> = ({item, userXId, screenType}) => { +const MomentPost: React.FC<MomentPostProps> = ({ + moment, + userXId, + screenType, +}) => { const {userId: loggedInUserId, username: loggedInUsername} = useSelector( (state: RootState) => state.user.user, ); @@ -29,7 +33,7 @@ const MomentPost: React.FC<MomentPostProps> = ({item, userXId, screenType}) => { const isOwnProfile = username === loggedInUsername; const loadTags = async () => { - const response = await loadMomentTags(item.moment_id); + const response = await loadMomentTags(moment.moment_id); setTags(response ? response : []); }; @@ -74,17 +78,17 @@ const MomentPost: React.FC<MomentPostProps> = ({item, userXId, screenType}) => { userXId={userXId} screenType={screenType} username={isOwnProfile ? loggedInUsername : username} - momentId={item.moment_id} + momentId={moment.moment_id} style={styles.postHeader} momentTagId={momentTagId} removeTag={removeTag} /> <MomentPostContent style={styles.postContent} - momentId={item.moment_id} - caption={item.caption} - pathHash={item.moment_url} - dateTime={item.date_created} + momentId={moment.moment_id} + caption={moment.caption} + pathHash={moment.moment_url} + dateTime={moment.date_created} screenType={screenType} momentTags={tags} /> diff --git a/src/screens/profile/IndividualMoment.tsx b/src/screens/profile/IndividualMoment.tsx index 95428c39..ba6a731c 100644 --- a/src/screens/profile/IndividualMoment.tsx +++ b/src/screens/profile/IndividualMoment.tsx @@ -7,7 +7,7 @@ import {useSelector} from 'react-redux'; import {IndividualMomentTitleBar, MomentPost} from '../../components'; import {MainStackParams} from '../../routes'; import {RootState} from '../../store/rootreducer'; -import {MomentType} from '../../types'; +import {MomentPostType, MomentType} from '../../types'; import {normalize, StatusBarHeight} from '../../utils'; /** @@ -52,8 +52,8 @@ const IndividualMoment: React.FC<IndividualMomentProps> = ({ /> <FlatList data={momentData} - renderItem={({item}: {item: MomentType}) => ( - <MomentPost userXId={userXId} screenType={screenType} item={item} /> + renderItem={({item}: {item: MomentPostType}) => ( + <MomentPost moment={item} userXId={userXId} screenType={screenType} /> )} keyExtractor={(_, index) => index.toString()} showsVerticalScrollIndicator={false} 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) => { diff --git a/src/store/initialStates.ts b/src/store/initialStates.ts index e2902a2d..92a1e456 100644 --- a/src/store/initialStates.ts +++ b/src/store/initialStates.ts @@ -1,14 +1,17 @@ -import {CommentThreadType, UniversityType} from './../types/types'; import { - MomentType, NotificationType, - ProfilePreviewType, ProfileInfoType, + ProfilePreviewType, ScreenType, SocialAccountType, UserType, UserXType, } from '../types'; +import { + CommentThreadType, + MomentPostType, + UniversityType, +} from './../types/types'; export const NO_PROFILE: ProfileInfoType = { biography: '', @@ -29,7 +32,7 @@ export const NO_PROFILE: ProfileInfoType = { is_private: true, }; -export const EMPTY_MOMENTS_LIST = <MomentType[]>[]; +export const EMPTY_MOMENTS_LIST = <MomentPostType[]>[]; export const EMPTY_NOTIFICATIONS_LIST = <NotificationType[]>[]; diff --git a/src/types/types.ts b/src/types/types.ts index e54c2201..1e50eba8 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -119,6 +119,14 @@ export interface MomentType { thumbnail_url: string; } +export interface MomentPostType extends MomentType { + comments_count: number; + comment_preview: { + user: ProfilePreviewType; + comment: string; + }; +} + export interface MomentTagType { id: string; user: ProfilePreviewType; @@ -172,7 +180,7 @@ export enum ScreenType { */ export interface UserXType { friends: ProfilePreviewType[]; - moments: MomentType[]; + moments: MomentPostType[]; socialAccounts: Record<string, SocialAccountType>; momentCategories: string[]; user: UserType; |