diff --git a/assets/css/app.css b/assets/css/app.css index 378c8f9..320c81d 100644 --- a/assets/css/app.css +++ b/assets/css/app.css @@ -1,5 +1,34 @@ @import "tailwindcss/base"; @import "tailwindcss/components"; + + @import "tailwindcss/utilities"; + +/* note import won't work without node based build pipeline - i.e postcss-import */ +/* @import "./components/buttons.css"; */ + +@layer components { + .btn-primary { + @apply py-2 px-4 bg-green-500 text-white font-semibold rounded-lg shadow-md hover:bg-green-700 focus:outline-none focus:ring-2 focus:ring-green-400 focus:ring-opacity-75; + } + + .sidebar-iconbox { + @apply relative flex items-center justify-center h-12 w-12 mt-2 mb-4 mx-auto ; + } + .sidebar-icon { + @apply stroke-green-500 hover:stroke-cyan-400 fill-transparent shadow-lg + hover:rounded-xl rounded-3xl transition-all duration-200 ease-linear; + + } + .sidebar-tooltip { + @apply absolute w-auto p-2 m-2 min-w-max left-14 rounded-md shadow-md + text-white bg-gray-900 text-xs font-bold + transition-all duration-100 scale-0 origin-left; + + } + } + + + /* This file is for your main application CSS */ diff --git a/assets/css/components/buttons.css b/assets/css/components/buttons.css new file mode 100644 index 0000000..ba85de5 --- /dev/null +++ b/assets/css/components/buttons.css @@ -0,0 +1,10 @@ +@tailwind base; +@tailwind components; +@tailwind utilities; + +@layer components { + .btn-primary { + @apply py-2 px-4 bg-green-500 text-white font-semibold rounded-lg shadow-md hover:bg-green-700 focus:outline-none focus:ring-2 focus:ring-green-400 focus:ring-opacity-75; + } +} + diff --git a/assets/tailwind.config.js b/assets/tailwind.config.js index b611701..069b7f1 100644 --- a/assets/tailwind.config.js +++ b/assets/tailwind.config.js @@ -13,6 +13,19 @@ module.exports = { extend: { colors: { brand: "#FD4F00", + primary: "#202225", + secondary: "#5865f2", + gray: { + 900: "#202225", + 800: "#243136", + 700: "#36393f", + 600: "#4f545c", + 400: "#d4d7dc", + 300: "#e3e5e8", + 200: "#ebedef", + 100: "#f2f3f5" + + } } }, }, diff --git a/lib/chirp/timeline.ex b/lib/chirp/timeline.ex index a9c2d76..fd09b21 100644 --- a/lib/chirp/timeline.ex +++ b/lib/chirp/timeline.ex @@ -21,6 +21,23 @@ defmodule Chirp.Timeline do Repo.all(from p in Post, order_by: [desc: p.id]) end + def inc_likes(%Post{id: id}) do + {1, [post]} = + from(p in Post, where: p.id == ^id, select: p) + |> Repo.update_all(inc: [likes_count: 1]) + + broadcast({:ok, post},:post_updated) + end + + def inc_reposts(%Post{id: id}) do + {1, [post]} = + from(p in Post, where: p.id == ^id, select: p) + |> Repo.update_all(inc: [reposts_count: 1]) + + broadcast({:ok, post},:post_updated) + end + + @doc """ Gets a single post. @@ -88,7 +105,10 @@ defmodule Chirp.Timeline do """ def delete_post(%Post{} = post) do - Repo.delete(post) + post + |> Repo.delete() + |> broadcast(:post_updated) + end @doc """ diff --git a/lib/chirp_web/controllers/hello_controller.ex b/lib/chirp_web/controllers/hello_controller.ex new file mode 100644 index 0000000..fb512cf --- /dev/null +++ b/lib/chirp_web/controllers/hello_controller.ex @@ -0,0 +1,7 @@ +defmodule ChirpWeb.HelloController do + use ChirpWeb, :controller + + def index(conn, _params) do + render(conn, "index.html") + end +end diff --git a/lib/chirp_web/live/post_live/index.ex b/lib/chirp_web/live/post_live/index.ex index 91fe702..d51a401 100644 --- a/lib/chirp_web/live/post_live/index.ex +++ b/lib/chirp_web/live/post_live/index.ex @@ -33,19 +33,7 @@ defmodule ChirpWeb.PostLive.Index do |> assign(:post, nil) end - @impl true - def handle_event("delete", %{"id" => id}, socket) do - post = Timeline.get_post!(id) - {:ok, _} = Timeline.delete_post(post) - {:noreply, assign(socket, :posts, list_posts())} - end - def handle_event("like", %{"id" => _id}, socket) do - {:noreply,socket} - end - def handle_event("repost", %{"id" => _id}, socket) do - {:noreply,socket} - end def handle_info({:post_created,post}, socket) do {:noreply, update(socket, :posts, fn posts-> [post|posts] end)} diff --git a/lib/chirp_web/live/post_live/post_component.ex b/lib/chirp_web/live/post_live/post_component.ex index a2afa13..6568241 100644 --- a/lib/chirp_web/live/post_live/post_component.ex +++ b/lib/chirp_web/live/post_live/post_component.ex @@ -3,9 +3,12 @@ defmodule ChirpWeb.PostLive.PostComponent do @spec render(any) :: Phoenix.LiveView.Rendered.t() def render(assigns) do + #IO.inspect(assigns.post.__meta__.state) ~H""" -
<%= @post.body %>-
<%= @post.body %>+