171 lines
4.4 KiB
Plaintext
171 lines
4.4 KiB
Plaintext
package pages
|
|
|
|
import (
|
|
"fmt"
|
|
"git.myrkvi.com/myrkvi/bin/models"
|
|
"git.myrkvi.com/myrkvi/bin/views/components"
|
|
"git.myrkvi.com/myrkvi/bin/views/partials"
|
|
)
|
|
|
|
templ page(inner templ.Component, menu []models.MenuItem, currentMenu int, title string) {
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
<script src="/static/htmx.min.js"></script>
|
|
<script src="/static/_hyperscript.min.js"></script>
|
|
<link rel="stylesheet" href="/static/tailwind.css" />
|
|
if title == "" {
|
|
<title id="title">bin</title>
|
|
} else {
|
|
<title id="title">{ title } - bin</title>
|
|
}
|
|
</head>
|
|
<body class="mt-4 sm:mt-12 mx-16 xl:mx-72 lg:mx-64 md:mx-32 sm:mx-24 bg-amber-50">
|
|
<header class="flex flex-row justify-between my-16">
|
|
<h1 class="text-5xl">bin</h1>
|
|
@components.NavMenu(menu, currentMenu, false)
|
|
</header>
|
|
<main id="main-content">
|
|
{! inner }
|
|
</main>
|
|
|
|
<div class="fixed left-0 bottom-1 flex flex-row justify-center w-screen pointer-events-none">
|
|
<div id="toast" class="w-fit pointer-events-auto">
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|
|
}
|
|
|
|
templ IndexFull() {
|
|
@page(
|
|
IndexPartial(),
|
|
models.DefaultMenu,
|
|
0,
|
|
"",
|
|
)
|
|
}
|
|
|
|
|
|
templ IndexPartial() {
|
|
<h2 class="text-xl">Welcome to <i>bin</i></h2>
|
|
<p>bin is a simple paste bin.</p>
|
|
<br />
|
|
@components.BoostButton("new", "/new")
|
|
|
|
}
|
|
|
|
templ NewFull(wantsText bool) {
|
|
@page(
|
|
NewPartial(wantsText),
|
|
models.DefaultMenu,
|
|
1,
|
|
"upload",
|
|
)
|
|
}
|
|
|
|
const placeholderCode string = `#include <stdio.h>
|
|
|
|
int main(int argc, char *argv[]) {
|
|
printf("Hello, world!\n");
|
|
|
|
return 0;
|
|
}`
|
|
|
|
templ NewPartial(wantsText bool) {
|
|
<h2 class="text-xl">submit a new file</h2>
|
|
<form
|
|
hx-post="/new"
|
|
hx-encoding="multipart/form-data"
|
|
method="POST"
|
|
hx-target="#main-content"
|
|
>
|
|
<div class="my-2 grid grid-cols-1 sm:grid-cols-3 md:grid-cols-5 gap-4 max-w-sm md:max-w-lg">
|
|
<label class="col-span-1" for="name">
|
|
file name:
|
|
</label>
|
|
<input
|
|
class="col-span-2 md:col-span-4 justify-self-start
|
|
outline-2 bg-amber-50
|
|
hover:outline-slate-400 hover:outline-dotted
|
|
focus:outline-slate-600 focus:outline-dashed
|
|
active:outline-green-600"
|
|
type="text"
|
|
name="name"
|
|
id="name"
|
|
placeholder="foo.txt"
|
|
_="on change set #description's @placeholder to `some stuff about ${my value} ...`"
|
|
/>
|
|
<label for="lang" class="col-span-1">language:</label>
|
|
<div class="col-span-2 md:col-span-4">@components.ChooseSyntax("lang")</div>
|
|
<label class="col-span-1" for="description">description:</label>
|
|
<textarea
|
|
class="col-span-2 md:col-span-4 resize-none hover:resize justify-self-start
|
|
w-full outline-2 bg-amber-50
|
|
hover:outline-slate-400 hover:outline-dotted
|
|
focus:outline-slate-600 focus:outline-dashed
|
|
active:outline-green-600"
|
|
name="description"
|
|
id="description"
|
|
rows="3"
|
|
placeholder="some stuff about foo.txt ..."
|
|
/>
|
|
</div>
|
|
if wantsText {
|
|
@partials.NewTextSubmit()
|
|
<input type="text" name="wantsText" hidden value="true" />
|
|
} else {
|
|
@partials.NewFileUpload()
|
|
}
|
|
@components.SubmitFormButton("submit")
|
|
</form>
|
|
}
|
|
|
|
templ BinFull(file models.File) {
|
|
@page(
|
|
BinPartial(file),
|
|
models.DefaultMenu,
|
|
-1,
|
|
file.Filename,
|
|
)
|
|
}
|
|
|
|
templ BinPartial(file models.File) {
|
|
<div>
|
|
<h1 class="text-xl my-2 inline-block">{ file.Filename }
|
|
if file.Language != "" {
|
|
<sup class="text-base mx-4">({ file.Language })</sup>
|
|
}
|
|
</h1>
|
|
<p class="italic mx-1 my-2">{ file.Description }</p>
|
|
<pre class="my-4">{ file.Data }</pre>
|
|
<div class="relative h-full">
|
|
<form
|
|
class="absolute -bottom-32"
|
|
hx-post={ "/b/" + file.PageKey + "/delete" }
|
|
hx-confirm="Are you sure you want to delete this?"
|
|
hx-target="#main-content"
|
|
>
|
|
<input
|
|
name="adminKey"
|
|
id="adminKey"
|
|
type="text"
|
|
class="mr-4 w-24 bg-amber-50
|
|
hover:outline-slate-400 hover:outline-dotted
|
|
focus:outline-slate-600 focus:outline-dashed
|
|
active:outline-green-600"
|
|
placeholder="deletion key"
|
|
value={ file.AdminKey }
|
|
/>
|
|
@components.SubmitFormButton("delete")
|
|
if file.AdminKey != "" {
|
|
<a class="text-blue-500 mx-4" href={ templ.URL(fmt.Sprintf("/b/%s?delcode=%s", file.PageKey, file.AdminKey))}><sup>permalink with deletion key</sup></a>
|
|
}
|
|
<p class="opacity-0 my-1 max-w-md" _="init if #adminKey's value is not '' log then show me with *opacity">
|
|
this is your deletion key! <br /> you will need to store it if you want to delete the file.
|
|
</p>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
} |