Feed no longer show replies

This commit is contained in:
LittleSheep 2024-02-14 18:48:02 +08:00
parent 1baffd4200
commit b0c9368530
3 changed files with 27 additions and 13 deletions

View File

@ -5,7 +5,6 @@ import "time"
type Post struct { type Post struct {
BaseModel BaseModel
// TODO Introduce thumbnail
Alias string `json:"alias" gorm:"uniqueIndex"` Alias string `json:"alias" gorm:"uniqueIndex"`
Title string `json:"title"` Title string `json:"title"`
Content string `json:"content"` Content string `json:"content"`

View File

@ -77,11 +77,14 @@ func listPost(c *fiber.Ctx) error {
if len(c.Query("category")) > 0 { if len(c.Query("category")) > 0 {
tx = services.FilterPostWithCategory(tx, c.Query("category")) tx = services.FilterPostWithCategory(tx, c.Query("category"))
} }
if len(c.Query("tag")) > 0 { if len(c.Query("tag")) > 0 {
tx = services.FilterPostWithTag(tx, c.Query("tag")) tx = services.FilterPostWithTag(tx, c.Query("tag"))
} }
if !c.QueryBool("reply", true) {
tx = tx.Where("reply_id IS NULL")
}
var count int64 var count int64
if err := tx. if err := tx.
Model(&models.Post{}). Model(&models.Post{}).

View File

@ -12,10 +12,14 @@ export default function DashboardPage() {
async function readPosts(pn?: number) { async function readPosts(pn?: number) {
if (pn) setPage(pn); if (pn) setPage(pn);
const res = await fetch("/api/posts?" + new URLSearchParams({ const res = await fetch(
"/api/posts?" +
new URLSearchParams({
take: (10).toString(), take: (10).toString(),
offset: ((page() - 1) * 10).toString() offset: ((page() - 1) * 10).toString(),
})); reply: false.toString(),
}),
);
if (res.status !== 200) { if (res.status !== 200) {
setError(await res.text()); setError(await res.text());
} else { } else {
@ -28,7 +32,7 @@ export default function DashboardPage() {
const meta: { [id: string]: any } = { const meta: { [id: string]: any } = {
reposting: null, reposting: null,
replying: null, replying: null,
editing: null editing: null,
}; };
meta[field] = data; meta[field] = data;
setPublishMeta(meta); setPublishMeta(meta);
@ -39,7 +43,7 @@ export default function DashboardPage() {
const [publishMeta, setPublishMeta] = createStore<any>({ const [publishMeta, setPublishMeta] = createStore<any>({
replying: null, replying: null,
reposting: null, reposting: null,
editing: null editing: null,
}); });
return ( return (
@ -47,10 +51,18 @@ export default function DashboardPage() {
<div id="alerts"> <div id="alerts">
<Show when={error()}> <Show when={error()}>
<div role="alert" class="alert alert-error"> <div role="alert" class="alert alert-error">
<svg xmlns="http://www.w3.org/2000/svg" class="stroke-current shrink-0 h-6 w-6" fill="none" <svg
viewBox="0 0 24 24"> xmlns="http://www.w3.org/2000/svg"
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" class="stroke-current shrink-0 h-6 w-6"
d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z" /> fill="none"
viewBox="0 0 24 24"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z"
/>
</svg> </svg>
<span class="capitalize">{error()}</span> <span class="capitalize">{error()}</span>
</div> </div>