芝麻web文件管理V1.00
编辑当前文件:/home/qrafawbu/reginaeigbe.com/folder/admin/tmp/resources/js/Admin/Pages/Posts/Index.jsx
import AdminLayouts from "@/Admin/Layouts/AdminLayouts"; import { Head, Link } from "@inertiajs/react"; import { newspaperOutline, search } from "ionicons/icons"; import { IonIcon } from "@ionic/react"; import { trashOutline, createOutline, eyeOutline } from "ionicons/icons"; import moment from "moment"; import { useState } from "react"; import { router } from "@inertiajs/react"; import ThSortable from "@/Admin/Components/Table/ThSortable"; import DropDownButton from "@/Admin/Components/Button/DropDownButton"; import { showAlert } from "@/Admin/Utils/SweetAlert.js"; import DeleteButton from "@/Admin/Components/Button/DeleteButton"; import hasPermission from "@/Admin/Utils/hasPermission"; export default function AllPosts({ posts, sort, categories, filter }) { const [searchQuery, setSearchQuery] = useState(""); const [selectedOption, setSelectedOption] = useState("Bulk Action"); const [isMarkAll, setIsMarkAll] = useState(false); const [markItems, setMarkItems] = useState([]); const [selectedStatus, setSelectedStatus] = useState(filter.status); const [selectedCategory, setSelectedCategory] = useState(filter.category); // handle search sort const getResults = (search) => { router.get( route("admin.posts.index", { search: search ?? setSearchQuery, sort: sort, filter: { status: selectedStatus, category: selectedCategory }, }), {}, { preserveState: true } ); }; // mark all const markAll = () => { if (isMarkAll) { setMarkItems([]); setIsMarkAll(false); } else { const items = posts.data.map((post) => post.id); setMarkItems(items); setIsMarkAll(true); } }; // handle mark unmark const handleMark = (postId) => { const existsMark = markItems.some((item) => item === postId); if (existsMark) { const removeItem = markItems.filter((item) => item !== postId); setMarkItems(removeItem); } else { const addedItem = [...markItems, postId]; setMarkItems(addedItem); } }; // handle bulk action const handleBulkAction = () => { let confirmMessage = ""; let action = ""; if (selectedOption === "Delete") { confirmMessage = "You want to delete selected posts?"; action = "admin.posts.bulk.delete"; } else if (selectedOption === "Publish") { confirmMessage = "You want to publish selected posts?"; action = "admin.posts.bulk.publish"; } else if (selectedOption === "UnPublish") { confirmMessage = "You want to unpublish selected posts?"; action = "admin.posts.bulk.unpublish"; } setIsMarkAll([]); showAlert("Are you sure?", confirmMessage, selectedOption + "!", () => { router.post(route(action, { ids: markItems.join(",") })); }); }; // handle post status toggle const handlePostStatusToggle = (postId) => { router.post(route("admin.posts.status.toggle", { id: postId })); }; return ( <>
All Posts
Posts
setSelectedOption( "Publish" ) } className={`dropdown-item ${ selectedOption === "Publish" ? "active" : "" }`} href="#" > Publish
setSelectedOption( "UnPublish" ) } className={`dropdown-item ${ selectedOption === "UnPublish" ? "active" : "" }`} href="#" > UnPublish
setSelectedOption( "Delete" ) } className={`dropdown-item ${ selectedOption === "Delete" ? "active" : "" }`} href="#" > Delete
handleBulkAction() } className="btn btn-success btn-sm" > Apply
setSelectedStatus( "All Status" ) } className={`dropdown-item ${ selectedStatus === "All Status" ? "active" : "" }`} href="#" > All Status
setSelectedStatus( "Published" ) } className={`dropdown-item ${ selectedStatus === "Published" ? "active" : "" }`} href="#" > Published
setSelectedStatus( "UnPublished" ) } className={`dropdown-item ${ selectedStatus === "UnPublished" ? "active" : "" }`} href="#" > UnPublished
setSelectedCategory( "All Categories" ) } className={`dropdown-item ${ selectedCategory === "All Categories" ? "active" : "" }`} href="#" > All Category
{categories.map( (category) => (
setSelectedCategory( category.title ) } className={`dropdown-item ${ selectedCategory === category.title ? "active" : "" }`} href="#" > { category.title }
) )}
getResults(searchQuery) } className="btn btn-success btn-sm" > Filter
{ setSearchQuery( e.target.value ); getResults( e.target.value ); }} />
{hasPermission("posts.create") && (
+
{" "} Create New )}
markAll() } style={{ width: "1%" }} >
getResults( searchQuery ) } column="title" > Title
getResults( searchQuery ) } column="published_by" > Published By
getResults( searchQuery ) } column="category" > Categories
getResults( searchQuery ) } column="comment_count" > Comments
getResults( searchQuery ) } column="created_at" > Date
{hasPermission( "posts.edit" ) && (
getResults( searchQuery ) } column="status" > Status
)}
Action
{posts.data.map( (post, index) => (
handleMark( post.id ) } >
item === post.id ) && "active" }`} />
{post.title}
{ post.user_name }
{ post.category_name }
{ post.comment_count }
{moment( post.created_at ).format("ll")}
{hasPermission( "posts.edit" ) && (
handlePostStatusToggle( post.id ) } >
)}
{hasPermission( "posts.edit" ) && (
)} {hasPermission( "posts.show" ) && (
)} {hasPermission( "posts.delete" ) && (
)}
) )}
{!posts.data.length && (
No Posts found!
)}
{/* .yoo-card */} {posts.total > 1 && (
{posts.links.map((link, index) => (
))}
)}
> ); }