Skip to content

Commit

Permalink
Move types to dedicated file (#168)
Browse files Browse the repository at this point in the history
* Move types to dedicated file

* Add newline to the end of file

* Reorganize props and add comments to identify groups

* Re-added env import

---------

Co-authored-by: h1divp <[email protected]>
  • Loading branch information
aaditkamat and h1divp authored Mar 19, 2024
1 parent 6d46a9e commit 0c14ef7
Show file tree
Hide file tree
Showing 12 changed files with 115 additions and 79 deletions.
7 changes: 1 addition & 6 deletions client/src/components/Common/ChatMessage.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import React, { useContext } from "react";
import { View, StyleSheet, Text, Image, Dimensions } from "react-native";
import { useSettings } from "../../contexts/SettingsContext";

interface MessageProps {
messageContent: string;
author: string,
time: number // Unix timestamp; Date.now() returns a Number.
};
import { MessageProps } from "../../types/Props";

const Message: React.FC<MessageProps> = ({ messageContent, time, author }) => {
const settings = useSettings();
Expand Down
5 changes: 1 addition & 4 deletions client/src/components/Common/CustomButtons.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import React from 'react'
import { View, StyleSheet, Text, TouchableOpacity, Image, Dimensions } from 'react-native'

interface ChatSendButtonProps {
onPress?: () => void,
}
import { ChatSendButtonProps } from '../../types/Props';

export const ChatSendButton: React.FC<ChatSendButtonProps> = ({ onPress }) => {
return (
Expand Down
43 changes: 13 additions & 30 deletions client/src/components/Common/CustomInputs.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,19 @@
import React from "react";
import {
TextInput,
View,
StyleSheet,
Dimensions,
Platform,
} from "react-native";
import { useFonts } from "expo-font";
import { ChatSendButton } from "./CustomButtons";
import React from 'react'
import { TextInput, View, StyleSheet, Dimensions, Platform } from 'react-native'
import { ChatInputProps } from '../../types/Props';
import { ChatSendButton } from './CustomButtons'

interface ChatInputProps {
value?: string;
onChangeText?: (text: string) => void;
invalid?: boolean;
onSend?: () => void;
export const WelcomeEmailInput: React.FC<ChatInputProps> = ({ value, onChangeText }) => {
return (
<TextInput style={styles.welcomeEmailInput}
placeholder='Email'
multiline={false}
value={value}
onChangeText={onChangeText}
/>
)
}

export const WelcomeEmailInput: React.FC<ChatInputProps> = ({
value,
onChangeText,
}) => {
return (
<TextInput
style={styles.welcomeEmailInput}
placeholder="Email"
multiline={false}
value={value}
onChangeText={onChangeText}
/>
);
};

// Maybe will put LogInEmailInput & LogInPasswordInput two together into a single component

export const LogInEmailInput: React.FC<ChatInputProps> = ({
Expand Down
47 changes: 47 additions & 0 deletions client/src/components/Common/LogInButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { router } from "expo-router";
import React from "react";
import { useFonts } from "expo-font";
import { StyleSheet, Text, TouchableOpacity, Dimensions } from "react-native";
import { LogInButtonProps } from "../../types/Props";


const LogInButton: React.FC<LogInButtonProps> = ({ onPress }) => {

const [fontsLoaded, fontError] = useFonts({
'Gilroy-ExtraBold': require('../../../assets/fonts/Gilroy-ExtraBold.otf'),
'Gilroy-Light': require('../../../assets/fonts/Gilroy-Light.otf'),
});

if (!fontsLoaded && !fontError) {
return null;
}

return (
<TouchableOpacity style={styles.button} onPress={onPress}>
<Text style={styles.button_text}>Log In</Text>
</TouchableOpacity>
);
};

const styles = StyleSheet.create({


button: {
backgroundColor: "#5dbea3",
width: Dimensions.get("window").width * 0.5,
height: Dimensions.get("window").height * 0.05,
display: "flex",
justifyContent: "center",
alignItems: "center",
borderRadius: 10,
},

button_text: {
color: "white",
fontFamily: "Gilroy-ExtraBold",
fontSize: Dimensions.get("window").height * 0.03,

},
});

export default LogInButton;
9 changes: 3 additions & 6 deletions client/src/components/Common/MessageChannel.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import React from 'react'
import Message from './ChatMessage'
import { FlatList, StyleSheet, View } from 'react-native'
import { MessageType } from '../../types/Message'
import { MessageChannelProps } from '../../types/Props';

interface MessageChannelProps {
messages: MessageType[],
}

const MessageChannel: React.FC<MessageChannelProps> = ({ messages }) => {
const reverseMessages = [...messages].reverse()
Expand All @@ -16,11 +13,11 @@ const MessageChannel: React.FC<MessageChannelProps> = ({ messages }) => {
width: '100%',
}}
data={reverseMessages}
keyExtractor={(item) => item.msgId.toString()}
keyExtractor={(item) => item.msgId}
renderItem={({ item }) => (
<Message
messageContent={item.msgContent}
author={item.author.uid}
author={item.author.uid} // TODO: call server to get author name from UID. Or should this stored with MessageType?
time={item.timeSent}
/>
)}
Expand Down
5 changes: 1 addition & 4 deletions client/src/components/Common/NearbyCount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import {
Text,
Dimensions
} from 'react-native';

interface CounterProps {
count: number;
}
import { CounterProps } from '../../types/Props';

const NearbyCount: React.FC<CounterProps> = ({count}) => {
return (
Expand Down
9 changes: 3 additions & 6 deletions client/src/components/Common/NearbyHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { View, Text, StyleSheet, Dimensions } from "react-native";
import React from "react";
import NearbyCount from "./NearbyCount";

interface CounterProps {
count: number;
}
import { View, Text, StyleSheet, Dimensions, Image } from 'react-native'
import React from 'react'
import { CounterProps } from '../../utils/types'

export const NearbyHeader: React.FC<CounterProps> = ({ count }) => {
return (
Expand Down
5 changes: 1 addition & 4 deletions client/src/components/Common/SafeAreaWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import React from "react";
import { useSettings } from "../../contexts/SettingsContext";
import { SafeAreaView, Platform, StyleSheet, StatusBar } from "react-native";

interface SafeAreaWrapperProps {
children: React.ReactNode;
}
import { SafeAreaWrapperProps } from "../../utils/types";

const SafeAreaWrapper: React.FC<SafeAreaWrapperProps> = ({ children }) => {
const settings = useSettings();
Expand Down
8 changes: 1 addition & 7 deletions client/src/components/Common/SignUpButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ import { router } from "expo-router";
import React from "react";
import { useFonts } from "expo-font";
import { StyleSheet, Text, TouchableOpacity, Dimensions } from "react-native";

// Interface for props function onPress
interface SignUpButtonProps {
onPress?: () => void;
}
import { SignUpButtonProps } from "../../utils/types";

const SignUpButton: React.FC<SignUpButtonProps> = ({ onPress }) => {

Expand All @@ -27,8 +23,6 @@ const SignUpButton: React.FC<SignUpButtonProps> = ({ onPress }) => {
};

const styles = StyleSheet.create({


button: {
backgroundColor: "#5dbea3",
width: Dimensions.get("window").width * 0.5,
Expand Down
2 changes: 1 addition & 1 deletion client/src/configs/firebaseConfig.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { initializeApp, getApp, getApps } from "firebase/app";
import { initializeAuth, getReactNativePersistence, getAuth, Auth } from "firebase/auth";
import AsyncStorage from "@react-native-async-storage/async-storage";
import {API_KEY, AUTH_DOMAIN, PROJECT_ID, STORAGE_BUCKET, MESSAGING_SENDER_ID, APP_ID} from "@env"; // Don't worry about this env error!
import {API_KEY, AUTH_DOMAIN} from "@env"; // Don't worry about this env error!

const firebaseConfig = {
apiKey: API_KEY || "Mock-Key",
Expand Down
43 changes: 43 additions & 0 deletions client/src/types/Props.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import React from "react";
import { MessageType } from "./Message";

/* button props */
export type LogInButtonProps = {
onPress?: () => void;
}

export type SignUpButtonProps = {
onPress?: () => void;
}

export type ChatSendButtonProps = {
onPress?: () => void,
}

/* input props */
export type ChatInputProps = {
value?: string,
onChangeText?: (text: string) => void
}

/* message related props */
export type MessageProps = {
messageContent: string;
time: number;
author: string;
}

export type MessageChannelProps = {
messages: MessageType[],
}

/* misc props*/
export type CounterProps = {
count: number;
}

export type SafeAreaWrapperProps = {
children: React.ReactNode;
}


11 changes: 0 additions & 11 deletions client/src/utils/types.ts

This file was deleted.

0 comments on commit 0c14ef7

Please sign in to comment.