Skip to content

Commit

Permalink
Add expo app
Browse files Browse the repository at this point in the history
  • Loading branch information
joonatanaatos committed Dec 21, 2023
1 parent 8010fa6 commit 7e3563a
Show file tree
Hide file tree
Showing 34 changed files with 16,051 additions and 0 deletions.
21 changes: 21 additions & 0 deletions app/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"env": {
"browser": true,
"es2021": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:react/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": ["@typescript-eslint", "react"],
"rules": {
"react/react-in-jsx-scope": "off",
"@typescript-eslint/no-non-null-asserted-optional-chain": "off"
}
}
19 changes: 19 additions & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
node_modules/
.expo/
dist/
npm-debug.*
*.jks
*.p8
*.p12
*.key
*.mobileprovision
*.orig.*
web-build/

# macOS
.DS_Store

# Temporary files created by Metro to check the health of the file watcher
.metro-health-check*

.env
6 changes: 6 additions & 0 deletions app/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"trailingComma": "all",
"tabWidth": 2,
"semi": true,
"singleQuote": true
}
3 changes: 3 additions & 0 deletions app/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
26 changes: 26 additions & 0 deletions app/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { StatusBar } from 'expo-status-bar';
import { NativeRouter, Navigate, Route, Routes } from 'react-router-native';
import Call from './components/views/Call';
import Dashboard from './components/views/Dashboard';
import { PaperProvider } from 'react-native-paper';
import { AppContextProvider } from './components/AppContext';
import Answer from './components/views/Answer';

export default function App() {
return (
<PaperProvider>
<AppContextProvider>
<NativeRouter>
<Routes>
<Route path="/" element={<Call />} />
<Route path="/accepted" element={<Answer accepted={true} />} />
<Route path="/declined" element={<Answer accepted={false} />} />
<Route path="/dashboard" element={<Dashboard />} />
<Route path="*" element={<Navigate to="/dashboard" />} />
</Routes>
<StatusBar style="auto" />
</NativeRouter>
</AppContextProvider>
</PaperProvider>
);
}
8 changes: 8 additions & 0 deletions app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Kuka soittaa?

## Getting started

1. Install yarn `npm install --global yarn`
2. Install dependencies `yarn install`
3. Create file `.env` and add the environment variable `API_URL="http://localhost:3000"`
4. Start development server `yarn start`
27 changes: 27 additions & 0 deletions app/api/answers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { api, useApi } from './base';

export interface Answer {
id?: string;
userName?: string;
eventId: string;
userId: string;
accepted: boolean;
comment: string;
created: string;
}

export const useAnswers = () => useApi<Answer[]>(['answers']);

export const createAnswer = async (
userId: string,
accepted: boolean,
comment?: string,
) =>
await api<Answer>(['answers'], {
method: 'POST',
body: JSON.stringify({
userId,
accepted,
comment,
}),
});
57 changes: 57 additions & 0 deletions app/api/base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { useEffect, useState } from 'react';
import { API_URL, APP_VERSION } from '@env';

const headers = {
'Content-Type': 'application/json',
'App-Version': APP_VERSION,
};

export const useApi = <Type>(path: string[], options?: RequestInit) => {
const [data, setData] = useState<Type | undefined>(undefined);
const [error, setError] = useState<string | undefined>(undefined);
const [isLoading, setIsLoading] = useState<boolean>(false);
const [status, setStatus] = useState<number | undefined>(undefined);

const url = `${API_URL}/${path.join('/')}`;

useEffect(() => {
fetch(url, {
headers,
...options,
})
.then(async (res) => {
setStatus(res.status);
if (res.ok) return res.json();
return Promise.reject(await res.text());
})
.then((res) => {
setData(res);
setIsLoading(false);
})
.catch((err) => {
console.error(err);
setError(err);
});
}, [url, options]);

return {
data,
error,
isLoading,
status,
};
};

export const api = async <Type>(path: string[], options?: RequestInit) => {
const url = `${API_URL}/${path.join('/')}`;

return (await fetch(url, {
headers,
...options,
})
.then(async (res) => {
if (res.ok) return res.json();
throw new Error(await res.text());
})
.catch((err) => console.error(err))) as Promise<Type>;
};
15 changes: 15 additions & 0 deletions app/api/events.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { useApi } from './base';

interface Event {
id: string;
time: string;
callerId: string;
caller: { name: string };
}

interface EventObject {
current?: Event;
next?: Event;
}

export const useEvents = () => useApi<EventObject>(['events']);
26 changes: 26 additions & 0 deletions app/api/users.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { api, useApi } from './base';

export interface User {
id?: string;
name: string;
}

export const useUsers = () => useApi<User[]>(['users']);

export const useUser = (id: string) => useApi<User>(['users', id]);

export const createUser = async (name: string) =>
await api<User>(['users'], {
method: 'POST',
body: JSON.stringify({
name,
}),
});

export const updateUser = async (id: string, name: string) =>
api<User>(['users', id], {
method: 'PUT',
body: JSON.stringify({
name,
}),
});
33 changes: 33 additions & 0 deletions app/app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"expo": {
"name": "Kuka soittaa?",
"slug": "kuka-soittaa",
"version": "0.0.1",
"orientation": "portrait",
"icon": "./assets/logo.png",
"userInterfaceStyle": "light",
"splash": {
"backgroundColor": "#ffffff"
},
"assetBundlePatterns": ["**/*"],
"ios": {
"supportsTablet": true,
"bundleIdentifier": "kukasoittaa"
},
"android": {
"adaptiveIcon": {
"foregroundImage": "./assets/logo.png",
"backgroundColor": "#ffffff"
},
"package": "com.joonatanaatos.kukasoittaa"
},
"web": {
"favicon": "./assets/logo.png"
},
"extra": {
"eas": {
"projectId": "c72fb7cc-2b5d-4d6b-8265-0cf6e59c5a18"
}
}
}
}
Binary file added app/assets/adaptive-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/splash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions app/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// eslint-disable-next-line no-undef
module.exports = function (api) {
api.cache(true);
return {
presets: ['babel-preset-expo'],
plugins: [
[
'module:react-native-dotenv',
{
moduleName: '@env',
path: '.env',
blacklist: null,
whitelist: null,
safe: false,
allowUndefined: true,
},
],
],
};
};
Loading

0 comments on commit 7e3563a

Please sign in to comment.