Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript Migration - Front End #15

Open
wants to merge 37 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
e597bda
Created a sample EventCard component
marked01one Nov 14, 2022
1f686aa
Implemented a sample profile picture stack
marked01one Nov 21, 2022
a0e0d64
Implemented overlapped profile pic icons for the component
marked01one Nov 28, 2022
ef7eb40
Refactor and clean up the EventCard
marked01one Jan 7, 2023
a0fbd9c
Added a functional 'Going' button. Currently returns an alert.
marked01one Jan 7, 2023
9b5e872
Changed the naming for the EventCard sub-components
marked01one Jan 10, 2023
522df3f
Changed properties based to reviews
marked01one Jan 12, 2023
fff48a9
Updated constants.js to eliminate merge conflict
marked01one Jan 13, 2023
adff80d
Removed react-native-elements from project & refactored code accordingly
marked01one Jan 18, 2023
d000fe3
Merging main into typescript_migration_frontend
marked01one Feb 14, 2023
892bfd2
Initialized project with tsconfig.json
marked01one Feb 14, 2023
ff5ad43
Completed translation to TypeScript for EventCard
marked01one Feb 14, 2023
1adf9af
Migrated explore folder and additional files
GuyWhoCode Feb 15, 2023
dd83a8f
Added absolute pathing compiler option
GuyWhoCode Feb 22, 2023
10d245d
TypeScript Migration March 3rd 2023
marked01one Mar 7, 2023
7087cf0
Completed migration for front-end (for now)
marked01one Mar 13, 2023
89ffcbb
Added type to fix rendering
GuyWhoCode Mar 20, 2023
a19ec0e
Updated tsconfig.json
marked01one Mar 20, 2023
235e42a
Merge branch 'typescript_migration_frontend' of https://github.com/cp…
marked01one Mar 20, 2023
af480cf
Change Root.js to Root.tsx
marked01one Mar 20, 2023
7ec449a
chore(typescript_migration): fixed file name typos
lxkedinh Mar 21, 2023
7654ead
Fixed issues with constants.ts and improve code styling
marked01one Apr 17, 2023
07bbd09
Fixed issues with constants.ts and improve code styling
marked01one Apr 17, 2023
e85c1ef
Merge branch 'main' into typescript_migration_frontend
nappalion Nov 12, 2023
e258c2d
feat(text-input): migrate TextInput file into typescript
nappalion Nov 19, 2023
f9842ef
feat(groups): migrate group components to typescript
nappalion Nov 19, 2023
13c74d5
feat(feed): migrate feed screen to typescript
nappalion Nov 19, 2023
3387a30
feat(landing): migrate landing screens to typescript
nappalion Nov 20, 2023
558376e
feat(jest): migrate jest and other misc files to typescript
nappalion Nov 20, 2023
f56598b
fix(prop-types): remove unnecessary prop-types
nappalion Nov 20, 2023
46bcfba
feat(es-lin): add packages and config files for
nappalion Nov 20, 2023
e147acf
fix(feed-drawer): fix props.getItem unknown error for FlatList
nappalion Dec 8, 2023
f12caab
fix(eslint): fix cannot read file ‘../tsconfig.json’ eslint error
nappalion Dec 8, 2023
b58dccc
fix(typescript/eslint): apply fixes to typescript/eslint errors
nappalion Dec 8, 2023
670a649
fix(metro): ts is not supported for metro files
nappalion Dec 8, 2023
30dc02b
fix(config): fix eslint and typescript errors in config files
nappalion Dec 8, 2023
f8cef42
Merge branch 'main' into typescript_migration_frontend
nappalion Dec 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
1 change: 1 addition & 0 deletions packages/app/__tests__/FeedDrawer.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import React from 'react';
import FeedDrawer from '../screens/feed/FeedDrawer';
import { render, fireEvent } from '@testing-library/react-native';
Expand Down
8 changes: 0 additions & 8 deletions packages/app/components/Button.js

This file was deleted.

17 changes: 17 additions & 0 deletions packages/app/components/Button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';
import { Button as RNButton, NativeSyntheticEvent, NativeTouchEvent, ColorValue } from 'react-native';

type ButtonProps = {
title: string;
onPress: (ev: NativeSyntheticEvent<NativeTouchEvent>) => void;
color?: ColorValue | undefined;
accessibilityLabel?: string | undefined;
disabled?: boolean | undefined;
}


