Initial stab at a reply feature.

master
Zed A. Shaw 3 days ago
parent d49d762d73
commit c225162d6c
  1. 14
      api/message.go
  2. 8
      pages/index.html
  3. 12
      views/feed.html
  4. 7
      views/post/new.html

@ -24,9 +24,17 @@ func PostApiMessage(c *fiber.Ctx) error {
message, err := ReceivePost[data.Message](c) message, err := ReceivePost[data.Message](c)
if err != nil { return IfErrNil(err, c) } if err != nil { return IfErrNil(err, c) }
sql, args, err := sq.Insert("message"). build := sq.Insert("message")
Columns("text", "user_id").
Values(message.Text, 1).ToSql() if c.Params("replying_to") == "" {
build = build.Columns("text", "user_id").
Values(message.Text, 1)
} else {
build = build.Columns("text", "user_id", "replying_to").
Values(message.Text, 1, c.Params("replying_to"))
}
sql, args, err := build.ToSql()
err = data.Exec(err, sql, args...) err = data.Exec(err, sql, args...)
if err != nil { return IfErrNil(err, c) } if err != nil { return IfErrNil(err, c) }

@ -5,13 +5,7 @@
<div class="p-1" x-data="feed"> <div class="p-1" x-data="feed">
<bar class="justify-evenly"> <bar class="justify-evenly">
<img src="/favicon.ico" /> <img src="/favicon.ico" />
<b>Notifications</b> <b>Your Feed</b>
<svg xmlns="http://www.w3.org/2000/svg"
width="2rem"
height="2rem"
viewBox="0 0 2rem 2rem">
<use href="/icons/settings.svg#settings" />
</svg>
</bar> </bar>
<template x-for="message in items"> <template x-for="message in items">

@ -1,11 +1,11 @@
{{define "post-action-bar"}} {{define "post-action-bar"}}
<bar class="!p-0 !pt-1 mt-4 bg-gray-800 justify-evenly rounded-full"> <bar class="!p-0 !pt-1 mt-4 bg-gray-800 justify-evenly rounded-full">
<svg xmlns="http://www.w3.org/2000/svg" <a x-bind:href="`/post/new/?replying_to=${message.id}`"><svg xmlns="http://www.w3.org/2000/svg"
width="2rem" width="2rem"
height="2rem" height="2rem"
viewBox="0 0 2rem 2rem"> viewBox="0 0 2rem 2rem">
<use href="/icons/reply.svg#img" /> <use href="/icons/reply.svg#img" />
</svg> </svg></a>
<svg xmlns="http://www.w3.org/2000/svg" <svg xmlns="http://www.w3.org/2000/svg"
width="2rem" width="2rem"
height="2rem" height="2rem"
@ -34,13 +34,7 @@
<div class="p-1" x-data="feed"> <div class="p-1" x-data="feed">
<bar class="justify-evenly"> <bar class="justify-evenly">
<img src="/favicon.ico" /> <img src="/favicon.ico" />
<b>Notifications</b> <b>Your Feed</b>
<svg xmlns="http://www.w3.org/2000/svg"
width="2rem"
height="2rem"
viewBox="0 0 2rem 2rem">
<use href="/icons/settings.svg#settings" />
</svg>
</bar> </bar>
<template x-for="message in items"> <template x-for="message in items">

@ -1,5 +1,6 @@
<block class="!gap-0 border-t-1 border-gray-600">
<form action="/api/message/new" method="POST"> <block class="!gap-0 border-t-1 border-gray-600" x-data="{replying_to: window.location.search}">
<form :action="`/api/message/new${replying_to}`" method="POST">
<bar class="justify-end"> <bar class="justify-end">
<button class="!p-1" type="button">Discard</button> <button class="!p-1" type="button">Discard</button>
<button class="!p-1" type="submit">Post</button> <button class="!p-1" type="submit">Post</button>
@ -8,7 +9,7 @@
<block class="!p-0 gap-2 mb-2"> <block class="!p-0 gap-2 mb-2">
<textarea name="text" class="border-1 border-gray-500" rows="10" placeholder="Type your message"></textarea> <textarea name="text" class="border-1 border-gray-500" rows="10" placeholder="Type your message"></textarea>
</block> </block>
</for> </form>
<bar class="!p-1 mt-2 bg-gray-400 justify-evenly rounded-full"> <bar class="!p-1 mt-2 bg-gray-400 justify-evenly rounded-full">
<img src="/icons/message-square.svg" /> <img src="/icons/message-square.svg" />

Loading…
Cancel
Save