Skip to content

Commit

Permalink
Merge pull request #87 from tylerslaton/explore-page
Browse files Browse the repository at this point in the history
fix: don't allow empty tool add and allow delete on explore
  • Loading branch information
tylerslaton authored Aug 13, 2024
2 parents 355d069 + 3d917ed commit b563222
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
12 changes: 10 additions & 2 deletions app/explore/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export default function Explore() {
setCurrent('/explore')
refresh()
}, []);

useEffect(() => { refresh() }, [authenticated]);;

return (
Expand Down Expand Up @@ -169,7 +170,7 @@ export default function Explore() {
{loading ?
<Loading /> :
<div className={'pb-10'}>
<ScriptModal script={selectedScript} open={open} setOpen={setOpen} />
<ScriptModal script={selectedScript} open={open} setOpen={setOpen} refresh={refresh} />
<div className="grid gap-12 grid-cols-1 lg:grid-cols-2 2xl:grid-cols-3 4xl:grid-cols-4">
{filteredScripts.map((script) => (
<div
Expand Down Expand Up @@ -217,7 +218,14 @@ export default function Explore() {
className="col-span-1 lg:col-span-2 2xl:col-span-3 4xl:col-span-4"
onPress={() => {
setNextLoading(true)
getScripts({limit: 10, continue: next})
getScripts({
limit: 10,
filter: (query || owner || visibility) && filter === "featured" ? '' : filter,
search: query,
visibility: visibility,
owner: owner,
continue: next
})
.then((resp) => {
if (resp.continue) setNext(resp.continue)
else setNext(undefined)
Expand Down
1 change: 1 addition & 0 deletions components/edit/configure/imports/toolCatalog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ const ToolCatalog: React.FC<ToolCatalogProps> = ({tools, addTool, removeTool}) =
startContent={<GoPlus />}
color="primary"
onPress={() => {
if (!url) return;
if (!priorityTools["From URL"].map((t) => t.url).includes(url)) {
addTool(url)
priorityTools["From URL"].push({
Expand Down
16 changes: 12 additions & 4 deletions components/explore/scriptModal.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
"use client"

import {Modal, ModalContent, ModalBody, ModalHeader, ModalFooter, Button, Link, Avatar, Divider, Accordion, AccordionItem, Chip, Tooltip, Table, TableHeader, TableColumn, TableRow, TableCell, TableBody } from "@nextui-org/react";
import {ParsedScript} from "@/actions/me/scripts";
import {deleteScript, ParsedScript} from "@/actions/me/scripts";
import { GoCode, GoPaperAirplane, GoPencil, GoTrash } from "react-icons/go";
import { AuthContext } from "@/contexts/auth";
import { useContext, useEffect, useState } from "react";
import { useCallback, useContext, useEffect, useState } from "react";
import {TbListDetails} from "react-icons/tb";
import { LiaExpandArrowsAltSolid } from "react-icons/lia";

interface ScriptModalProps {
className?: string;
script: ParsedScript;
open: boolean; setOpen: React.Dispatch<React.SetStateAction<boolean>>;
refresh: () => void;
}

const ScriptModal = ({ className, script, open, setOpen }: ScriptModalProps) => {
const ScriptModal = ({ className, script, open, setOpen, refresh }: ScriptModalProps) => {
const {authenticated, me} = useContext(AuthContext);
const [expanded, setExpanded] = useState(false);

const handleDelete = useCallback((script: ParsedScript) => {
deleteScript(script)
.then(() => refresh() )
.catch((error) => console.error(error))
.finally(() => setOpen(false));
}, []);

return (
<Modal
id="script-modal"
Expand Down Expand Up @@ -97,7 +105,7 @@ const ScriptModal = ({ className, script, open, setOpen }: ScriptModalProps) =>
{authenticated && me?.username === script.owner &&
<>
<Button as={Link} href={`/edit?file=${script.publicURL}&id=${script.id}`} color="primary" className="w-full" startContent={<GoPencil />}>Edit</Button>
<Button className="w-full" color="danger" variant="bordered" startContent={<GoTrash />}>Delete</Button>
<Button className="w-full" color="danger" variant="bordered" startContent={<GoTrash />} onPress={() => handleDelete(script)}>Delete</Button>
</>
}
</ModalFooter>
Expand Down

0 comments on commit b563222

Please sign in to comment.