-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
170 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { FC, useEffect, useState } from 'react'; | ||
|
||
import { cn } from '@/lib/utils'; | ||
import { socket } from '@/lib/socket'; | ||
|
||
const UPLOAD_TASKS = [ | ||
{ name: 'Validation', kind: 'validation' }, | ||
{ name: 'Data Sourcing', kind: 'data-sourcing' }, | ||
{ name: 'Geocoding', kind: 'geocoding' }, | ||
{ name: 'Impact Calculation', kind: 'impact-calculation' }, | ||
]; | ||
|
||
type ProgressTask = { | ||
kind: string; | ||
step: string; | ||
progress: number; | ||
}; | ||
|
||
export const UploadTracker: FC = () => { | ||
const [tasksProgress, setTaskProgress] = useState<ProgressTask[]>([]); | ||
|
||
useEffect(() => { | ||
socket.connect(); | ||
|
||
return () => { | ||
socket.disconnect(); | ||
}; | ||
}, []); | ||
|
||
useEffect(() => { | ||
function setTasksProgress(tasks: ProgressTask[]) { | ||
setTaskProgress(tasks); | ||
} | ||
|
||
socket.on('message', setTasksProgress); | ||
|
||
return () => { | ||
socket.off('message', setTasksProgress); | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<div className="w-full rounded-3xl bg-white px-8 py-10"> | ||
<div className="grid grid-cols-4 gap-1"> | ||
{UPLOAD_TASKS.map(({ name }) => ( | ||
<div className="flex flex-col items-start" key={name}> | ||
<span className={cn('text-base text-gray-400')}>{name}</span> | ||
{/* // ? use parser for the percentage */} | ||
<span className="text-sm text-gray-500">Progress: 20%</span> | ||
</div> | ||
))} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default UploadTracker; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { io } from 'socket.io-client'; | ||
|
||
// "undefined" means the URL will be computed from the `window.location` object | ||
const URL = process.env.NODE_ENV === 'production' ? undefined : 'http://localhost:4000'; | ||
|
||
export const socket = io(URL, { | ||
autoConnect: false, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters