diff --git a/app/src/components/header.tsx b/app/src/components/header.tsx index 87a5a3a..6ea998f 100644 --- a/app/src/components/header.tsx +++ b/app/src/components/header.tsx @@ -40,6 +40,11 @@ const NavBar = () => { const {data: session} = useSession() const router = useRouter() const { toastDispatch } = useToasts() + const [path, setPath] = useState("") + + useEffect(() => { + if (typeof window !== 'undefined') setPath(window.location.href) + }, [path]) useEffect(() => { const atTopCallback = () => { @@ -67,7 +72,7 @@ const NavBar = () => { session ? : - signIn("google")}/> + signIn("google", {callbackUrl: path})}/> } diff --git a/app/src/pages/demo.tsx b/app/src/pages/demo.tsx index 69b5c80..3a76160 100644 --- a/app/src/pages/demo.tsx +++ b/app/src/pages/demo.tsx @@ -23,11 +23,13 @@ const Session = ({ data, onClick = () => { }, ...props }) => { } const Demo: NextPage = ({ officers }) => { + const updateDelay = 2000 const { toastDispatch } = useToasts(); const [input, setInput] = useState({ phone: '', }) const [sessions, setSessions] = useState([]) + const [loadingSummary, setLoadingSummary] = useState(false) const [focusSession, setFocusSession] = useState(null) const { data: session } = useSession() @@ -46,33 +48,41 @@ const Demo: NextPage = ({ officers }) => { notify(toastDispatch, "", "Updated Phone: " + input.phone, ToastType.SUCCESS) } - const popOut = async (session) => { - notify(toastDispatch, "", "Loading call log...", ToastType.DEFAULT) + const getSummary = async (sesh) => { + const summary = await (await fetch(process.env.NEXT_PUBLIC_API_URL + '/session/summary/?sessionId=' + sesh.id, { + method: 'GET', + headers: { + 'Content-Type': 'application/json' + }, + })).json() + return summary.summary + } - const messages = await (await fetch(process.env.NEXT_PUBLIC_API_URL + '/session/message/?sessionId=' + session.id, { + const summarize = async () => { + // setLoadingSummary(true) + notify(toastDispatch, "", "Loading summary...", ToastType.DEFAULT) + focusSession.summary = await getSummary(focusSession) + notify(toastDispatch, "", "Loaded summary!", ToastType.SUCCESS) + setFocusSession(focusSession) + // setLoadingSummary(false) + } + + const updateMessages = async (sesh) => { + const messages = await (await fetch(process.env.NEXT_PUBLIC_API_URL + '/session/message/?sessionId=' + sesh.id, { method: 'GET', headers: { 'Content-Type': 'application/json' }, })).json() - const summary = await (await fetch(process.env.NEXT_PUBLIC_API_URL + '/session/summary/?sessionId=' + session.id, { - method: 'GET', - headers: { - 'Content-Type': 'application/json' - }, - })).json() + return messages.messages + } - session.messages = messages.messages; - session.summary = summary.summary; - console.log(session) - - setFocusSession(session) - notify(toastDispatch, "", "Loaded call log!", ToastType.SUCCESS) + const popOut = async (sesh) => { + setFocusSession(sesh) } const transfer = async () => { - console.log(session['token'].sub) const res = await (await fetch(process.env.NEXT_PUBLIC_API_URL + '/session/transfer/?sessionId=' + focusSession.id, { method: 'GET', headers: { @@ -87,6 +97,28 @@ const Demo: NextPage = ({ officers }) => { setFocusSession(null) } + useEffect(() => { + const main = async () => { + const fetcher = async () => { + focusSession.messages = await updateMessages(focusSession) + setFocusSession(focusSession) + } + if (focusSession) { + if (!focusSession.messages) { + await fetcher(); + const cycle = () => setTimeout(async () => { + if (focusSession) { + await fetcher() + cycle() + } + }, updateDelay) + cycle() + } + } + } + main() + }, [focusSession]) + useEffect(() => { const interval = setInterval(async () => { const fetcher = async () => { @@ -100,7 +132,7 @@ const Demo: NextPage = ({ officers }) => { setSessions(s.sessions) } await fetcher() - }, 2000) + }, updateDelay) return () => clearInterval(interval) }, []) @@ -119,12 +151,13 @@ const Demo: NextPage = ({ officers }) => { {focusSession ? <>
-

Caller: {focusSession.callerPhone} | {focusSession.startedAt}

+

Caller: {focusSession.callerPhone} | {focusSession.startedAt}

+

Summary: {focusSession.summary}

- {focusSession.messages.map(msg => { + {(focusSession.messages ? focusSession.messages : []).map(msg => { return (

{msg.role}: {msg.content}