-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add front end for caching new collections.
- Loading branch information
Showing
5 changed files
with
97 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
||
} |
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,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 new Promise(r => setTimeout(r, 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 new Promise(r => setTimeout(r, 5000)); | ||
await pollUpdates() | ||
|
||
} | ||
|
||
return ( | ||
<div className="p-2"> | ||
<select className="p-1 m-2" value={repo} onChange={(e) => { | ||
setRepo(e.target.value); | ||
}}> | ||
{repos.map( | ||
(repo) => <option value={repo} key={repo}>{repo}</option> | ||
)} | ||
</select> | ||
<input className="m-2 border-2" type="text" size={40} value={collectionName} onChange={(e) => setCollectionName(e.target.value)} /> | ||
<button className="p-1 m-2" onClick={submitForm}>Add</button> | ||
</div> | ||
) | ||
} | ||
|
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,23 @@ | ||
|
||
export const dynamic = 'force-dynamic' | ||
|
||
import Link from 'next/link' | ||
|
||
import AddCollectionSelect from '@/components/addCollectionSelect' | ||
|
||
export default async function AddCollection() { | ||
|
||
|
||
const repoUrls = JSON.parse(process.env.REPO_URLS ?? "[]") | ||
|
||
/* REPO_URLS */ | ||
return ( | ||
<div> | ||
<div className="text-m m-5"><Link href={"/"}><- Back to collections</Link></div> | ||
<div className="text-2xl m-5">Add a Collection:</div> | ||
<AddCollectionSelect repos={Object.keys(repoUrls)} /> | ||
</div> | ||
|
||
) | ||
|
||
} |
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 |
---|---|---|
|
@@ -3,5 +3,6 @@ BASE_URL= | |
BUTLER_URL= | ||
BUCKET_NAME= | ||
BUCKET_URL= | ||
PAGE_LINKS= | ||
S3_KEY= | ||
S3_SECRET= |