This commit is contained in:
2025-08-17 17:04:27 -04:00
parent f9f23f2d3f
commit 2eed0d9021
72 changed files with 2713 additions and 100 deletions

View File

@@ -0,0 +1,134 @@
package document
import (
"fmt"
g "maragu.dev/gomponents"
h "maragu.dev/gomponents/html"
"reichard.io/antholume/pkg/utils"
"reichard.io/antholume/web/assets"
"reichard.io/antholume/web/components/ui"
"reichard.io/antholume/web/models"
)
func Actions(d models.Document) g.Node {
return h.Div(
h.Class("flex flex-col float-left gap-2 w-44 md:w-60 lg:w-80 mr-4 relative"),
// Cover
ui.AnchoredPopover(
h.Img(
h.Class("rounded object-fill w-full"),
h.Src(fmt.Sprintf("/documents/%s/cover", d.ID)),
),
editCoverPopover(d.ID),
),
// Read
ui.LinkButton(g.Text("Read"), fmt.Sprintf("/reader#id=%s&type=REMOTE", d.ID)),
// Actions
h.Div(
h.Class("flex flex-col justify-between z-20 gap-2 relative"),
h.Div(
h.Class("flex grow align-center justify-between my-auto text-gray-500 dark:text-gray-500"),
ui.AnchoredPopover(
ui.SpanButton(assets.Icon("delete", 28), ui.ButtonConfig{Variant: ui.ButtonVariantGhost}),
deletePopover(d.ID),
),
ui.LinkButton(
assets.Icon("activity", 28),
fmt.Sprintf("../activity?document=%s", d.ID),
ui.ButtonConfig{Variant: ui.ButtonVariantGhost},
),
ui.AnchoredPopover(
ui.SpanButton(assets.Icon("search", 28), ui.ButtonConfig{Variant: ui.ButtonVariantGhost}),
searchPopover(d),
),
ui.LinkButton(
assets.Icon("download", 28),
fmt.Sprintf("./%s/file", d.ID),
ui.ButtonConfig{
Variant: ui.ButtonVariantGhost,
Disabled: !d.HasFile,
},
),
),
),
)
}
func editCoverPopover(docID string) g.Node {
return h.Div(
h.Class("flex flex-col gap-2"),
h.Form(
h.Class("flex flex-col gap-2 w-[19rem] text-black dark:text-white text-sm"),
h.Method("POST"),
g.Attr("enctype", "multipart/form-data"),
h.Action(fmt.Sprintf("./%s/edit", docID)),
h.Input(h.Type("file"), h.ID("cover_file"), h.Name("cover_file")),
ui.FormButton(g.Text("Upload Cover"), ""),
),
h.Form(
h.Class("flex flex-col gap-2 w-[19rem] text-black dark:text-white text-sm"),
h.Method("POST"),
h.Action(fmt.Sprintf("./%s/edit", docID)),
h.Input(
h.ID("remove_cover"),
h.Name("remove_cover"),
h.Class("hidden"),
h.Type("checkbox"),
h.Checked(),
),
ui.FormButton(g.Text("Remove Cover"), ""),
),
)
}
func deletePopover(id string) g.Node {
return h.Form(
h.Class("text-black dark:text-white text-sm w-24"),
h.Method("POST"),
h.Action(fmt.Sprintf("./%s/delete", id)),
ui.FormButton(g.Text("Delete"), ""),
)
}
func searchPopover(d models.Document) g.Node {
return h.Form(
h.Method("POST"),
h.Action(fmt.Sprintf("./%s/identify", d.ID)),
h.Class("flex flex-col gap-2 text-black dark:text-white text-sm"),
h.Input(
h.ID("title"),
h.Name("title"),
h.Class("p-2 bg-gray-300 text-black dark:bg-gray-700 dark:text-white"),
h.Type("text"),
h.Placeholder("Title"),
h.Value(d.Title),
),
h.Input(
h.ID("author"),
h.Name("author"),
h.Class("p-2 bg-gray-300 text-black dark:bg-gray-700 dark:text-white"),
h.Type("text"),
h.Placeholder("Author"),
h.Value(d.Author),
),
h.Input(
h.ID("isbn"),
h.Name("isbn"),
h.Class("p-2 bg-gray-300 text-black dark:bg-gray-700 dark:text-white"),
h.Type("text"),
h.Placeholder("ISBN 10 / ISBN 13"),
h.Value(utils.FirstNonZero(d.ISBN13, d.ISBN10)),
),
ui.FormButton(g.Text("Identify"), ""),
)
}

View File

@@ -0,0 +1,54 @@
package document
import (
"fmt"
g "maragu.dev/gomponents"
h "maragu.dev/gomponents/html"
"reichard.io/antholume/pkg/formatters"
"reichard.io/antholume/web/assets"
"reichard.io/antholume/web/components/ui"
"reichard.io/antholume/web/models"
)
func Card(d models.Document) g.Node {
return h.Div(
h.Class("w-full relative"),
h.Div(
h.Class("flex gap-4 w-full h-full p-4 shadow-lg bg-white dark:bg-gray-700 rounded"),
h.Div(
h.Class("min-w-fit my-auto h-48 relative"),
h.A(
h.Href("./documents/"+d.ID),
h.Img(
h.Src("./documents/"+d.ID+"/cover"),
h.Class("rounded object-cover h-full"),
),
),
),
h.Div(
h.Class("flex flex-col justify-around dark:text-white w-full text-sm"),
ui.KeyValue(g.Text("Title"), g.Text(d.Title)),
ui.KeyValue(g.Text("Author"), g.Text(d.Author)),
ui.KeyValue(g.Text("Progress"), g.Text(fmt.Sprintf("%.2f%%", d.Percentage))),
ui.KeyValue(g.Text("Time Read"), g.Text(formatters.FormatDuration(d.TotalTimeRead))),
),
),
h.Div(
h.Class("absolute flex flex-col gap-2 right-4 bottom-4 text-gray-500 dark:text-gray-400"),
ui.LinkButton(
assets.Icon("activity", 24),
"./activity?document="+d.ID,
ui.ButtonConfig{Variant: ui.ButtonVariantGhost},
),
ui.LinkButton(
assets.Icon("download", 24),
"./documents/"+d.ID+"/file",
ui.ButtonConfig{
Variant: ui.ButtonVariantGhost,
Disabled: !d.HasFile,
},
),
),
)
}

