Skip to content

Commit

Permalink
Update finished app
Browse files Browse the repository at this point in the history
  • Loading branch information
hola-soy-milk committed Feb 21, 2024
1 parent e180f3b commit c084080
Show file tree
Hide file tree
Showing 22 changed files with 2,618 additions and 2,338 deletions.
10 changes: 0 additions & 10 deletions guest-list-mobile/.eslintignore

This file was deleted.

6 changes: 0 additions & 6 deletions guest-list-mobile/.eslintrc.cjs

This file was deleted.

36 changes: 16 additions & 20 deletions guest-list-mobile/app.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"expo": {
"name": "Guest List",
"scheme": "guest-list-mobile",
"name": "guest-list-mobile",
"slug": "guest-list-mobile",
"version": "1.0.0",
"orientation": "portrait",
Expand All @@ -10,35 +9,32 @@
"splash": {
"image": "./assets/splash.png",
"resizeMode": "contain",
"backgroundColor": "#f0e5cf"
"backgroundColor": "#ffffff"
},
"assetBundlePatterns": [
"**/*"
],
"assetBundlePatterns": ["**/*"],
"ios": {
"supportsTablet": true
},
"android": {
"adaptiveIcon": {
"foregroundImage": "./assets/adaptive-icon.png",
"backgroundColor": "#f0e5cf"
},
"package": "com.hola_soy_milk.guestlistmobile"
"backgroundColor": "#ffffff"
}
},
"scheme": "guest-list-mobile",
"web": {
"bundler": "metro",
"favicon": "./assets/favicon.png",
"bundler": "metro"
"output": "server"
},
"plugins": [
"expo-router"
],
"extra": {
"router": {
"origin": false
},
"eas": {
"projectId": "a1acaf69-939d-4848-a410-9826ebc944fb"
}
}
"expo-font",
[
"expo-router",
{
"origin": "https://evanbacon.dev/"
}
]
]
}
}
2 changes: 0 additions & 2 deletions guest-list-mobile/app/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ function routeMapping(pathname: string) {

export default function HomeLayout() {
const pathname = usePathname();

const label = routeMapping(pathname);
const [fontsLoaded] = useFonts({
Pacifico_400Regular,
Expand All @@ -42,7 +41,6 @@ export default function HomeLayout() {
if (!fontsLoaded) {
return null;
}

return (
<View style={styles.container}>
<Header label={label} />
Expand Down
5 changes: 0 additions & 5 deletions guest-list-mobile/app/guests/[...id].tsx

This file was deleted.

59 changes: 59 additions & 0 deletions guest-list-mobile/app/guests/[id].tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Expo router Page to display a single user

import { useEffect, useState } from 'react';

import { useLocalSearchParams } from 'expo-router';
import { StyleSheet, Text, View } from 'react-native';

import { colors } from '../../styles/constants';

const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: colors.background,
},
text: {
color: colors.text,
},
});

type Guest = {
id: string;
firstName: string;
lastName: string;
deadline?: string;
attending: boolean;
};

const API_URL =
'https://37820499-b115-4574-94d1-64870873aef3-00-2o18dc9ex4s5s.spock.replit.dev';

export default function Guests() {
const { id } = useLocalSearchParams();

const [guest, setGuest] = useState<Guest>();

useEffect(() => {
async function loadGuest() {
const response = await fetch(`${API_URL}/guests/${id}`);

Check failure on line 38 in guest-list-mobile/app/guests/[id].tsx

View workflow job for this annotation

GitHub Actions / Lint, Check Types

Invalid type "string | string[] | undefined" of template literal expression
const fetchedGuest = await response.json();
setGuest(fetchedGuest);
}
loadGuest();

Check warning on line 42 in guest-list-mobile/app/guests/[id].tsx

View workflow job for this annotation

GitHub Actions / Lint, Check Types

Promises must be awaited, end with a call to .catch, or end with a call to .then with a rejection handler
}, [id]);

if (!guest) {
return null;
}

return (
<View style={styles.container}>
<Text style={styles.text}>
{guest.firstName} {guest.lastName}
</Text>
<Text style={styles.text}>
{guest.attending ? 'Attending' : 'Not attending'}
</Text>
</View>
);
}
5 changes: 5 additions & 0 deletions guest-list-mobile/app/hello+api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { ExpoRequest, ExpoResponse } from 'expo-router/server';

export function GET(request: ExpoRequest) {

Check warning on line 3 in guest-list-mobile/app/hello+api.ts

View workflow job for this annotation

GitHub Actions / Lint, Check Types

'request' is defined but never used
return ExpoResponse.json({ hello: 'world' });
}
54 changes: 31 additions & 23 deletions guest-list-mobile/app/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@ import { FlatList, StyleSheet } from 'react-native';
import GuestItem from '../components/GuestItem';
import { colors } from '../styles/constants';

const API_URL =
'https://37820499-b115-4574-94d1-64870873aef3-00-2o18dc9ex4s5s.spock.replit.dev';

const styles = StyleSheet.create({
list: {
marginTop: 30,
paddingLeft: 30,
paddingRight: 30,
width: '100%',
},
button: {
marginTop: 30,
paddingTop: 10,
Expand All @@ -22,6 +19,19 @@ const styles = StyleSheet.create({
backgroundColor: colors.cardBackground,
fontSize: 24,
},
list: {
marginTop: 30,
paddingLeft: 30,
paddingRight: 30,
width: '100%',
},
container: {
flex: 1,
backgroundColor: colors.background,
},
text: {
color: colors.text,
},
});

type Guest = {
Expand All @@ -32,45 +42,43 @@ type Guest = {
attending: boolean;
};

const API_URL = 'http://45063d72-10f4-4077-a954-686bc0c70988.id.repl.co';

const renderItem = (item: { item: Guest }) => <GuestItem guest={item.item} />;

export default function Index() {
const { firstName, lastName } = useLocalSearchParams<{
firstName?: Guest['firstName'];
lastName?: Guest['lastName'];
}>();

const [guests, setGuests] = useState<Guest[]>([]);

useEffect(() => {
async function callApi() {
const response = await fetch(`/hello`);
const data = await response.json();
console.log(data);
}
async function loadGuests() {
// const response = await fetch(`${API_URL}/guests`);
// const fetchedGuests: Guest[] = await response.json();
// setGuests(fetchedGuests);
const response = await fetch(`${API_URL}/guests`);
const fetchedGuests: Guest[] = await response.json();
setGuests(fetchedGuests);
}

async function postGuest(guest: Guest) {
async function postGuest(guest: { firstName: string; lastName: string }) {

Check warning on line 65 in guest-list-mobile/app/index.tsx

View workflow job for this annotation

GitHub Actions / Lint, Check Types

'guest' is defined but never used
const response = await fetch(`${API_URL}/guests`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
firstName: guest.firstName,
lastName: guest.lastName,
}),
body: JSON.stringify({ firstName, lastName }),
});
const newGuest: Guest = await response.json();
setGuests((g) => [...g, newGuest]);
setGuests([...guests, newGuest]);
}
loadGuests();

Check warning on line 76 in guest-list-mobile/app/index.tsx

View workflow job for this annotation

GitHub Actions / Lint, Check Types

Promises must be awaited, end with a call to .catch, or end with a call to .then with a rejection handler
callApi();

Check warning on line 77 in guest-list-mobile/app/index.tsx

View workflow job for this annotation

GitHub Actions / Lint, Check Types

Promises must be awaited, end with a call to .catch, or end with a call to .then with a rejection handler

if (typeof firstName === 'string' && typeof lastName === 'string') {
postGuest({ id: '0', attending: false, firstName, lastName }).catch(
() => {},
);
postGuest({ firstName, lastName });

Check warning on line 80 in guest-list-mobile/app/index.tsx

View workflow job for this annotation

GitHub Actions / Lint, Check Types

Promises must be awaited, end with a call to .catch, or end with a call to .then with a rejection handler
}
loadGuests().catch(() => {});
}, [firstName, lastName]);

Check warning on line 82 in guest-list-mobile/app/index.tsx

View workflow job for this annotation

GitHub Actions / Lint, Check Types

React Hook useEffect has a missing dependency: 'guests'. Either include it or remove the dependency array. You can also do a functional update 'setGuests(g => ...)' if you only need 'guests' in the 'setGuests' call
return (
<>
Expand Down
8 changes: 4 additions & 4 deletions guest-list-mobile/app/new-guest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@ const styles = StyleSheet.create({
});

export default function NewGuest() {
const [firstName, setFirstName] = useState('');
const [lastName, setLastName] = useState('');
const [firstName, onFirstName] = useState('');

Check warning on line 33 in guest-list-mobile/app/new-guest.tsx

View workflow job for this annotation

GitHub Actions / Lint, Check Types

useState call is not destructured into value + setter pair
const [lastName, onLastName] = useState('');

Check warning on line 34 in guest-list-mobile/app/new-guest.tsx

View workflow job for this annotation

GitHub Actions / Lint, Check Types

useState call is not destructured into value + setter pair
return (
<>
<TextInput
style={styles.input}
onChangeText={setFirstName}
onChangeText={onFirstName}
placeholder="First Name"
value={firstName}
/>
<TextInput
style={styles.input}
onChangeText={setLastName}
onChangeText={onLastName}
placeholder="Last Name"
value={lastName}
/>
Expand Down
6 changes: 6 additions & 0 deletions guest-list-mobile/babel.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = function (api) {
api.cache(true);
return {
presets: ['babel-preset-expo'],
};
};
10 changes: 0 additions & 10 deletions guest-list-mobile/babel.config.js

This file was deleted.

20 changes: 12 additions & 8 deletions guest-list-mobile/components/GuestItem.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Link } from 'expo-router';
import { StyleSheet, Text, View } from 'react-native';
import { router } from 'expo-router';
import { StyleSheet, Text, TouchableOpacity } from 'react-native';

import { colors } from '../styles/constants';

Expand Down Expand Up @@ -46,15 +46,19 @@ type Props = {
};

export default function GuestItem({ guest }: Props) {
const { firstName, lastName, attending } = guest;

const { id, firstName, lastName, attending } = guest;
const openGuest = () => {
router.push({
pathname: `/guests/[id]`,
params: { id },
});
};
return (
<View style={styles.card}>
<TouchableOpacity style={styles.card} onPress={openGuest}>
<Text style={styles.center}>
{firstName} {lastName}
</Text>
<Link href={`guests/${guest.id}`}>Check it out</Link>
<Text style={styles.right}>{attending ? 'Coming!' : 'Not Coming'}</Text>
</View>
<Text style={styles.right}>{attending ? 'Coming!' : 'Not coming.'}</Text>
</TouchableOpacity>
);
}
6 changes: 4 additions & 2 deletions guest-list-mobile/components/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import React from 'react';

import Constants from 'expo-constants';
import { SafeAreaView, StyleSheet, Text, View } from 'react-native';

Expand All @@ -14,15 +16,15 @@ const styles = StyleSheet.create({
},
label: {
color: colors.text,
fontFamily: 'Pacifico_400Regular',
fontSize: 32,
textAlign: 'center',
fontFamily: 'Pacifico_400Regular',
},
});

type Props = {
label: string;
};

export default function Header(props: Props) {
return (
<SafeAreaView style={styles.safeArea}>
Expand Down
18 changes: 0 additions & 18 deletions guest-list-mobile/eas.json

This file was deleted.

1 change: 1 addition & 0 deletions guest-list-mobile/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from 'eslint-config-upleveled';
Loading

0 comments on commit c084080

Please sign in to comment.