feat: Add proper success page

This commit is contained in:
overflowerror 2023-12-02 22:13:02 +01:00
parent 803c54e4d4
commit 5473554422
6 changed files with 38 additions and 9 deletions

View file

@ -3,5 +3,9 @@
return function (array &$context) {
$data = [];
if (key_exists("formonly", $_GET)) {
require(ROOT . "/templates/pages/components/url-form.php");
} else {
require(ROOT . "/templates/pages/homepage.php");
}
};

View file

@ -22,9 +22,10 @@ return function (array &$context) {
if (!$url) {
setStatusCode(400);
echo json_encode(
errorResponse("URL missing", "Please provide a URL.")
);
$data = [
"error" => "Something went wrong. Please try again later."
];
require(ROOT . "/templates/pages/components/url-form.php");
return;
}
@ -49,5 +50,9 @@ return function (array &$context) {
$accessKey
));
echo json_encode($result);
$data = [
"url" => "https://drnk.me/$slug",
"accessKey" => $accessKey,
];
require(ROOT . "/templates/pages/components/creation-successful.php");
};

View file

@ -58,3 +58,7 @@ html {
width: 100%;
margin-top: 1vw;
}
.result {
font-size: 2vw;
}

View file

@ -0,0 +1,5 @@
<div class="result">
<a href="<?php echo $data["url"] ?? ""; ?>" target="_blank"><?php echo $data["url"] ?? ""; ?></a>
</div>
<!-- <?php echo $data["accessKey"] ?? ""; ?> -->
Click <a hx-get="/?formonly" hx-swap="innerHTML" hx-target=".center-panel" href="/">here</a> to create a new link.

View file

@ -0,0 +1,14 @@
<?php
if ($data["error"] ?? false) {
?>
<div class="error">
<?php echo $data["error"]; ?>
</div>
<?php
}
?>
<form action="/manage" method="POST" hx-post="/manage" hx-swap="innerHTML" hx-target=".center-panel">
<input type="text" name="url" placeholder="<?php echo $data["url"] ?? "URL" ?>">
<input type="submit" value="Submit">
</form>

View file

@ -10,10 +10,7 @@ require(__DIR__ . "/../layout/top.php");
<img class="bottle" src="/static/img/bottle.png" alt="picture of a vile with a tag 'Drnk Me'" />
<div class="center-panel">
<form action="/manage" method="POST">
<input type="text" name="url" placeholder="<?php echo $data["url"] ?? "URL" ?>">
<input type="submit" value="Submit">
</form>
<?php require(__DIR__ . "/components/url-form.php"); ?>
</div>
<?php