Skip to content

Commit 3821e3e

Browse files
feature: UNT-T23965: Added Typescript Support
1 parent 4632223 commit 3821e3e

File tree

16 files changed

+184
-70
lines changed

16 files changed

+184
-70
lines changed

app/App.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import React from 'react';
1+
import React, {FC} from 'react';
22
import {AppContainer} from './navigation';
33

4-
const App = () => {
4+
const App: FC<{}> = () => {
55
return <AppContainer></AppContainer>;
66
};
77

app/components/button/Button.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import React from 'react';
1+
import React, {FC} from 'react';
22
import {StyleSheet, TouchableOpacity} from 'react-native';
33
import {Colors} from '../../constants';
4+
import type {ButtonProp} from './ButtonTypes';
45

5-
export const Button = ({
6+
export const Button: FC<ButtonProp> = ({
67
onPress = () => {},
78
children,
89
style = {},
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import type {GestureResponderEvent, StyleProp, ViewStyle} from 'react-native';
2+
3+
export interface ButtonProp {
4+
children: JSX.Element[] | JSX.Element;
5+
onPress?: (event: GestureResponderEvent) => void;
6+
style?: StyleProp<ViewStyle>;
7+
}

app/components/row/Row.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import React from 'react';
1+
import React, {FC} from 'react';
22
import {StyleSheet, View} from 'react-native';
3+
import type {RowProps} from './RowTypes';
34

4-
export const Row = ({children, style = {}}) => {
5+
export const Row: FC<RowProps> = ({children, style = {}}) => {
56
return <View style={[styles.container, style]}>{children}</View>;
67
};
78

app/components/row/RowTypes.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import type {StyleProp, ViewStyle} from 'react-native';
2+
3+
export interface RowProps {
4+
children: JSX.Element[] | JSX.Element;
5+
style?: StyleProp<ViewStyle>;
6+
}

app/constants/Config.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import SQLite from 'react-native-sqlite-storage';
22

3-
const DB_NAME = 'MyTSC.db';
3+
const DB_NAME: string = 'MyTSC.db';
44

5-
const scripts = [
5+
const scripts: string[] = [
66
'CREATE TABLE IF NOT EXISTS active_user (userId INTEGER, name VARCHAR, mobile INTEGER, role VARCHAR, username VARCHAR)',
77
'CREATE TABLE IF NOT EXISTS users (userId INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR, mobile INTEGER, role VARCHAR, username VARCHAR, password VARCHAR)',
88
'CREATE TABLE IF NOT EXISTS todos (id INTEGER PRIMARY KEY AUTOINCREMENT,userId INTEGER, title VARCHAR, is_completed BOOLEAN, FOREIGN KEY(userId) REFERENCES users(userId))',
@@ -14,19 +14,19 @@ class Database {
1414
this.db = this.initializeDatabase();
1515
}
1616

17-
initializeDatabase() {
17+
initializeDatabase(): SQLite.SQLiteDatabase {
1818
return SQLite.openDatabase(
1919
{name: DB_NAME, location: 'default'},
2020
this.handleDbSuccess,
2121
this.handleDbError,
2222
);
2323
}
2424

25-
getDatabase() {
25+
getDatabase(): SQLite.SQLiteDatabase {
2626
return this.db;
2727
}
2828

29-
initialSetup() {
29+
initialSetup(): void {
3030
this.db.transaction(tx => {
3131
scripts.map((scpt, idx) => {
3232
tx.executeSql(
@@ -43,12 +43,12 @@ class Database {
4343
});
4444
}
4545

46-
handleDbSuccess = () => {
46+
handleDbSuccess = (): void => {
4747
console.log('Database opened successfully');
4848
this.initialSetup();
4949
};
5050

51-
handleDbError = (error: SQLite.SQLError) => {
51+
handleDbError = (error: SQLite.SQLError): void => {
5252
console.error('Error opening database: ', error);
5353
};
5454
}

app/modules/AddTask/AddTaskScreen.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
import React, {useState} from 'react';
1+
import React, {FC, useState} from 'react';
22
import {Alert, Text, TextInput, View} from 'react-native';
33
import {Button, Row} from '../../components';
44
import {styles} from './AddTaskStyles';
55
import Database from '../../constants/Config';
6+
import type {ComponentProps} from './AddTaskTypes';
7+
import type {SQLiteDatabase} from 'react-native-sqlite-storage';
68

7-
const DB = Database.getDatabase();
9+
const DB: SQLiteDatabase = Database.getDatabase();
810

9-
export const AddTask = ({route, navigation}) => {
11+
export const AddTask: FC<ComponentProps> = ({route, navigation}) => {
1012
const [taskName, setTaskName] = useState<string>('');
1113

1214
let {userId} = route.params;
13-
const addTask = () => {
15+
const addTask = (): void => {
1416
if (!taskName) {
1517
Alert.alert('Enter Task Name');
1618
return;
@@ -19,14 +21,14 @@ export const AddTask = ({route, navigation}) => {
1921
DB.executeSql(
2022
'insert into todos (userId, title, is_completed) values (?,?,?)',
2123
[userId, taskName, false],
22-
(result) => {
24+
result => {
2325
setTaskName('');
24-
console.log("Success",result)
25-
navigation.goBack()
26+
console.log('Success', result);
27+
navigation.goBack();
2628
},
27-
(e) => {
29+
e => {
2830
console.log('Error', e);
29-
}
31+
},
3032
);
3133
};
3234

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import type {ScreenComponentProps} from '../../navigation/AppNavigationTypes';
2+
3+
export type ComponentProps = ScreenComponentProps<'AddTask'>;

app/modules/Auth/SignIn/SignInScreen.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
import React, {useState} from 'react';
1+
import React, {FC, useState} from 'react';
22
import {Alert, Text, TextInput, View} from 'react-native';
33
import {styles} from './SignInStyles';
44
import {Button, Row} from '../../../components';
55
import Database from '../../../constants/Config';
6+
import type {ComponentProp} from './SignInTypes';
7+
import type {User} from '../SignUp/SignUpTypes';
8+
import type { ResultSet, SQLiteDatabase, Transaction } from 'react-native-sqlite-storage';
69

7-
const DB = Database.getDatabase();
10+
const DB: SQLiteDatabase = Database.getDatabase();
811

9-
const SignInScreen = ({navigation, setLoggedInUser}) => {
10-
const [username, setUsername] = useState('');
11-
const [password, setPassword] = useState('');
12+
const SignInScreen: FC<ComponentProp> = ({navigation, setLoggedInUser}) => {
13+
const [username, setUsername] = useState<string>('');
14+
const [password, setPassword] = useState<string>('');
1215

13-
const handleLogin = () => {
16+
const handleLogin = (): void => {
1417
if (!username || !password) {
1518
Alert.alert('Enter all fields');
1619
return;
@@ -20,7 +23,7 @@ const SignInScreen = ({navigation, setLoggedInUser}) => {
2023
tx.executeSql(
2124
'select * from users where username = ? and password = ?',
2225
[username, password],
23-
(result, set) => {
26+
(result: Transaction, set: ResultSet) => {
2427
if (set.rows.length == 0) {
2528
Alert.alert('Invalid Credentials');
2629
return;
@@ -29,7 +32,7 @@ const SignInScreen = ({navigation, setLoggedInUser}) => {
2932
console.log('User Logged In Successfully', result);
3033
Alert.alert('User Logged In Successfully');
3134

32-
let obj;
35+
let obj: User;
3336

3437
console.log('___', set.rows.item(0));
3538
obj = set.rows.item(0);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import type {ScreenNavigationProp} from '../../../navigation/AppNavigationTypes';
2+
import type {User} from '../SignUp/SignUpTypes';
3+
4+
export type ComponentProp = {
5+
navigation: ScreenNavigationProp<'SignIn'>;
6+
setLoggedInUser: (user: User) => void;
7+
};

0 commit comments

Comments
 (0)