Browser tab content: # GitHub Spark \\\`jsx import React from "react"; import {…
- User
Browser tab content: # GitHub Spark
```jsx
import React from "react";
import { createRoot } from "react-dom/client";
import {
SparkApp,
PageContainer,
Card,
Button,
Input,
Dialog,
DialogTrigger,
DialogContent,
DialogHeader,
DialogTitle,
DialogDescription,
DialogFooter,
DialogClose
} from "@github/spark/components";
import { useKV } from "@github/spark/hooks";
import { Plus, Edit, Trash, DragHandle } from "@phosphor-icons/react";
import { DragDropContext, Droppable, Draggable } from "react-beautiful-dnd";
// Main App component
function App() {
// Use useKV to persist routines
const [routines, setRoutines] = useKV("dailyRoutines", []);
const [editingRoutine, setEditingRoutine] = React.useState(null);
const [isDialogOpen, setIsDialogOpen] = React.useState(false);
// Function to add or update a routine
const saveRoutine = (routine) => {
if (editingRoutine) {
// Update existing routine
setRoutines(
routines.map((r) => (r.id === routine.id ? routine : r))
);
} else {
// Add new routine
setRoutines([
...routines,
{ ...routine, id: Date.now().toString() },
]);
}
setIsDialogOpen(false);
setEditingRoutine(null);
};
// Function to delete a routine
const deleteRoutine = (id) => {
setRoutines(routines.filter((r) => r.id !== id));
};
// Function to handle drag end
const onDragEnd = (result) => {
if (!result.destination) return;
const newRoutines = Array.from(routines);
const [reorderedItem] = newRoutines.splice(result.source.index, 1);
newRoutines.splice(result.destination.index, 0, reorderedItem);
setRoutines(newRoutines);
};
return (
{/* Routine list */}
{(provided) => (
{...provided.droppableProps}
ref={provided.innerRef}
className="space-y-4"
>
{routines.map((routine, index) => (
<Draggable
key={routine.id}
- Assistant
The content you provided is a snippet of a React application that uses the GitHub Spark component library for a daily routine manager. Here's a breakdown of the key components and functionality of the application:
-
Libraries and Components:
- The application leverages React for building the user interface and uses hooks for managing state.
- It imports various components from the GitHub Spark library, which provides styled UI components.
-