View File

@@ -0,0 +1,104 @@
package document
import (
"fmt"
g "maragu.dev/gomponents"
h "maragu.dev/gomponents/html"
"reichard.io/antholume/pkg/utils"
"reichard.io/antholume/web/components/ui"
"reichard.io/antholume/web/models"
)
func IdentifyPopover(docID string, m *models.DocumentMetadata) g.Node {
if m == nil {
return nil
}
if m.Error != nil {
return ui.Popover(h.Div(
h.Class("flex flex-col gap-2"),
h.H3(
h.Class("text-lg font-bold text-center"),
g.Text("Error"),
),
h.Div(
h.Class("bg-gray-100 dark:bg-gray-900 p-2"),
h.P(g.Text(*m.Error)),
),
ui.LinkButton(g.Text("Back to Document"), fmt.Sprintf("/documents/%s", docID)),
))
}
return ui.Popover(h.Div(
h.Class("flex flex-col gap-2"),
h.H3(
h.Class("text-lg font-bold text-center"),
g.Text("Metadata Results"),
),
h.Form(
h.ID("metadata-save"),
h.Method("POST"),
h.Action(fmt.Sprintf("/documents/%s/edit", docID)),
h.Class("text-black dark:text-white border-b dark:border-black"),
h.Dl(
h.Div(
h.Class("p-3 bg-gray-100 dark:bg-gray-900 grid grid-cols-3 gap-4 sm:px-6"),
h.Dt(h.Class("my-auto font-medium text-gray-500"), g.Text("Cover")),
h.Dd(
h.Class("mt-1 text-sm sm:mt-0 sm:col-span-2"),
h.Img(
h.Class("rounded object-fill h-32"),
h.Src(fmt.Sprintf("https://books.google.com/books/content/images/frontcover/%s?fife=w480-h690", m.SourceID)),
),
),
),
h.Div(
h.Class("p-3 bg-white dark:bg-gray-800 grid grid-cols-3 gap-4 sm:px-6"),
h.Dt(h.Class("my-auto font-medium text-gray-500"), g.Text("Title")),
h.Dd(h.Class("mt-1 text-sm sm:mt-0 sm:col-span-2"), g.Text(utils.FirstNonZero(m.Title, "N/A"))),
),
h.Div(
h.Class("p-3 bg-gray-100 dark:bg-gray-900 grid grid-cols-3 gap-4 sm:px-6"),
h.Dt(h.Class("my-auto font-medium text-gray-500"), g.Text("Author")),
h.Dd(h.Class("mt-1 text-sm sm:mt-0 sm:col-span-2"), g.Text(utils.FirstNonZero(m.Author, "N/A"))),
),
h.Div(
h.Class("p-3 bg-white dark:bg-gray-800 grid grid-cols-3 gap-4 sm:px-6"),
h.Dt(h.Class("my-auto font-medium text-gray-500"), g.Text("ISBN 10")),
h.Dd(h.Class("mt-1 text-sm sm:mt-0 sm:col-span-2"), g.Text(utils.FirstNonZero(m.ISBN10, "N/A"))),
),
h.Div(
h.Class("p-3 bg-gray-100 dark:bg-gray-900 grid grid-cols-3 gap-4 sm:px-6"),
h.Dt(h.Class("my-auto font-medium text-gray-500"), g.Text("ISBN 13")),
h.Dd(h.Class("mt-1 text-sm sm:mt-0 sm:col-span-2"), g.Text(utils.FirstNonZero(m.ISBN13, "N/A"))),
),
h.Div(
h.Class("p-3 bg-white dark:bg-gray-800 sm:grid sm:grid-cols-3 sm:gap-4 px-6"),
h.Dt(h.Class("my-auto font-medium text-gray-500"), g.Text("Description")),
h.Dd(
h.Class("max-h-[10em] overflow-scroll mt-1 sm:mt-0 sm:col-span-2"),
g.Text(utils.FirstNonZero(m.Description, "N/A")),
),
),
),
h.Div(
h.Class("hidden"),
h.Input(h.Type("text"), h.ID("title"), h.Name("title"), h.Value(m.Title)),
h.Input(h.Type("text"), h.ID("author"), h.Name("author"), h.Value(m.Author)),
h.Input(h.Type("text"), h.ID("description"), h.Name("description"), h.Value(m.Description)),
h.Input(h.Type("text"), h.ID("isbn_10"), h.Name("isbn_10"), h.Value(m.ISBN10)),
h.Input(h.Type("text"), h.ID("isbn_13"), h.Name("isbn_13"), h.Value(m.ISBN13)),
h.Input(h.Type("text"), h.ID("cover_gbid"), h.Name("cover_gbid"), h.Value(m.SourceID)),
),
),
h.Div(
h.Class("flex justify-end"),
h.Div(
h.Class("flex gap-4 w-48"),
ui.LinkButton(g.Text("Cancel"), fmt.Sprintf("/documents/%s", docID)),
ui.FormButton(g.Text("Save"), "metadata-save"),
),
),
))
}