This commit is contained in:
E
2021-03-07 21:46:40 -07:00
parent b0aec2cfd1
commit 0760c93ce4
7 changed files with 107 additions and 48 deletions

View File

@@ -4,7 +4,6 @@ import React, { FormEvent } from 'react'
import { useState } from 'react'
import { useHistory } from 'react-router-dom'
import { createClient } from '../api'
import settings from '../settings'
export const Dashboard = () => {
const history = useHistory()
@@ -30,13 +29,13 @@ export const Dashboard = () => {
return
}
if (settings.env === 'jank') {
history.push(`/sessions/${phone}`)
return
}
const client_id = await createClient({
name,
email,
phone: parseInt(phone),
})
await createClient({ name, email, phone: parseInt(phone) })
history.push(`/sessions/${phone}`)
history.push(`/sessions/${client_id}`)
}
return (

View File

@@ -1,24 +1,38 @@
import React, { useEffect, useState } from 'react'
import { RouteComponentProps, useHistory } from 'react-router-dom'
import { getClient, killSession, restartSession } from '../api'
import { getClient, killSession, restartSession, startSession } from '../api'
import { SessionPictures } from './SessionPictures'
import { Button, Divider, message, PageHeader, Popconfirm, Row } from 'antd'
import {
Button,
Divider,
message,
PageHeader,
Popconfirm,
Row,
Tag,
} from 'antd'
import { Content } from 'antd/lib/layout/layout'
import { Client } from '../types'
type Props = RouteComponentProps<{ clientId: string }>
export const Session = (props: Props) => {
const history = useHistory()
const { clientId } = props.match.params
const [client, setClient] = useState<Client | null>(null)
const [active, setActive] = useState(false)
const handleStartSession = async () => {
await startSession(clientId)
message.loading('Photo sequence starting! Stand by...')
setActive(true)
}
const handleRestartSession = async () => {
setActive(false)
message.loading('Removing all photos...')
await restartSession(clientId)
message.loading('Restarting capture sequence! Stand by...')
setActive(true)
}
@@ -33,13 +47,13 @@ export const Session = (props: Props) => {
useEffect(() => {
const get = async () => {
const { photos } = await getClient(clientId)
if (photos.length) setActive(true)
else message.info("Click 'Capture' to take a photo set!")
const client = await getClient(clientId)
setClient(client)
if (client.has_photos) setActive(true)
}
get()
})
}, [clientId])
return (
<Content>
@@ -47,6 +61,7 @@ export const Session = (props: Props) => {
ghost={false}
onBack={() => history.goBack()}
title={`Session for ${clientId}`}
tags={active ? <Tag color="lime">Active</Tag> : <Tag>Inactive</Tag>}
subTitle={`session has ${active ? 'started' : 'not started'}`}
extra={[
<Button
@@ -88,7 +103,7 @@ export const Session = (props: Props) => {
></PageHeader>
<Divider />
<Row className="controls">
{active && <SessionPictures clientId={clientId} />}
<SessionPictures clientId={clientId} />
</Row>
</Content>
)

View File

@@ -1,34 +1,55 @@
import { Spin } from 'antd'
import React, { useEffect, useState } from 'react'
import { getClient } from '../api'
import { Card, Spin } from 'antd'
import { getSession } from '../api'
import { client } from '../data'
import settings from '../settings'
import { url } from 'inspector'
type Props = {
clientId: string
}
export const SessionPictures = ({ clientId }: Props) => {
const [pics, setPics] = useState<string[] | null>(null)
const [urls, setUrls] = useState<string[] | null>(null)
useEffect(() => {
const get = async () => {
if (pics) return
const { photos } = await getClient(clientId)
if (photos.length) setPics(photos)
if (urls) return
const { photos } = await getSession(clientId)
if (photos.length) setUrls(photos)
}
const interval = setInterval(get, 300)
const interval = setInterval(get, 5000)
return () => clearInterval(interval)
}, [clientId, pics])
}, [clientId, urls])
const host = settings.env === 'jank' ? 'http://192.168.1.107:5000' : ''
if (!urls?.length) return null
return (
<div>
<h3>Session Pictures</h3>
{pics ? (
pics.map((src) => <img id={src} src={src} alt="lol" />)
) : (
<Spin />
)}
<div className="photo-wall">
{urls ? (
urls
.sort((a, b) => a.split('_')[0].localeCompare(b.split('_')[0]))
.map((src) => (
<Card className="photo" title={src.split('_')[0]}>
<img
key={src}
id={src}
src={`${host}/output/${clientId}/${src}`}
alt="lol"
/>
</Card>
))
) : (
<Spin />
)}
</div>
</div>
)
}