mirror of
https://github.com/fergalmoran/malarkey.git
synced 2025-12-22 09:48:46 +00:00
Enough of this malarkey
This commit is contained in:
@@ -5,7 +5,7 @@ defmodule Malarkey.Timeline do
|
||||
|
||||
import Ecto.Query, warn: false
|
||||
|
||||
alias Malarkey.Accounts
|
||||
alias Malarkey.Timeline.PostUserLike
|
||||
alias Malarkey.Repo
|
||||
alias Malarkey.Timeline.Post
|
||||
|
||||
@@ -40,7 +40,7 @@ defmodule Malarkey.Timeline do
|
||||
post
|
||||
|> Post.changeset(attrs)
|
||||
|> Repo.update()
|
||||
|> broadcast(:post_created)
|
||||
|> broadcast(:post_updated)
|
||||
end
|
||||
|
||||
def delete_post(%Post{} = post) do
|
||||
@@ -52,12 +52,17 @@ defmodule Malarkey.Timeline do
|
||||
end
|
||||
|
||||
def add_like(user, post) do
|
||||
post
|
||||
|> Repo.preload(:liked_by)
|
||||
|> Repo.preload(:user)
|
||||
|> Post.changeset_add_like(user)
|
||||
|> Repo.update()
|
||||
|> broadcast(:post_created)
|
||||
if user in post.liked_by do
|
||||
Repo.delete_all(PostUserLike.user_post_like_query(user, post))
|
||||
|> broadcast(:post_updated)
|
||||
else
|
||||
post
|
||||
|> Repo.preload(:liked_by)
|
||||
|> Repo.preload(:user)
|
||||
|> Post.changeset_add_like(user)
|
||||
|> Repo.update()
|
||||
|> broadcast(:post_updated)
|
||||
end
|
||||
end
|
||||
|
||||
def add_repost(user, post) do
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
defmodule Malarkey.Timeline.PostUserLike do
|
||||
import Ecto.Query
|
||||
use Ecto.Schema
|
||||
alias Malarkey.Timeline.PostUserLike
|
||||
|
||||
@primary_key false
|
||||
schema "user_likes" do
|
||||
@@ -7,4 +9,8 @@ defmodule Malarkey.Timeline.PostUserLike do
|
||||
belongs_to :post, Malarkey.Timeline.Post, primary_key: true
|
||||
timestamps()
|
||||
end
|
||||
|
||||
def user_post_like_query(user, post) do
|
||||
from PostUserLike, where: [user_id: ^user.id, post_id: ^post.id]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -6,8 +6,6 @@ defmodule MalarkeyWeb.PostLive.Index do
|
||||
on_mount MalarkeyWeb.UserLiveAuth
|
||||
|
||||
@impl true
|
||||
@spec mount(any, any, Phoenix.LiveView.Socket.t()) ::
|
||||
{:ok, map, [{:temporary_assigns, [...]}, ...]}
|
||||
def mount(_params, _session, socket) do
|
||||
if connected?(socket), do: Timeline.subscribe()
|
||||
{:ok, assign(socket, :posts, list_posts()), temporary_assigns: [posts: []]}
|
||||
@@ -42,6 +40,13 @@ defmodule MalarkeyWeb.PostLive.Index do
|
||||
|> assign(:post, nil)
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_event("login", _id, socket) do
|
||||
{:noreply,
|
||||
socket
|
||||
|> push_redirect(to: "/users/log_in")}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_event("like", %{"id" => id}, socket) do
|
||||
post = Timeline.get_post!(id)
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
<.header>
|
||||
Timeline
|
||||
<%= if !!@current_user do %>
|
||||
<div id="user-greeting">Hi, <%= !!@current_user.fullname || "Sailor" %></div>
|
||||
<% else %>
|
||||
<div id="anonymous-greeting">Hello, Sailor!</div>
|
||||
<% end %>
|
||||
<:actions>
|
||||
<.link patch={(!!@current_user && ~p"/posts/new") || "/users/log_in"}>
|
||||
<button class="inline-flex items-center px-3 py-2 text-sm font-semibold leading-6 text-white rounded-lg bg-brand phx-submit-loading:opacity-75 hover:bg-zinc-700 active:text-white/80">
|
||||
@@ -11,13 +15,13 @@
|
||||
</.header>
|
||||
|
||||
<div id="posts" phx-update="prepend">
|
||||
<%= if !!@current_user do %>
|
||||
<h1 id="user-greeting">Hi, <%= !!@current_user.fullname %></h1>
|
||||
<% else %>
|
||||
<h1 id="anonymous-greeting">Hello, Sailor!</h1>
|
||||
<% end %>
|
||||
<%= for post <- @posts do %>
|
||||
<.live_component module={MalarkeyWeb.PostLive.PostComponent} id={post.id} , post={post} />
|
||||
<.live_component
|
||||
module={MalarkeyWeb.PostLive.PostComponent}
|
||||
id={post.id}
|
||||
post={post}
|
||||
user={@current_user}
|
||||
/>
|
||||
<% end %>
|
||||
</div>
|
||||
<.modal
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
defmodule MalarkeyWeb.PostLive.PostComponent do
|
||||
use MalarkeyWeb, :live_component
|
||||
alias Malarkey.Timeline
|
||||
alias Malarkey.Accounts
|
||||
|
||||
@impl true
|
||||
@spec render(any) :: Phoenix.LiveView.Rendered.t()
|
||||
@@ -8,10 +8,7 @@ defmodule MalarkeyWeb.PostLive.PostComponent do
|
||||
~H"""
|
||||
<div class="max-w-xl mx-auto my-6">
|
||||
<article class="flex flex-wrap items-start p-2 border-t border-b border-gray-400 cursor-pointer hover:bg-gray-100">
|
||||
<img
|
||||
src="https://joeschmoe.io/api/v1/random?q=#{@post.id}"
|
||||
class="w-12 h-12 mr-3 rounded-full"
|
||||
/>
|
||||
<img src="https://i.pravatar.cc/300?u=#{@post.id}" class="w-12 h-12 mr-3 rounded-full" />
|
||||
<div class="flex flex-wrap items-start justify-start flex-1">
|
||||
<div class="flex items-center flex-1">
|
||||
<div class="flex items-center flex-1">
|
||||
@@ -53,6 +50,7 @@ defmodule MalarkeyWeb.PostLive.PostComponent do
|
||||
|
||||
<div class="w-full">
|
||||
<p class="my-1"><%= @post.body %></p>
|
||||
<%!-- Item has embedded media --%>
|
||||
<%= if false do %>
|
||||
<div class="rounded-lg">
|
||||
<img
|
||||
@@ -74,14 +72,20 @@ defmodule MalarkeyWeb.PostLive.PostComponent do
|
||||
</div>
|
||||
|
||||
<div class="flex items-center mr-8 text-gray-600 hover:text-green-500">
|
||||
<.link phx-click={JS.push("repost", value: %{id: @post.id})}>
|
||||
<.link phx-click={
|
||||
(@user && JS.push("repost", value: %{id: @post.id})) ||
|
||||
JS.push("login")
|
||||
}>
|
||||
<%= Heroicons.icon("arrow-path-rounded-square", type: "outline", class: "w-5 h-5") %>
|
||||
</.link>
|
||||
<span class="ml-1"><%= length(@post.reposted_by) %></span>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center mr-6 text-gray-600 hover:text-red-500">
|
||||
<.link phx-click={JS.push("like", value: %{id: @post.id})}>
|
||||
<.link phx-click={
|
||||
(@user && JS.push("like", value: %{id: @post.id})) ||
|
||||
JS.push("login")
|
||||
}>
|
||||
<%= Heroicons.icon("heart", type: "outline", class: "w-5 h-5") %>
|
||||
</.link>
|
||||
<span class="ml-1"><%= length(@post.liked_by) %></span>
|
||||
|
||||
8
mix.lock
8
mix.lock
@@ -7,8 +7,8 @@
|
||||
"cowboy_telemetry": {:hex, :cowboy_telemetry, "0.4.0", "f239f68b588efa7707abce16a84d0d2acf3a0f50571f8bb7f56a15865aae820c", [:rebar3], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7d98bac1ee4565d31b62d59f8823dfd8356a169e7fcbb83831b8a5397404c9de"},
|
||||
"cowlib": {:hex, :cowlib, "2.11.0", "0b9ff9c346629256c42ebe1eeb769a83c6cb771a6ee5960bd110ab0b9b872063", [:make, :rebar3], [], "hexpm", "2b3e9da0b21c4565751a6d4901c20d1b4cc25cbb7fd50d91d2ab6dd287bc86a9"},
|
||||
"db_connection": {:hex, :db_connection, "2.4.2", "f92e79aff2375299a16bcb069a14ee8615c3414863a6fef93156aee8e86c2ff3", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "4fe53ca91b99f55ea249693a0229356a08f4d1a7931d8ffa79289b145fe83668"},
|
||||
"decimal": {:hex, :decimal, "2.0.0", "a78296e617b0f5dd4c6caf57c714431347912ffb1d0842e998e9792b5642d697", [:mix], [], "hexpm", "34666e9c55dea81013e77d9d87370fe6cb6291d1ef32f46a1600230b1d44f577"},
|
||||
"ecto": {:hex, :ecto, "3.9.2", "017db3bc786ff64271108522c01a5d3f6ba0aea5c84912cfb0dd73bf13684108", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "21466d5177e09e55289ac7eade579a642578242c7a3a9f91ad5c6583337a9d15"},
|
||||
"decimal": {:hex, :decimal, "2.1.1", "5611dca5d4b2c3dd497dec8f68751f1f1a54755e8ed2a966c2633cf885973ad6", [:mix], [], "hexpm", "53cfe5f497ed0e7771ae1a475575603d77425099ba5faef9394932b35020ffcc"},
|
||||
"ecto": {:hex, :ecto, "3.9.6", "2f420c173efcb2e22fa4f8fc41e75e02b3c5bd4cffef12085cae5418c12e530d", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "df17bc06ba6f78a7b764e4a14ef877fe5f4499332c5a105ace11fe7013b72c84"},
|
||||
"ecto_sql": {:hex, :ecto_sql, "3.9.1", "9bd5894eecc53d5b39d0c95180d4466aff00e10679e13a5cfa725f6f85c03c22", [:mix], [{:db_connection, "~> 2.5 or ~> 2.4.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.9.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.6.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.16.0 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.1 or ~> 2.2", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "5fd470a4fff2e829bbf9dcceb7f3f9f6d1e49b4241e802f614de6b8b67c51118"},
|
||||
"elixir_make": {:hex, :elixir_make, "0.6.3", "bc07d53221216838d79e03a8019d0839786703129599e9619f4ab74c8c096eac", [:mix], [], "hexpm", "f5cbd651c5678bcaabdbb7857658ee106b12509cd976c2c2fca99688e1daf716"},
|
||||
"esbuild": {:hex, :esbuild, "0.5.0", "d5bb08ff049d7880ee3609ed5c4b864bd2f46445ea40b16b4acead724fb4c4a3", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}], "hexpm", "f183a0b332d963c4cfaf585477695ea59eef9a6f2204fdd0efa00e099694ffe5"},
|
||||
@@ -19,7 +19,7 @@
|
||||
"gettext": {:hex, :gettext, "0.20.0", "75ad71de05f2ef56991dbae224d35c68b098dd0e26918def5bb45591d5c8d429", [:mix], [], "hexpm", "1c03b177435e93a47441d7f681a7040bd2a816ece9e2666d1c9001035121eb3d"},
|
||||
"heroicons": {:hex, :heroicons, "0.5.1", "cca0dcca07af5f74d8a7d111e40418d3615d65e6773c0ea10e20cef070fd30aa", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}, {:phoenix_live_view, "~> 0.18.2", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}], "hexpm", "4b096d0a1d50e9054df9b12cc637c9f65c3972ff086791d3f2d1846f0653117e"},
|
||||
"hpax": {:hex, :hpax, "0.1.2", "09a75600d9d8bbd064cdd741f21fc06fc1f4cf3d0fcc335e5aa19be1a7235c84", [:mix], [], "hexpm", "2c87843d5a23f5f16748ebe77969880e29809580efdaccd615cd3bed628a8c13"},
|
||||
"jason": {:hex, :jason, "1.4.0", "e855647bc964a44e2f67df589ccf49105ae039d4179db7f6271dfd3843dc27e6", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "79a3791085b2a0f743ca04cec0f7be26443738779d09302e01318f97bdb82121"},
|
||||
"jason": {:hex, :jason, "1.4.1", "af1504e35f629ddcdd6addb3513c3853991f694921b1b9368b0bd32beb9f1b63", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fbb01ecdfd565b56261302f7e1fcc27c4fb8f32d56eab74db621fc154604a7a1"},
|
||||
"mime": {:hex, :mime, "2.0.3", "3676436d3d1f7b81b5a2d2bd8405f412c677558c81b1c92be58c00562bb59095", [:mix], [], "hexpm", "27a30bf0db44d25eecba73755acf4068cbfe26a4372f9eb3e4ea3a45956bff6b"},
|
||||
"mint": {:hex, :mint, "1.4.2", "50330223429a6e1260b2ca5415f69b0ab086141bc76dc2fbf34d7c389a6675b2", [:mix], [{:castore, "~> 0.1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:hpax, "~> 0.1.1", [hex: :hpax, repo: "hexpm", optional: false]}], "hexpm", "ce75a5bbcc59b4d7d8d70f8b2fc284b1751ffb35c7b6a6302b5192f8ab4ddd80"},
|
||||
"nimble_options": {:hex, :nimble_options, "0.4.0", "c89babbab52221a24b8d1ff9e7d838be70f0d871be823165c94dd3418eea728f", [:mix], [], "hexpm", "e6701c1af326a11eea9634a3b1c62b475339ace9456c1a23ec3bc9a847bca02d"},
|
||||
@@ -39,7 +39,7 @@
|
||||
"ranch": {:hex, :ranch, "1.8.0", "8c7a100a139fd57f17327b6413e4167ac559fbc04ca7448e9be9057311597a1d", [:make, :rebar3], [], "hexpm", "49fbcfd3682fab1f5d109351b61257676da1a2fdbe295904176d5e521a2ddfe5"},
|
||||
"swoosh": {:hex, :swoosh, "1.8.2", "af9a22ab2c0d20b266f61acca737fa11a121902de9466a39e91bacdce012101c", [:mix], [{:cowboy, "~> 1.1 or ~> 2.4", [hex: :cowboy, repo: "hexpm", optional: true]}, {:ex_aws, "~> 2.1", [hex: :ex_aws, repo: "hexpm", optional: true]}, {:finch, "~> 0.6", [hex: :finch, repo: "hexpm", optional: true]}, {:gen_smtp, "~> 0.13 or ~> 1.0", [hex: :gen_smtp, repo: "hexpm", optional: true]}, {:hackney, "~> 1.9", [hex: :hackney, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:mail, "~> 0.2", [hex: :mail, repo: "hexpm", optional: true]}, {:mime, "~> 1.1 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_cowboy, ">= 1.0.0", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.2 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "d058ba750eafadb6c09a84a352c14c5d1eeeda6e84945fcc95785b7f3067b7db"},
|
||||
"tailwind": {:hex, :tailwind, "0.1.9", "25ba09d42f7bfabe170eb67683a76d6ec2061952dc9bd263a52a99ba3d24bd4d", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}], "hexpm", "9213f87709c458aaec313bb5f2df2b4d2cedc2b630e4ae821bf3c54c47a56d0b"},
|
||||
"telemetry": {:hex, :telemetry, "1.1.0", "a589817034a27eab11144ad24d5c0f9fab1f58173274b1e9bae7074af9cbee51", [:rebar3], [], "hexpm", "b727b2a1f75614774cff2d7565b64d0dfa5bd52ba517f16543e6fc7efcc0df48"},
|
||||
"telemetry": {:hex, :telemetry, "1.2.1", "68fdfe8d8f05a8428483a97d7aab2f268aaff24b49e0f599faa091f1d4e7f61c", [:rebar3], [], "hexpm", "dad9ce9d8effc621708f99eac538ef1cbe05d6a874dd741de2e689c47feafed5"},
|
||||
"telemetry_metrics": {:hex, :telemetry_metrics, "0.6.1", "315d9163a1d4660aedc3fee73f33f1d355dcc76c5c3ab3d59e76e3edf80eef1f", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7be9e0871c41732c233be71e4be11b96e56177bf15dde64a8ac9ce72ac9834c6"},
|
||||
"telemetry_poller": {:hex, :telemetry_poller, "1.0.0", "db91bb424e07f2bb6e73926fcafbfcbcb295f0193e0a00e825e589a0a47e8453", [:rebar3], [{:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "b3a24eafd66c3f42da30fc3ca7dda1e9d546c12250a2d60d7b81d264fbec4f6e"},
|
||||
"websock": {:hex, :websock, "0.4.3", "184ac396bdcd3dfceb5b74c17d221af659dd559a95b1b92041ecb51c9b728093", [:mix], [], "hexpm", "5e4dd85f305f43fd3d3e25d70bec4a45228dfed60f0f3b072d8eddff335539cf"},
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
cd -P -- "$(dirname -- "$0")"
|
||||
exec ./malarkey eval Malarkey.Release.migrate
|
||||
@@ -1 +0,0 @@
|
||||
call "%~dp0\malarkey" eval Malarkey.Release.migrate
|
||||
@@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
cd -P -- "$(dirname -- "$0")"
|
||||
PHX_SERVER=true exec ./malarkey start
|
||||
@@ -1,2 +0,0 @@
|
||||
set PHX_SERVER=true
|
||||
call "%~dp0\malarkey" start
|
||||
Reference in New Issue
Block a user