This commit is contained in:
E 2021-03-07 20:56:20 -07:00
parent 1e8d655d1d
commit b0aec2cfd1
5 changed files with 61 additions and 55 deletions

View File

@ -5,7 +5,7 @@ import settings from '../settings'
const apiUrl = '/api' const apiUrl = '/api'
export const createClient = async (body: Client) => { export const createClient = async (body: Omit<Client, 'photos'>) => {
await axios.post(`${apiUrl}/clients`, body) await axios.post(`${apiUrl}/clients`, body)
} }
@ -20,12 +20,12 @@ export const getClient = async (id: string): Promise<Client> => {
return res.data return res.data
} }
export const startSession = async (clientId: string) => { export const startSession = async (clientId: string) => {
const res = await axios.post(`${apiUrl}/clients/${clientId}/session`) const res = await axios.post(`${apiUrl}/clients/${clientId}`)
return res.data // session data return res.data // session data
} }
export const killSession = async (clientId: string) => { export const killSession = async (clientId: string) => {
await axios.delete(`${apiUrl}/clients/${clientId}/session`) await axios.delete(`${apiUrl}/clients/${clientId}`)
} }
export const restartSession = async (clientId: string) => { export const restartSession = async (clientId: string) => {

View File

@ -5,12 +5,7 @@ import 'antd/dist/antd.css'
import App from './App' import App from './App'
import reportWebVitals from './reportWebVitals' import reportWebVitals from './reportWebVitals'
ReactDOM.render( ReactDOM.render(<App />, document.getElementById('root'))
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root'),
)
// If you want to start measuring performance in your app, pass a function // If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log)) // to log results (for example: reportWebVitals(console.log))

View File

@ -1,3 +1,4 @@
import { message } from 'antd'
import { Content } from 'antd/lib/layout/layout' import { Content } from 'antd/lib/layout/layout'
import React, { FormEvent } from 'react' import React, { FormEvent } from 'react'
import { useState } from 'react' import { useState } from 'react'
@ -24,6 +25,7 @@ export const Dashboard = () => {
if (phone.length < 10) { if (phone.length < 10) {
// helpful message // helpful message
message.error('Check all fields!')
setError('Phone number needs to be a length of at least 10') setError('Phone number needs to be a length of at least 10')
return return
} }
@ -44,6 +46,7 @@ export const Dashboard = () => {
<label htmlFor="name"> <label htmlFor="name">
Name: Name:
<input <input
minLength={3}
value={name} value={name}
onChange={(e) => setName(e.target.value)} onChange={(e) => setName(e.target.value)}
name="name" name="name"

View File

@ -2,7 +2,7 @@ import React, { useEffect, useState } from 'react'
import { RouteComponentProps, useHistory } from 'react-router-dom' import { RouteComponentProps, useHistory } from 'react-router-dom'
import { getClient, killSession, restartSession } from '../api' import { getClient, killSession, restartSession } from '../api'
import { SessionPictures } from './SessionPictures' import { SessionPictures } from './SessionPictures'
import { Button, message, PageHeader, Popconfirm, Row } from 'antd' import { Button, Divider, message, PageHeader, Popconfirm, Row } from 'antd'
import { Content } from 'antd/lib/layout/layout' import { Content } from 'antd/lib/layout/layout'
type Props = RouteComponentProps<{ clientId: string }> type Props = RouteComponentProps<{ clientId: string }>
@ -43,7 +43,6 @@ export const Session = (props: Props) => {
return ( return (
<Content> <Content>
<div className="site-page-header-ghost-wrapper">
<PageHeader <PageHeader
ghost={false} ghost={false}
onBack={() => history.goBack()} onBack={() => history.goBack()}
@ -59,15 +58,20 @@ export const Session = (props: Props) => {
Capture Capture
</Button>, </Button>,
<Popconfirm <Popconfirm
key="retry"
title="Re-capture set?" title="Re-capture set?"
onConfirm={handleRestartSession} onConfirm={handleRestartSession}
> >
<Button key="retry" type="default" disabled={!active}> <Button type="default" disabled={!active}>
Retry Capture Retry Capture
</Button> </Button>
</Popconfirm>, </Popconfirm>,
<Popconfirm title="Delete all photos?" onConfirm={handleNuke}> <Popconfirm
<Button key="nuke" danger disabled={!active}> key="nuke"
title="Delete all photos?"
onConfirm={handleNuke}
>
<Button danger disabled={!active}>
Nuke Session Nuke Session
</Button> </Button>
</Popconfirm>, </Popconfirm>,
@ -82,8 +86,7 @@ export const Session = (props: Props) => {
</Button>, </Button>,
]} ]}
></PageHeader> ></PageHeader>
</div> <Divider />
<Row className="controls"> <Row className="controls">
{active && <SessionPictures clientId={clientId} />} {active && <SessionPictures clientId={clientId} />}
</Row> </Row>

View File

@ -1,5 +1,6 @@
import { Spin } from 'antd'
import React, { useEffect, useState } from 'react' import React, { useEffect, useState } from 'react'
import { getSession } from '../api' import { getClient } from '../api'
type Props = { type Props = {
clientId: string clientId: string
@ -11,8 +12,8 @@ export const SessionPictures = ({ clientId }: Props) => {
useEffect(() => { useEffect(() => {
const get = async () => { const get = async () => {
if (pics) return if (pics) return
const previewPics = await getSession(clientId) const { photos } = await getClient(clientId)
if (previewPics) setPics(previewPics) if (photos.length) setPics(photos)
} }
const interval = setInterval(get, 300) const interval = setInterval(get, 300)
@ -23,7 +24,11 @@ export const SessionPictures = ({ clientId }: Props) => {
return ( return (
<div> <div>
<h3>Session Pictures</h3> <h3>Session Pictures</h3>
{pics && pics.map((src) => <img id={src} src={src} />)} {pics ? (
pics.map((src) => <img id={src} src={src} alt="lol" />)
) : (
<Spin />
)}
</div> </div>
) )
} }