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
12 changed files
with
467 additions
and
99 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 @@ | ||
import { ReactNode, useEffect, useState } from "react"; | ||
import { SortableItem } from "./SortableItem"; | ||
|
||
export interface SortableProps { | ||
items: ReactNode[]; | ||
onChange: (newSortedIndices: number[]) => void; | ||
} | ||
|
||
export const Sortable = ({ items, onChange }) => { | ||
const [sortOrder, setSortOrder] = useState<number[]>([]); | ||
|
||
const update = (newRanking: number[]) => { | ||
setSortOrder(newRanking); | ||
onChange(newRanking); | ||
}; | ||
|
||
useEffect(() => { | ||
const indices = Array.from({ length: items.length }).map((_, i) => i); | ||
setSortOrder(indices); | ||
onChange(indices); | ||
}, [items, onChange]); | ||
|
||
return ( | ||
<ul className="flex flex-col gap-4"> | ||
{sortOrder.map((rank, i) => ( | ||
<SortableItem | ||
key={`${rank}`} | ||
canIncrement={i > 0} | ||
onIncrement={() => { | ||
const newRanking = sortOrder.slice(); | ||
const newIdx = i - 1; | ||
[newRanking[i], newRanking[newIdx]] = [newRanking[newIdx], newRanking[i]]; | ||
update(newRanking); | ||
}} | ||
canDecrement={i < sortOrder.length - 1} | ||
onDecrement={() => { | ||
const newRanking = sortOrder.slice(); | ||
const newIdx = i + 1; | ||
[newRanking[i], newRanking[newIdx]] = [newRanking[newIdx], newRanking[i]]; | ||
update(newRanking); | ||
}} | ||
> | ||
{items[rank]} | ||
</SortableItem> | ||
))} | ||
</ul> | ||
); | ||
}; |
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,44 @@ | ||
import { ArrowUpIcon, ArrowDownIcon } from "@heroicons/react/20/solid"; | ||
import { Button } from "src/components/Button"; | ||
import clsx from "clsx"; | ||
|
||
export interface SortableItemProps { | ||
canIncrement: boolean; | ||
canDecrement: boolean; | ||
onIncrement: () => void; | ||
onDecrement: () => void; | ||
children: React.ReactNode; | ||
} | ||
|
||
export const SortableItem = ({ canIncrement, canDecrement, onIncrement, onDecrement, children }: SortableItemProps) => { | ||
return ( | ||
<li className="grid grid-cols-[min-content_1fr] items-center rounded-lg shadow-md gap-x-2 p-2"> | ||
<ArrowButton active={canIncrement} onClick={onIncrement}> | ||
<ArrowUpIcon width={28} /> | ||
</ArrowButton> | ||
<span style={{ gridRow: "span 2" }}>{children}</span> | ||
|
||
<ArrowButton active={canDecrement} onClick={onDecrement}> | ||
<ArrowDownIcon width={28} /> | ||
</ArrowButton> | ||
</li> | ||
); | ||
}; | ||
|
||
interface ArrowButtonProps { | ||
active: boolean; | ||
onClick: () => void; | ||
children: React.ReactNode; | ||
} | ||
|
||
const ArrowButton = ({ children, active, onClick }: ArrowButtonProps) => { | ||
return ( | ||
<Button | ||
className={clsx("justify-center", active ? "hover:bg-indigo-200" : "opacity-10")} | ||
onClick={onClick} | ||
disabled={!active} | ||
> | ||
{children} | ||
</Button> | ||
); | ||
}; |
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,10 @@ | ||
export const TaskInfo = ({ id, output }: { id: string; output: any }) => { | ||
return ( | ||
<div className="grid grid-cols-[min-content_auto] gap-x-2 text-gray-700"> | ||
<b>Prompt</b> | ||
<span>{id}</span> | ||
<b>Output</b> | ||
<span>{output}</span> | ||
</div> | ||
); | ||
}; |
Oops, something went wrong.