function Button(props: ButtonProps) {
return <RNButton {...props} />;
}

export default Button;
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React from 'react';
import { Image, StyleSheet, View } from 'react-native';
import { GestureResponderEvent, Image, ImageSourcePropType, StyleSheet, View } from 'react-native';
import EventCardText from './EventCardText';
import EventCardRegistration from './EventCardRegistration';

// Stylesheet for the EventCard component
const styles = StyleSheet.create({
banner: {
width: '100%',
Expand All @@ -24,21 +25,32 @@ const styles = StyleSheet.create({
}
});

const EventCard = (props) => {
export type EventCardProps = {
banner: ImageSourcePropType,
title: string,
timeBegin: string,
timeEnd: string,
location: string,
description: string,
}

const EventCard: React.FC<EventCardProps> = ({
banner, title, timeBegin, timeEnd, location, description
}) => {
const onRegisterClicked = () => {
alert("Register button works!");
}
nappalion marked this conversation as resolved.
Show resolved Hide resolved

return (
<View style={styles.card}>
{ props.banner ? <Image source={props.banner} style={styles.banner}/> : null}
{ banner ? <Image source={banner} style={styles.banner}/> : null}
<View style={{ padding: 10, marginBottom: 0 }}>
<EventCardText
title={props.title}
timeBegin={props.timeBegin}
timeEnd={props.timeEnd}
location={props.location}
description={props.description}
title={title}
timeBegin={timeBegin}
timeEnd={timeEnd}
location={location}
description={description}
/>
<EventCardRegistration register={onRegisterClicked} />
</View>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,20 @@
import React from "react";
import { StyleSheet, Button, View } from "react-native";
import { StyleSheet, Button, View, GestureResponderEvent } from "react-native";
import FaceIcon from "./FaceIcon";

// Sample array for testing
const sampleArray = [0,1,2,3];

const styles = StyleSheet.create({
buttonView: {
flex: 7,
justifyContent: 'center',
},
button: {
marginBottom: 0,
marginLeft: 0,
marginRight: 0,
},
faceView: {
flexDirection: 'row',
flex: 3,
justifyContent: 'center'
}
});
export type EventCardRegistrationProps = {
register: () => void;
}

const EventCardRegistration: React.FC<EventCardRegistrationProps> = ({register}) => {

export default function EventCardRegistration(props) {
const { register } = props;

return (
<View style={{ flexDirection: 'row' }}>
<View style={styles.buttonView}>
<Button
style={styles.button}
title='Going'
onPress={register}
/>
Expand All @@ -45,4 +30,24 @@ export default function EventCardRegistration(props) {
</View>
</View>
)
};
};

const styles = StyleSheet.create({
buttonView: {
flex: 7,
justifyContent: 'center',
},
button: {
marginBottom: 0,
marginLeft: 0,
marginRight: 0,
},
faceView: {
flexDirection: 'row',
flex: 3,
justifyContent: 'center'
}
});


export default EventCardRegistration;
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,35 @@ const styles = StyleSheet.create({
}
});

export default function EventCardText(props) {
export type EventTextProps = {
timeBegin: string;
timeEnd: string;
title: string;
location: string;
description: string;
}


const EventCardText: React.FC<EventTextProps> = ({
timeBegin, timeEnd, title, location, description
}) => {

return (
<View>
<Text style={styles.smallText}>
{props.timeBegin} - {props.timeEnd}
<Text style={styles.smallText}>
{timeBegin} - {timeEnd}
</Text>
<Text style={styles.eventTitle}>
{props.title}
{title}
</Text>
<Text style={styles.smallText}>
📌 {props.location}
📌 {location}
</Text>
<Text style={styles.description} numberOfLines={3}>
{props.description}
{description}
</Text>
</View>
)
}
};

export default EventCardText;
13 changes: 0 additions & 13 deletions packages/app/components/EventCard/FaceIcon.js

This file was deleted.

23 changes: 23 additions & 0 deletions packages/app/components/EventCard/FaceIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from "react";
import { StyleSheet, Image, ImageSourcePropType } from "react-native";

export type FaceIconProps = {
index: number;
iconUrl: string
}


const FaceIcon: React.FC<FaceIconProps> = ({index, iconUrl}) => {

return <Image source={{ uri: iconUrl }} key={index}
style={{
height: 36,
width: 36,
borderRadius: 18,
transform: [{translateX: 30 - index * 20}]
}}/>
};


export default FaceIcon;

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import React from 'react';
import React, { ReactNode } from 'react';
import { SafeAreaView, StatusBar } from 'react-native';

function Screen(props) {
type ScreenProps = {
children: ReactNode
}

function Screen(props: ScreenProps ) {
const { children, ...rest } = props;

return (
Expand Down
File renamed without changes.
File renamed without changes.
8 changes: 0 additions & 8 deletions packages/app/jsconfig.json

This file was deleted.

14 changes: 10 additions & 4 deletions packages/app/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "app",
"version": "1.0.0",
"main": "index.js",
"main": "index.tsx",
nappalion marked this conversation as resolved.
Show resolved Hide resolved
"scripts": {
"start": "expo start",
"android": "expo start --android",
Expand All @@ -24,17 +24,23 @@
"expo-web-browser": "~12.0.0",
"react": "18.1.0",
"react-native": "0.70.5",
"react-native-safe-area-context": "4.4.1",
"react-native-screens": "~3.18.0",
"react-native-gesture-handler": "~2.8.0",
"react-native-reanimated": "~2.12.0",
"react-native-safe-area-context": "4.4.1",
"react-native-screens": "~3.18.0",
"react-test-renderer": "^18.2.0"
},
"devDependencies": {
"@babel/core": "^7.19.3",
"@testing-library/react-native": "^11.5.0",
"@tsconfig/react-native": "^2.0.3",
"@types/jest": "^29.4.0",
"@types/react": "^18.0.28",
"@types/react-native": "^0.71.2",
"@types/react-test-renderer": "^18.0.0",
"babel-plugin-module-resolver": "^4.1.0",
"jest": "^29.3.1",
"babel-plugin-module-resolver": "^4.1.0"
"typescript": "^4.9.5"
},
"private": true
}
nappalion marked this conversation as resolved.
Show resolved Hide resolved
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useCallback, useEffect, useState } from "react";
import { Text, Image, StyleSheet, View, FlatList } from "react-native";
import { Text, Image, ImageProps as DefaultImageProps, ImageURISource, ImageSourcePropType, StyleSheet, View, FlatList } from "react-native";
import axios from "axios";
import AsyncStorage from "@react-native-async-storage/async-storage";

Expand All @@ -11,6 +11,30 @@ import { useUserContext } from "@app/utils/UserContext";
import { logoutUser } from "@app/utils/datalayer";
import { ENDPOINT } from "@app/utils/constants";

type EventType = {
event_id: string,
guild_id: string,
title: string,
description: string,
start_date: number,
end_date: number,
location: string,
thumbnail: string
}

type ItemType = {
banner: ImageSourcePropType,
title: string,
description: string,
location: string,
start_date: string,
end_date: string
}
marked01one marked this conversation as resolved.
Show resolved Hide resolved

type ImageProps = DefaultImageProps & {
source: ImageURISource;
};

function FeedScreen() {
const { user, setUser } = useUserContext();
nappalion marked this conversation as resolved.
Show resolved Hide resolved
const [events, setEvents] = useState([]);
Expand All @@ -30,11 +54,11 @@ function FeedScreen() {
const response = await axios.get(`${ENDPOINT}/events`, {
withCredentials: true,
headers: {
Authorization: token,
Authorization: token ?? "",
},
});

const serializeEvents = response.data.events.map(event => {
const serializeEvents = response.data.events.map((event: EventType) => {
return {
...event,
key: event.event_id
Expand All @@ -54,9 +78,10 @@ function FeedScreen() {
setRefreshing(false);
}, []);

const handleRenderItem = useCallback(({ item }) => {
const handleRenderItem = useCallback(( item: ItemType ) => {
return (
<CardEvent
banner={item.banner}
title={item.title}
description={item.description}
location={item.location}
Expand Down
nappalion marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Text } from 'react-native';

import Screen from '@app/components/Screen';

function GroupScreen() {
function GroupScreen(): JSX.Element {
return (
<Screen>
<Text>group</Text>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import GroupScreen from './GroupScreen';

const Group = createNativeStackNavigator();

function GroupStack() {
function GroupStack(): JSX.Element {
return (
<Group.Navigator
screenOptions={{ headerShown: false }}
Expand Down
Loading