添加(FooterMenu): 添加了点击事件处理程序以提交POST请求

新增(Category): 新增了CategoryAction文件来处理创建新分类的数据库操作
♻️ 重构(CategoryLoader): 优化了获取分类数据的SQL查询语句
🚀 部署(router): 添加了CategoryAction到路由配置中
This commit is contained in:
yuruo
2024-06-20 08:52:00 +08:00
parent 1312385478
commit 6e5f6f3228
4 changed files with 15 additions and 2 deletions

View File

@@ -1,10 +1,14 @@
import { Add, DatabaseConfig } from '@icon-park/react'
import { useSubmit } from 'react-router-dom'
export const FooterMenu = () => {
const submit = useSubmit()
return (
<>
<div className="nav">
<Add theme="outline" size="20" fill="#333"/>
<Add theme="outline" size="20" fill="#333" onClick={(_e)=>
submit(null, {method:'POST'})
}/>
<DatabaseConfig theme="outline" size="20" fill="#333"/>
</div>
</>

View File

@@ -0,0 +1,7 @@
export default async({request}) =>{
await window.api.sql(
"insert into categories (name, created_at) values('未命名', datetime())",
"create",
)
return {}
}

View File

@@ -1,3 +1,3 @@
export default () => {
return window.api.sql("SELECT * FROM categories", "findAll")
return window.api.sql("SELECT * FROM categories order by id desc", "findAll")
}

View File

@@ -10,6 +10,7 @@ import { Content } from "@renderer/pages/Content/Content";
import ContentAction from "@renderer/pages/Content/ContentAction";
import { Welcome } from "@renderer/pages/Welcome";
import ContentListAction from "@renderer/pages/ContentList/ContentListAction";
import CategoryAction from "@renderer/pages/Category/CategoryAction";
const router = createHashRouter([
{
@@ -25,6 +26,7 @@ const router = createHashRouter([
// 界面第一次打开时,默认显示的页面
element: <Category />,
loader: CategoryLoader,
action: CategoryAction,
children: [
{
path: "contentList/:cid?",