-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add username field to Post interface and update related components; i…
…mplement language selection with AsyncStorage support
- Loading branch information
Showing
9 changed files
with
137 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,69 @@ | ||
import { Stack, useLocalSearchParams } from "expo-router"; | ||
import React from "react"; | ||
import React, { useState, useEffect } from "react"; | ||
import { View, StyleSheet } from "react-native"; | ||
import Post from "@/components/Post"; | ||
import { ThemedView } from "@/components/ThemedView"; | ||
import { samplePosts } from "@/constants/sampleData"; | ||
import { fetchData } from "@/utils/api"; | ||
import { Post as PostType } from "@/interfaces/Post"; | ||
|
||
export default function PostDetailScreen() { | ||
const { id } = useLocalSearchParams<{ id: string }>(); | ||
const post = samplePosts.find((t) => t.id === id); | ||
const [post, setPost] = useState<PostType | null>(null); | ||
|
||
useEffect(() => { | ||
const fetchPost = async () => { | ||
try { | ||
const response = await fetchData(`posts/${id}`); | ||
const post = { | ||
id: response.id, | ||
user: { | ||
name: response.author?.name || "Unknown", | ||
avatar: response.author?.image || "https://via.placeholder.com/50", | ||
username: response.author?.username || "unknown", | ||
}, | ||
content: decodeURIComponent(response.text), | ||
timestamp: new Date(response.created_at).toLocaleTimeString(), | ||
likes: 0, // Assuming default value | ||
reposts: 0, // Assuming default value | ||
replies: 0, // Assuming default value | ||
}; | ||
setPost(post); | ||
} catch (error) { | ||
console.error("Error fetching post:", error); | ||
} | ||
}; | ||
|
||
if (id) { | ||
fetchPost(); | ||
} | ||
}, [id]); | ||
|
||
return ( | ||
<> | ||
<Stack.Screen options={{ title: "Post" }} /> | ||
<ThemedView style={styles.container}> | ||
{post && <Post {...post} showActions={false} />} | ||
{post && ( | ||
<Post | ||
id={post.id} | ||
avatar={post.user.avatar} | ||
name={post.user.name} | ||
username={post.user.username} | ||
content={post.content} | ||
time={post.timestamp} | ||
likes={post.likes} | ||
reposts={post.reposts} | ||
replies={post.replies} | ||
showActions={false} | ||
/> | ||
)} | ||
</ThemedView> | ||
</> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
backgroundColor: "#fff", | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
|
||
export interface Post { | ||
id: string; | ||
user: { | ||
name: string; | ||
avatar: string; | ||
username: string; | ||
}; | ||
content: string; | ||
timestamp: string; | ||
} | ||
likes: number; | ||
reposts: number; | ||
replies: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters