Skip to content

Typescript Migration - Front End #15

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

Open
wants to merge 37 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
12 changes: 9 additions & 3 deletions packages/app/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
{
"plugins": ["react", "react-native"],
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": ["react", "react-native","@typescript-eslint"],
"env": {
"react-native/react-native": true
},
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 2023,
"ecmaFeatures": { "jsx": true }
"ecmaFeatures": { "jsx": true },
"project": ["./tsconfig.json"],
"tsconfigRootDir": "packages/app/"
},
"ignorePatterns": ["babel.config.js", "metro.config.js"],
"extends": [
"prettier",
"eslint:recommended",
"plugin:react-native/all",
"plugin:react/recommended"
"plugin:react/recommended",
"plugin:@typescript-eslint/recommended"
]
}
15 changes: 7 additions & 8 deletions packages/app/Root.js → packages/app/Root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ import Constants from "expo-constants";
const Tab = createBottomTabNavigator();
const Stack = createNativeStackNavigator();

import {
GoogleSignin,
} from "@react-native-google-signin/google-signin";
import { GoogleSignin } from "@react-native-google-signin/google-signin";

function TabNavigation() {
return (
Expand All @@ -39,7 +37,8 @@ function App() {
const { user, setUser } = useUserContext();

const currentSession = async () => {
let accessToken = await SecureStore.getValueFor("accessToken");
const accessToken = await SecureStore.getValueFor("accessToken");
let refreshToken = await SecureStore.getValueFor("refreshToken");

if (!accessToken) {
return;
Expand Down Expand Up @@ -68,7 +67,7 @@ function App() {
}

// If access token is invalid/expired, try to get a new one with the refresh token
const refreshToken = await SecureStore.getValueFor("refreshToken");
refreshToken = await SecureStore.getValueFor("refreshToken");
try {
const { data: response } = await axios.post(`${ENDPOINT}/auth/token`, {
refreshToken: refreshToken,
Expand Down Expand Up @@ -97,10 +96,10 @@ function App() {

useEffect(() => {
GoogleSignin.configure({
webClientId: Constants.expoConfig.extra.webClientId,
iosClientId: Constants.expoConfig.extra.iosClientId,
webClientId: Constants?.expoConfig?.extra?.webClientId,
iosClientId: Constants?.expoConfig?.extra?.iosClientId,
});

currentSession();
}, []);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React from "react";
import FeedDrawer from "../screens/feed/FeedDrawer";
import { render } from "@testing-library/react-native";
import { NavigationContainer } from "@react-navigation/native";
import jest, { test, expect } from "jest";

// This section is used to mock the user data information within the FeedScreen.
// Without this, Jest does not recognize the user data and throws an error.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react";
import { render } from "@testing-library/react-native";
import GroupScreen from "@app/screens/group/GroupScreen";
import GroupHeader from "@app/components/GroupScreen/GroupHeader";
import jest, { describe, it, expect } from "jest";
import { GroupHeaderProps } from "@app/types/Group";

jest.mock("@expo/vector-icons/Ionicons", () => ({
Ionicons: () => null,
Expand All @@ -12,6 +12,8 @@ jest.mock("@expo/vector-icons/FontAwesome5", () => ({
FontAwesome5: () => null,
}));

let props: GroupHeaderProps;

describe("GroupScreen Tests", () => {
describe(GroupScreen, () => {
it("renders the GroupHeader component", () => {
Expand All @@ -35,25 +37,25 @@ describe("GroupScreen Tests", () => {

describe(GroupHeader, () => {
it("renders group icon", () => {
const { getByTestId } = render(<GroupHeader />);
const { getByTestId } = render(<GroupHeader {...props} />);
const groupIcon = getByTestId("groupIcon");
expect(groupIcon).toBeTruthy();
});

it("renders club banner", () => {
const { getByTestId } = render(<GroupHeader />);
const { getByTestId } = render(<GroupHeader {...props} />);
const clubBanner = getByTestId("clubBanner");
expect(clubBanner).toBeTruthy();
});

it("renders group header info", () => {
const { getByTestId } = render(<GroupHeader />);
const { getByTestId } = render(<GroupHeader {...props} />);
const groupHeaderInfo = getByTestId("groupHeaderInfo");
expect(groupHeaderInfo).toBeTruthy();
});

it("renders group media icons", () => {
const { getByTestId } = render(<GroupHeader />);
const { getByTestId } = render(<GroupHeader {...props} />);
const groupMediaIcon = getByTestId("groupMediaIcon");
expect(groupMediaIcon).toBeTruthy();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import { render, fireEvent } from "@testing-library/react-native";
import LandingScreen from "@app/screens/landing/LandingScreen";
import jest, { describe, it, expect } from "jest";
import { LandingScreenNavigationProps } from "@app/types/Landing";

// Need these to avoid "Cannot use import statement outside a module" error
jest.mock("expo-web-browser", () => ({
Expand All @@ -14,24 +14,31 @@ jest.mock("expo-constants", () => ({
Constants: () => null,
}));

let props: LandingScreenNavigationProps;
const mockedNavigate = jest.fn();

jest.mock("@react-navigation/native", () => ({
useNavigation: () => ({ navigate: mockedNavigate }),
}));

describe(LandingScreen, () => {
it("renders logo text", () => {
const { getByTestId } = render(<LandingScreen />);
const { getByTestId } = render(<LandingScreen {...props} />);
const logo = getByTestId("logo");
expect(logo).toBeTruthy();
});

describe("Email/Password Text Inputs", () => {
it("renders correctly", () => {
const { getByTestId } = render(<LandingScreen />);
const { getByTestId } = render(<LandingScreen {...props} />);
const emailInput = getByTestId("emailInput.textInput");
const passwordInput = getByTestId("passwordInput.textInput");
expect(emailInput).toBeTruthy();
expect(passwordInput).toBeTruthy();
});

it("displays the placeholder text", () => {
const { getByTestId } = render(<LandingScreen />);
const { getByTestId } = render(<LandingScreen {...props} />);

const emailInput = getByTestId("emailInput.textInput");
const passwordInput = getByTestId("passwordInput.textInput");
Expand All @@ -41,7 +48,7 @@ describe(LandingScreen, () => {
});

it("accepts inputs", () => {
const { getByTestId } = render(<LandingScreen />);
const { getByTestId } = render(<LandingScreen {...props} />);

const emailInput = getByTestId("emailInput.textInput");
const passwordInput = getByTestId("passwordInput.textInput");
Expand All @@ -54,7 +61,9 @@ describe(LandingScreen, () => {
});

it("doesn't accept an invalid email/password", () => {
const { queryByTestId, getByTestId } = render(<LandingScreen />);
const { queryByTestId, getByTestId } = render(
<LandingScreen {...props} />
);
const loginButton = getByTestId("loginButton");
const emailInput = getByTestId("emailInput.textInput");
const passwordInput = getByTestId("passwordInput.textInput");
Expand All @@ -69,7 +78,7 @@ describe(LandingScreen, () => {
});

it("visibility icon toggles password visibility", () => {
const { getByTestId } = render(<LandingScreen />);
const { getByTestId } = render(<LandingScreen {...props} />);
const hidePasswordButton = getByTestId("passwordInput.visibility");
const passwordInput = getByTestId("passwordInput.textInput");

Expand All @@ -81,33 +90,30 @@ describe(LandingScreen, () => {

describe("Buttons", () => {
it("login button renders correctly", () => {
const { getByTestId } = render(<LandingScreen />);
const { getByTestId } = render(<LandingScreen {...props} />);
const loginButton = getByTestId("loginButton");
expect(loginButton).toBeTruthy();
fireEvent.press(loginButton);
});

it("google button renders correctly", () => {
const { getByTestId } = render(<LandingScreen />);
const { getByTestId } = render(<LandingScreen {...props} />);
const googleButton = getByTestId("googleButton");
expect(googleButton).toBeTruthy();
fireEvent.press(googleButton);
});

it("signup button renders correctly", () => {
const mockNavigation = {
navigate: jest.fn(),
};
const { getByTestId } = render(
<LandingScreen navigation={mockNavigation} />
<LandingScreen {...props} />
);
const signupButton = getByTestId("signupButton");
expect(signupButton).toBeTruthy();
fireEvent.press(signupButton);
});

it("forgot password button renders correctly", () => {
const { getByTestId } = render(<LandingScreen />);
const { getByTestId } = render(<LandingScreen {...props} />);
const forgotPassButton = getByTestId("forgotPassButton");
expect(forgotPassButton).toBeTruthy();
fireEvent.press(forgotPassButton);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { test, expect } from "jest";

test("test", () => {
expect(true).toBe(true);
});
3 changes: 2 additions & 1 deletion packages/app/app.config.js → packages/app/app.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require("dotenv").config();
import dotenv from 'dotenv';
dotenv.config();

module.exports = {
name: "Icebreak",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from "react";
import Svg, { Path } from "react-native-svg";

const EyeOff = (props) => (
const EyeOff = (props: any) => (
<Svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from "react";
import Svg, { Path } from "react-native-svg";

const EyeOn = (props) => (
const EyeOn = (props: any) => (
<Svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from "react";
import Svg, { Path } from "react-native-svg";

const GoogleIcon = (props) => (
const GoogleIcon = (props: any) => (
<Svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 48 48"
Expand Down
6 changes: 5 additions & 1 deletion packages/app/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
module.exports = function (api) {
api.cache(false);
return {
presets: ["babel-preset-expo"],
presets: [
["@babel/preset-env", { targets: { node: "current" } }],
"babel-preset-expo",
"@babel/preset-typescript",
],
plugins: [
[
require.resolve("babel-plugin-module-resolver"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import { StyleSheet, TouchableHighlight, View, Text } from "react-native";
import PropTypes from "prop-types";
import { ButtonProps } from "@app/types/Button.ts";

const styles = StyleSheet.create({
container: {
Expand All @@ -13,9 +13,13 @@ const styles = StyleSheet.create({
},
});

function Button(props) {
function Button(props: ButtonProps) {
return (
<TouchableHighlight {...props}>
<TouchableHighlight
{...props}
style={[styles.container, props.style]}
onPress={props.onPress}
disabled={props.disabled}>
<View style={styles.container}>
{props.icon}

Expand All @@ -35,12 +39,4 @@ function Button(props) {
);
}

Button.propTypes = {
fontColor: PropTypes.string,
fontWeight: PropTypes.string,
icon: PropTypes.node,
textStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
title: PropTypes.string,
};

export default Button;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import { StyleSheet, View, Text } from "react-native";
import PropTypes from "prop-types";
import { DividerWithTextProps } from "@app/types/DividerWithText";

const GRAY = "#c4c4c4";

Expand All @@ -27,7 +27,7 @@ const styles = StyleSheet.create({
},
});

function DividerWithText(props) {
function DividerWithText(props: DividerWithTextProps) {
return (
<View style={styles.container}>
<View style={styles.lineDivider} />
Expand All @@ -37,8 +37,4 @@ function DividerWithText(props) {
);
}

DividerWithText.propTypes = {
title: PropTypes.string,
};

export default DividerWithText;
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React from "react";
import React, { FC } from "react";
import { Image, StyleSheet, View } from "react-native";
import EventCardText from "./EventCardText";
import EventCardRegistration from "./EventCardRegistration";
import PropTypes from "prop-types";
import { EventCardProps } from "@app/types/EventCard";

const cardColor = "white";

// Stylesheet for the EventCard component
const styles = StyleSheet.create({
banner: {
borderTopLeftRadius: 15,
Expand All @@ -26,7 +27,7 @@ const styles = StyleSheet.create({
},
});

const EventCard = ({
const EventCard: FC<EventCardProps> = ({
style,
banner,
title,
Expand Down Expand Up @@ -56,14 +57,4 @@ const EventCard = ({
);
};

EventCard.propTypes = {
banner: PropTypes.number,
description: PropTypes.string,
location: PropTypes.string,
style: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
timeBegin: PropTypes.string,
timeEnd: PropTypes.string,
title: PropTypes.string,
};

export default EventCard;
Loading