From 91644d07efda302f432457a0943aa09d01bdd2da Mon Sep 17 00:00:00 2001 From: Immanuel Onyeka Date: Sat, 23 Oct 2021 11:18:15 -0400 Subject: [PATCH] Add return and archiving to calls page --- src/App.jsx | 29 ++++++++++++++++++++++++++--- src/Call.jsx | 36 +++++++++++++++++++++++++++++------- src/Feed.jsx | 14 ++------------ 3 files changed, 57 insertions(+), 22 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index 2490f2f..c4c6492 100755 --- a/src/App.jsx +++ b/src/App.jsx @@ -6,20 +6,43 @@ import Feed from './Feed.jsx'; import Navigator from './Navigator.jsx'; import Call from './Call.jsx'; +function fetchActivities(setStack) { + return fetch('https://aircall-job.herokuapp.com/activities') + .then(response => { + return response.json() + }) +} + +function fetchEntry(id) { + return fetch('https://aircall-job.herokuapp.com/activities/' + id) + .then(response => { + return response.json() + }) +} + const App = () => { const [recent, setRecent] = useState(true) const [entry, setEntry] = useState() + const [ stack, setStack ] = useState(null) + + useEffect(() => { + fetchActivities().then(data => {setStack(data)}) + }, []) - let focus = setEntry(c) }/> + let focus = setEntry(c) }/> if (entry) { - focus = + focus = setEntry(null)} + onUpdate={(e) => { + fetchEntry(e.id).then(data => setEntry(data)) + fetchActivities().then(data => setStack(data)) + }}/> } return (
- setRecent(r) } + {setEntry(null); setRecent(r)} } recent={recent}/>
diff --git a/src/Call.jsx b/src/Call.jsx index c71a619..f940a3a 100644 --- a/src/Call.jsx +++ b/src/Call.jsx @@ -26,16 +26,34 @@ function ContactIcon() { ) } -function BackIcon() { +function BackIcon(props) { return ( - + props.onClick()} width="1em" height="1em" viewBox="0 0 16 + 16" className="bi bi-chevron-left" fill="currentColor" + xmlns="http://www.w3.org/2000/svg"> ) } +// Function should be moved to parent component idealy +function moveCall(call, update) { + fetch('https://aircall-job.herokuapp.com/activities/' + + String(call.id), + { + method: 'POST', + headers: {'Content-Type': 'application/json', + 'Accept': 'application/json' + }, + body: JSON.stringify({'is_archived': !call.is_archived}) + } + ).then(response => { + if (response.ok) { + update(call) + } + }) +} + function Call(props) { return (
@@ -63,7 +81,11 @@ function Call(props) {
- + props.onBack()}/> +
diff --git a/src/Feed.jsx b/src/Feed.jsx index 016cc67..f282c0a 100644 --- a/src/Feed.jsx +++ b/src/Feed.jsx @@ -63,19 +63,9 @@ function Seperator(props) { // The component used for retrieving, sorting, and rendering calls. function Feed(props) { - const [ stack, setStack ] = useState(null) - - - useEffect(() => { - fetch('https://aircall-job.herokuapp.com/activities') - .then(response => { - return response.json() - }).then(data => { - setStack(data) - }) - }, []) - + const stack = props.stack let entries + if (stack) { entries = stack.map((entry, index) => {