diff --git a/app/_components/AddCollectionSelectServer.js b/app/_components/AddCollectionSelectServer.js new file mode 100644 index 0000000..16983af --- /dev/null +++ b/app/_components/AddCollectionSelectServer.js @@ -0,0 +1,22 @@ + +'use server' + +export async function pollJob(jobId) { + + let res = await fetch(`http://production-tools/plot-navigator/cache/job/${jobId}`) + let data = await res.json() + return data +} + +export async function putCollection(repo, collectionName) { + + let res = await fetch("http://production-tools/plot-navigator/cache", + {method: "PUT", + body: JSON.stringify({repo: repo, collection: collectionName}), + headers: {"Content-Type": "application/json"}} + ) + let data = await res.json() + + return data.jobId + +} diff --git a/app/_components/addCollectionSelect.js b/app/_components/addCollectionSelect.js new file mode 100644 index 0000000..b73c241 --- /dev/null +++ b/app/_components/addCollectionSelect.js @@ -0,0 +1,48 @@ +'use client' + +import React from 'react'; +import { useState } from 'react' + +import {putCollection, pollJob} from './AddCollectionSelectServer.js' + +export default function AddCollectionSelect({repos}) { + + const [repo, setRepo] = useState(repos[0]); + const [collectionName, setCollectionName] = useState(""); + const [jobId, setJobId] = useState(""); + + const pollUpdates = async () => { + await wait(5000) + console.log(`Polling ${jobId}`) + const res = await pollJob(jobId) + console.log(`Status ${res.status}`) + if(res.status == "in_progress") { + await pollUpdates() + } + + + } + + const submitForm = async () => { + const jobId = await putCollection(repo, collectionName) + setJobId(jobId) + await wait(5000) + await pollUpdates() + + } + + return ( +