Compare commits
	
		
			1 Commits
		
	
	
		
			de14be0673
			...
			6ca8e4e42e
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | 6ca8e4e42e | 
| @ -8,7 +8,7 @@ import Arrangement from '@/app/ui/arrangements/arrangement'; | ||||
| import ArrangementsTable from '@/app/ui/arrangements/arrangements-table'; | ||||
| import { classNames } from '@/app/ui/components/button'; | ||||
| import { Toast } from 'primereact/toast'; | ||||
| import React, { useEffect, useRef, useState } from 'react'; | ||||
| import React, { useRef, useState } from 'react'; | ||||
| 
 | ||||
| export default function Page() { | ||||
|   const toast = useRef<Toast>(null); | ||||
|  | ||||
| @ -13,8 +13,6 @@ export function loadTableSimulations(onLoad?: (tableSimulations: TableArrangemen | ||||
|           name: record.name, | ||||
|           discomfort: record.discomfort, | ||||
|           valid: record.valid, | ||||
|           progress: record.progress, | ||||
|           status : record.status | ||||
|         }); | ||||
|       })); | ||||
|     }, (error) => { | ||||
|  | ||||
| @ -14,8 +14,6 @@ export type TableArrangement = { | ||||
|   guests?: Guest[]; | ||||
|   discomfort?: number; | ||||
|   valid?: boolean; | ||||
|   progress: number; | ||||
|   status: 'in_progress' | 'completed' | 'not_started'; | ||||
| } | ||||
| 
 | ||||
| export type User = { | ||||
|  | ||||
| @ -22,12 +22,10 @@ export type Table = { | ||||
| export class TableSimulation implements Entity { | ||||
|   id?: string; | ||||
|   tables: Table[]; | ||||
|   progress: number; | ||||
| 
 | ||||
|   constructor(id?: string, tables?: Table[], progress?: number) { | ||||
|   constructor(id?: string, tables?: Table[]) { | ||||
|     this.id = id; | ||||
|     this.tables = tables || []; | ||||
|     this.progress = progress || 0; | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| @ -45,7 +43,7 @@ export class TableSimulationSerializer implements Serializable<TableSimulation> | ||||
|           } | ||||
|         }, | ||||
|       } | ||||
|     }), data.progress); | ||||
|     })); | ||||
|   } | ||||
| 
 | ||||
|   toJson(simulation: TableSimulation): string { | ||||
|  | ||||
| @ -10,21 +10,11 @@ import { loadTableSimulations } from "@/app/api/tableSimulations"; | ||||
| import { ArchiveBoxXMarkIcon, CheckBadgeIcon } from "@heroicons/react/24/outline"; | ||||
| import { Tooltip } from "primereact/tooltip"; | ||||
| import clsx from "clsx"; | ||||
| import { ProgressBar } from "primereact/progressbar"; | ||||
| import { useEffect } from "react"; | ||||
| import { TableSimulation, TableSimulationSerializer } from "@/app/lib/tableSimulation"; | ||||
| import { AbstractApi } from "@/app/api/abstract-api"; | ||||
| 
 | ||||
| export default function ArrangementsTable({ onArrangementSelected }: { onArrangementSelected: (arrangementId: string) => void }) { | ||||
|   const [arrangements, setArrangements] = useState<Array<TableArrangement>>([]); | ||||
|   const [arrangementsLoaded, setArrangementsLoaded] = useState(false); | ||||
| 
 | ||||
|   useEffect(() => { | ||||
|     refreshSimulations(); | ||||
|     const interval = setInterval(refreshSimulations, 10000); | ||||
|     return () => clearInterval(interval); | ||||
|   }, []); | ||||
| 
 | ||||
|   function refreshSimulations() { | ||||
|     loadTableSimulations((arrangements) => { | ||||
|       setArrangements(arrangements); | ||||
| @ -36,9 +26,11 @@ export default function ArrangementsTable({ onArrangementSelected }: { onArrange | ||||
|     onArrangementSelected(e.currentTarget.getAttribute('data-arrangement-id') || ''); | ||||
|   } | ||||
| 
 | ||||
|   !arrangementsLoaded && refreshSimulations(); | ||||
| 
 | ||||
|   return ( | ||||
|     <TableOfContents | ||||
|       headers={['Name', 'Discomfort', 'Status', 'Actions']} | ||||
|       headers={['Name', 'Discomfort', 'Actions', 'Status']} | ||||
|       caption='Simulations' | ||||
|       elements={arrangements} | ||||
|       rowRender={(arrangement) => ( | ||||
| @ -52,19 +44,18 @@ export default function ArrangementsTable({ onArrangementSelected }: { onArrange | ||||
|           <td className="px-6 py-4"> | ||||
|             {arrangement.discomfort} | ||||
|           </td> | ||||
|           <td className="px-4"> | ||||
|             <Tooltip target=".tooltip-status" /> | ||||
| 
 | ||||
|             <> | ||||
|               { arrangement.valid && arrangement.status === 'not_started' && <ProgressBar mode="indeterminate" style={{ height: '6px' }}></ProgressBar>  } | ||||
|               { arrangement.valid && arrangement.status !== 'not_started' && <ProgressBar value={(100 * arrangement.progress).toFixed(2) }></ProgressBar> } | ||||
| 
 | ||||
|               { !arrangement.valid && 'The list of potential guests has changed since this simulation.' } | ||||
|             </> | ||||
|           </td> | ||||
|           <td> | ||||
|             <button data-arrangement-id={arrangement.id} onClick={arrangementClicked} className={classNames('primary')}>Load</button> | ||||
|           </td> | ||||
|           <td> | ||||
|             <Tooltip target=".tooltip-status" /> | ||||
| 
 | ||||
|             { | ||||
|               arrangement.valid ? | ||||
|                 <CheckBadgeIcon className='size-6 tooltip-status' data-pr-position="right" data-pr-tooltip="Simulation is valid" /> : | ||||
|                 <ArchiveBoxXMarkIcon className='size-6 tooltip-status' data-pr-position="right" data-pr-tooltip="Simulation is expired due to attendance or affinity changes" /> | ||||
|             } | ||||
|           </td> | ||||
|         </tr> | ||||
|       )} | ||||
|     /> | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user