-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8010fa6
commit 7e3563a
Showing
34 changed files
with
16,051 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"trailingComma": "all", | ||
"tabWidth": 2, | ||
"semi": true, | ||
"singleQuote": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"editor.defaultFormatter": "esbenp.prettier-vscode" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
], | ||
], | ||
}; | ||
}; |
Oops, something went wrong.