FoodOrderer: stage 0

This commit is contained in:
Kagura 2024-11-22 13:20:25 +08:00
parent 4c6c668a3e
commit 128cf29dfc
3 changed files with 67 additions and 1 deletions

View file

@ -2,7 +2,7 @@ import React from 'react';
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
const NameList = () => { const NameList = () => {
const names = ['TicTacToe','TodoList']; const names = ['TicTacToe','TodoList','FoodOrderer'];
return ( return (
<div className="min-h-screen bg-gray-100 flex justify-center items-center p-4"> <div className="min-h-screen bg-gray-100 flex justify-center items-center p-4">

64
src/FoodOrderer.tsx Normal file
View file

@ -0,0 +1,64 @@
import React, { useState } from "react";
interface ShopItem {
name: string,
need: number, // 需求数量
provide: number, // 提供的数量
imageUrl: string
}
const shopItems: ShopItem[] = [
{
name: "Apple",
need: 10,
provide: 5,
imageUrl: "https://example.com/images/apple.png"
},
{
name: "Orange",
need: 8,
provide: 10,
imageUrl: "https://example.com/images/orange.png"
},
{
name: "Milk",
need: 15,
provide: 20,
imageUrl: "https://example.com/images/milk.png"
},
{
name: "Bread",
need: 12,
provide: 6,
imageUrl: "https://example.com/images/bread.png"
}
];
function FoodList({list,setList}:{
list: ShopItem[],
setList: React.Dispatch<React.SetStateAction<ShopItem[]>>
}) {
return(
<div>
{list.map((item) =>
<div className="flex">
</div>
)}
</div>
)}
const FoodOrderer = () => {
const [items,setItems] = useState<ShopItem[]>(shopItems)
return (
<>
<FoodList list={items} setList={setItems} />
</>
)
}
export default FoodOrderer

View file

@ -5,6 +5,7 @@ import "./styles.css";
import TicTacToe from "./TicTacToe"; import TicTacToe from "./TicTacToe";
import TodoList from "./TodoList"; import TodoList from "./TodoList";
import NameList from "./App"; import NameList from "./App";
import FoodOrderer from "./FoodOrderer";
import { BrowserRouter, Routes, Route } from "react-router-dom"; import { BrowserRouter, Routes, Route } from "react-router-dom";
const root = createRoot(document.getElementById("root")); const root = createRoot(document.getElementById("root"));
@ -20,6 +21,7 @@ root.render(
<Route path="/" element={<NameList />} /> <Route path="/" element={<NameList />} />
<Route path="/TicTacToe" element={<TicTacToe />} /> <Route path="/TicTacToe" element={<TicTacToe />} />
<Route path="/TodoList" element={<TodoList />} /> <Route path="/TodoList" element={<TodoList />} />
<Route path="/FoodOrderer" element={<FoodOrderer />} />
</Routes> </Routes>
</BrowserRouter> </BrowserRouter>
</StrictMode> </StrictMode>