Skip to content

Commit

Permalink
Add username field to Post interface and update related components; i…
Browse files Browse the repository at this point in the history
…mplement language selection with AsyncStorage support
  • Loading branch information
NateIsern committed Dec 13, 2024
1 parent 4e76658 commit 51ca704
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 51 deletions.
21 changes: 4 additions & 17 deletions app/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export default function HomeScreen() {
author: {
name: string;
image: string;
username: string;
};
};

Expand All @@ -45,6 +46,7 @@ export default function HomeScreen() {
user: {
name: post.author?.name || "Unknown",
avatar: post.author?.image || "https://via.placeholder.com/50",
username: post.author?.username || "unknown",
},
content: decodeURIComponent(post.text),
timestamp: new Date(post.created_at).toLocaleTimeString(),
Expand Down Expand Up @@ -109,23 +111,8 @@ export default function HomeScreen() {

const styles = StyleSheet.create({
container: {
},
header: {
flexDirection: "row",
justifyContent: "space-between",
alignItems: "center",
padding: 16,
borderBottomWidth: 1,
borderBottomColor: "#e1e8ed",
},
headerTitle: {
fontSize: 24,
fontWeight: "bold",
},
composeButton: {
backgroundColor: "#1DA1F2",
padding: 8,
borderRadius: 9999,
flex: 1,
backgroundColor: "#fff",
},
fab: {
position: "fixed",
Expand Down
52 changes: 48 additions & 4 deletions app/post/[id].tsx
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",
},
});
40 changes: 36 additions & 4 deletions app/settings/languages.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
import React from "react";
import { View, Text, StyleSheet, SafeAreaView } from "react-native";
import React, { useState } from "react";
import { View, Text, StyleSheet, SafeAreaView, Button } from "react-native";
import { Picker } from "@react-native-picker/picker";
import { useTranslation } from "react-i18next";
import AsyncStorage from '@react-native-async-storage/async-storage';

export default function LanguageSettings() {
const { t } = useTranslation();
const { t, i18n } = useTranslation();
const [selectedLanguage, setSelectedLanguage] = useState(i18n.language);

const changeLanguage = async (language: string) => {
await i18n.changeLanguage(language);
setSelectedLanguage(language);
await AsyncStorage.setItem('selectedLanguage', language);
};

return (
<SafeAreaView style={styles.container}>
<Text style={styles.title}>{t("Language Settings")}</Text>
{/* Add language settings components here */}
<View style={styles.pickerContainer}>
<Text style={styles.label}>{t("Select Language")}</Text>
<Picker
selectedValue={selectedLanguage}
style={styles.picker}
onValueChange={(itemValue: string) => changeLanguage(itemValue)}
>
<Picker.Item label="English" value="en" />
<Picker.Item label="Spanish" value="es" />
{/* Add more languages here */}
</Picker>
</View>
<Button title={t("Save")} onPress={() => {/* Save language settings */ }} />
</SafeAreaView>
);
}
Expand All @@ -24,4 +45,15 @@ const styles = StyleSheet.create({
fontWeight: 'bold',
marginBottom: 16,
},
pickerContainer: {
marginBottom: 16,
},
label: {
fontSize: 18,
marginBottom: 8,
},
picker: {
height: 50,
width: '100%',
},
});
2 changes: 2 additions & 0 deletions hooks/useFetchPosts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface PostAPIResponse {
author: {
name: string;
image: string;
username: string;
};
}

Expand All @@ -24,6 +25,7 @@ export const useFetchPosts = () => {
user: {
name: post.author?.name || "Unknown",
avatar: post.author?.image || "https://via.placeholder.com/50",
username: post.author?.username || "unknown",
},
content: decodeURIComponent(post.text),
timestamp: new Date(post.created_at).toLocaleTimeString(),
Expand Down
7 changes: 5 additions & 2 deletions interfaces/Post.ts
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;
}
47 changes: 24 additions & 23 deletions locales/en.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
{
"Home": "Inicio",
"Search": "Buscar",
"Notifications": "Notificaciones",
"Messages": "Mensajes",
"New Post": "Nueva Publicación",
"What's happening?": "¿Qué está pasando?",
"Post": "Publicar",
"Settings": "Configuraciones",
"Language": "Idioma",
"Primary Color": "Color Primario",
"Apply Settings": "Aplicar Configuraciones",
"Welcome to Mention! 👋": "¡Bienvenido a Mention! 👋",
"Thanks for trying out our app. Start exploring now!": "Gracias por probar nuestra aplicación. ¡Empieza a explorar ahora!",
"This screen doesn't exist.": "Esta pantalla no existe.",
"Go to home screen!": "¡Ir a la pantalla de inicio!",
"Hey, how are you?": "Hola, ¿cómo estás?",
"Let's catch up soon!": "¡Pongámonos al día pronto!",
"liked your Post": "le gustó tu Post",
"reposted your Post": "retuiteó tu Post",
"This is a sample post": "Este es un post de muestra",
"Another example post": "Otro post de ejemplo",
"Customize your view": "Personaliza tu vista",
"These settings affect all the Mention accounts on this device.": "Estas configuraciones afectan todas las cuentas de Mention en este dispositivo.",
"Home": "Home",
"Search": "Search",
"Notifications": "Notifications",
"Messages": "Messages",
"New Post": "New Post",
"What's happening?": "What's happening?",
"Post": "Post",
"Save": "Save",
"Settings": "Settings",
"Language": "Language",
"Primary Color": "Primary Color",
"Apply Settings": "Apply Settings",
"Welcome to Mention! 👋": "Welcome to Mention! 👋",
"Thanks for trying out our app. Start exploring now!": "Thanks for trying out our app. Start exploring now!",
"This screen doesn't exist.": "This screen doesn't exist.",
"Go to home screen!": "Go to home screen!",
"Hey, how are you?": "Hey, how are you?",
"Let's catch up soon!": "Let's catch up soon!",
"liked your Post": "liked your Post",
"reposted your Post": "reposted your Post",
"This is a sample post": "This is a sample post",
"Another example post": "Another example post",
"Customize your view": "Customize your view",
"These settings affect all the Mention accounts on this device.": "These settings affect all the Mention accounts on this device.",
"Account": "Account",
"Manage your account settings": "Manage your account settings",
"Notification preferences": "Notification preferences",
Expand Down
8 changes: 7 additions & 1 deletion locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"New Post": "Nueva Publicación",
"What's happening?": "¿Qué está pasando?",
"Post": "Publicar",
"Save": "Guardar",
"Settings": "Configuraciones",
"Language": "Idioma",
"Primary Color": "Color Primario",
Expand Down Expand Up @@ -33,5 +34,10 @@
"About": "Acerca de",
"About this app": "Acerca de esta aplicación",
"Battery": "Batería",
"Loading...": "Cargando..."
"Loading...": "Cargando...",
"Customize the look and feel of the app": "Personaliza el aspecto y la sensación de la aplicación",
"Light": "Claro",
"Dark": "Oscuro",
"Accent Color": "Color de Acento",
"Display Settings": "Configuración de Pantalla"
}
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@expo/vector-icons": "^14.0.2",
"@oxyhq/services": "^0.0.85",
"@react-native-async-storage/async-storage": "^2.1.0",
"@react-native-picker/picker": "^2.10.2",
"@react-navigation/bottom-tabs": "^7.0.0",
"@react-navigation/native": "^7.0.0",
"emoji-picker-react": "^4.12.0",
Expand Down

0 comments on commit 51ca704

Please sign in to comment.