-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
871de49
commit 80568be
Showing
13 changed files
with
295 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
:set prompt "[\ESC[38;2;255;100;0mHomepage dev\ESC[0m] > " | ||
:seti -fdiagnostics-color=auto | ||
:set prompt "[\ESC[38;2;255;100;0mHomepage dev\ESC[0m] > " |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module Helpers.Tables where | ||
|
||
import Data.Aeson | ||
import Data.ByteString.Lazy (fromStrict) | ||
import Control.Applicative | ||
|
||
import Database.SQLite.Simple | ||
import Database.SQLite.Simple.FromRow | ||
|
||
data GuestbookEntry = GuestbookEntry { | ||
name :: String, | ||
content :: String, | ||
parent :: Int | ||
} | EmptyGuestbook | ||
deriving Show | ||
|
||
instance FromJSON GuestbookEntry where | ||
parseJSON (Object v) = GuestbookEntry <$> | ||
v .: "name" <*> | ||
v .: "content" <*> | ||
v .: "parentId" | ||
parseJSON _ = empty | ||
|
||
instance ToJSON GuestbookEntry where | ||
toJSON (GuestbookEntry name content parent) = object ["name" .= name, "content" .= content, "parent" .= parent] | ||
|
||
instance FromRow GuestbookEntry where | ||
fromRow = GuestbookEntry <$> field <*> field <*> field |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
module Pages.Guestbook.Guestbook where | ||
|
||
import IHP.HSX.QQ (hsx) | ||
import Text.Blaze.Html (Html) | ||
|
||
import Helpers.Database (getGuestbook) | ||
import Helpers.Section (section) | ||
|
||
import Data.List (filter) | ||
|
||
import Data.Time.Format.ISO8601 | ||
import Data.Time.Format | ||
import Data.Time.Clock.POSIX | ||
|
||
type Guestbook = [(Int, Int, String, String, Int)] | ||
|
||
toPosix :: Int -> POSIXTime | ||
toPosix n = read ((show n) ++ "s") :: POSIXTime | ||
|
||
prettify_guestbook :: Guestbook -> Html | ||
prettify_guestbook ((id, timestamp, name, content, parent):xs) = mconcat [section [hsx| | ||
<h3>{name} said: </h3> | ||
<div style="background-color: #111111; border: 1px solid #111111; border-radius: 5px;"> | ||
id: <span style="color: #ff0000">{id}</span> | ||
parent: <span style="color: #ff0000">{parent}</span> | ||
timestamp: <span style="color: #ff0000">{formatTime defaultTimeLocale "%c" $ posixSecondsToUTCTime (toPosix timestamp)}</span> | ||
<br><br> | ||
{content} | ||
</div> | ||
{prettify_guestbook $ children} | ||
{guestbook_input id True} | ||
<br><br> | ||
|], prettify_guestbook rest] | ||
where | ||
children :: Guestbook | ||
children = filter (\(_, _, _, _, childParent) -> childParent == id) xs | ||
rest :: Guestbook | ||
rest = filter (\(_, _, _, _, childParent) -> childParent /= id) xs | ||
prettify_guestbook [] = [hsx||] | ||
|
||
guestbook_input :: Int -> Bool -> Html | ||
guestbook_input parent False = [hsx| | ||
<textarea class="guestbook-text" id={"guestbook-text::"++show parent} type="text"></textarea> | ||
<br> | ||
Name: <input id={"guestbook-name::"++show parent} class="guestbook-name" type="text"> | ||
<button id={show parent} onclick="post(this.id)">Post</button> | ||
|] | ||
guestbook_input parent True = [hsx| | ||
<button id={show parent} onclick="guestbookToggleInput(this.id)">New reply</button> | ||
<br> | ||
<div style="display:none;" id={"guestbook-reply::"++show parent}> | ||
{guestbook_input parent False} | ||
</div> | ||
|] | ||
|
||
guestbook :: IO Html | ||
guestbook = do | ||
guestbook <- getGuestbook | ||
return [hsx| | ||
<script> | ||
function guestbookToggleInput(id) { | ||
var reply = document.getElementById("guestbook-reply::"+id) | ||
if(reply.style.display == "none") { | ||
reply.style.display = "unset" | ||
} | ||
else { | ||
reply.style.display = "none" | ||
} | ||
} | ||
function post(id) { | ||
var text = document.getElementById("guestbook-text::"+id).value | ||
var name = document.getElementById("guestbook-name::"+id).value | ||
console.log(id) | ||
fetch("/api/guestbook/add", { | ||
method:"POST", | ||
body: JSON.stringify({ | ||
name: name, | ||
content: text, | ||
parentId: Number(id) | ||
}) | ||
}).then(response => { | ||
if(response.status == 200){ | ||
window.location.reload() | ||
} | ||
}) | ||
} | ||
</script> | ||
<h1>Guestbook</h1> | ||
Write a message for me :)<br> | ||
{guestbook_input (-1) False} | ||
<hr> | ||
<h2>History</h2> | ||
{prettify_guestbook guestbook} | ||
|] | ||
|
Oops, something went wrong.