Skip to content

Commit f604b9f

Browse files
committed
wrangling a form to create groups using LiveView #220
1 parent 44a9517 commit f604b9f

File tree

8 files changed

+123
-32
lines changed

8 files changed

+123
-32
lines changed

BUILDIT.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ it in **30 minutes**. 🏁
3131
- [10.6 Group _People_](#106-group-people)
3232
- [10.7 _Test_ `group_people.ex`](#107-test-group_peopleex)
3333
- [10.8 Make `group_people_test.exs` pass](#108-make-group_people_testexs-pass)
34+
- [10.9.1 Add Font Awesome Icons](#1091-add-font-awesome-icons)
3435

3536
<br />
3637

@@ -351,7 +352,8 @@ You should see the following:
351352
![groups-liveview](https://user-images.githubusercontent.com/194400/197360963-fedeccf7-a096-4a94-b95d-4457cae72f0b.png)
352353

353354
Don't worry, all of this UI will be replaced shortly.
354-
This is just to confirm we have Tailwind and LiveView working.
355+
This is just to confirm we have
356+
`Tailwind` and `LiveView` _working_.
355357

356358
## 10.5 Create `groups_live_test.exs`
357359

@@ -684,3 +686,5 @@ of a **_single_ page**
684686
because we expect this to be
685687
used in the context of our **Mobile-first `App`**.
686688

689+
### 10.9.1 Add Font Awesome Icons
690+

assets/css/app.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
@import "tailwindcss/components";
33
@import "tailwindcss/utilities";
44

5+
56
/* This file is for your main application css. */
67

78
/* @import "./phoenix.css"; */

config/config.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ config :auth_plug,
4747
api_key: System.get_env("AUTH_API_KEY")
4848

4949
config :tailwind,
50-
version: "3.2.0",
50+
version: "3.1.8",
5151
default: [
5252
args: ~w(
5353
--config=tailwind.config.js

lib/auth/init/roles.ex

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,57 +3,57 @@ defmodule Auth.InitRoles do
33
def roles do
44
[
55
%{
6-
name: "superadmin",
7-
desc: "With great power comes great responsibility",
6+
name: "superadmin",
7+
desc: "With great power comes great responsibility",
88
person_id: 1,
99
# id: 1,
1010
permissions: "grant_admin_role"
1111
},
1212
%{
13-
name: "admin",
14-
desc: "Can perform all system administration tasks",
13+
name: "admin",
14+
desc: "Can perform all system administration tasks",
1515
person_id: 1,
1616
# id: 2,
1717
permissions: "manage_people, grant_non_admin_role"
1818
},
1919
%{
20-
name: "moderator",
21-
desc: "Can view and neutrally moderate any content. Can ban rule-breakers. Cannot delete.",
20+
name: "moderator",
21+
desc: "Can view and neutrally moderate any content. Can ban rule-breakers. Cannot delete.",
2222
person_id: 1,
2323
# id: 3,
2424
permissions: "edit_any_content, lock_content, unpublish_content, ban_rule_breaking_people, view_deleted"
2525
},
2626
%{
27-
name: "creator",
28-
desc: "Can create any content. Can edit and delete their own content.",
27+
name: "creator",
28+
desc: "Can create any content. Can edit and delete their own content.",
2929
person_id: 1,
3030
# id: 4,
3131
permissions: "create_content, upload_images, edit_own_content, delete_own_content, invite_people"
3232
},
3333
%{
34-
name: "commenter",
35-
desc: "Can comment on content where commenting is available.",
34+
name: "commenter",
35+
desc: "Can comment on content where commenting is available.",
3636
person_id: 1,
3737
# id: 5,
3838
permissions: "comment, flag_comments, flag_content"
3939
},
4040
%{
41-
name: "subscriber",
42-
desc: "Subscribes for updates e.g. newsletter or content from a specific person. Cannot comment until verified.",
41+
name: "subscriber",
42+
desc: "Subscribes for updates e.g. newsletter or content from a specific person. Cannot comment until verified.",
4343
person_id: 1,
4444
# id: 6,
4545
permissions: "subscribe, give_feedback"
4646
},
4747
%{
48-
name: "banned",
49-
desc: "Can still login to see their content but cannot perform any other action.",
48+
name: "banned",
49+
desc: "Can still login to see their content but cannot perform any other action.",
5050
person_id: 1,
5151
# id: 7,
5252
permissions: "view_content, view_profile, delete_own_content, delete_own_profile"
5353
},
5454
%{
55-
name: "app_admin",
56-
desc: "Can manage their own App(s).",
55+
name: "app_admin",
56+
desc: "Can manage their own App(s).",
5757
person_id: 1,
5858
# id: 8,
5959
permissions: "manage_own_apps, create_content, upload_images, edit_own_content, delete_own_content, invite_people"
@@ -66,4 +66,4 @@ defmodule Auth.InitRoles do
6666
Auth.Role.upsert_role(role)
6767
end)
6868
end
69-
end
69+
end

lib/auth_web.ex

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ defmodule AuthWeb do
5959
end
6060
end
6161

62+
def component do
63+
quote do
64+
use Phoenix.Component
65+
66+
unquote(view_helpers())
67+
end
68+
end
69+
6270
def router do
6371
quote do
6472
use Phoenix.Router
@@ -80,6 +88,7 @@ defmodule AuthWeb do
8088
quote do
8189
# Use all HTML functionality (forms, tags, etc)
8290
use Phoenix.HTML
91+
import Phoenix.Component
8392
use PetalComponents
8493

8594
# Import LiveView and .heex helpers (live_render, live_patch, <.form>, etc)

lib/auth_web/endpoint.ex

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@ defmodule AuthWeb.Endpoint do
1010
signing_salt: "Fir8x4nA"
1111
]
1212

13-
socket "/live", Phoenix.LiveView.Socket, websocket: [connect_info: [session: @session_options]]
13+
socket "/live", Phoenix.LiveView.Socket,
14+
websocket: [connect_info: [session: @session_options]]
1415

15-
# socket "/socket", AuthWeb.UserSocket,
16-
# websocket: true,
17-
# longpoll: false
1816

1917
# Serve at "/" the static files from "priv/static" directory.
2018
#
@@ -35,10 +33,6 @@ defmodule AuthWeb.Endpoint do
3533
plug Phoenix.Ecto.CheckRepoStatus, otp_app: :auth
3634
end
3735

38-
# plug Phoenix.LiveDashboard.RequestLogger,
39-
# param_key: "request_logger",
40-
# cookie_key: "request_logger"
41-
4236
plug Plug.RequestId
4337
plug Plug.Telemetry, event_prefix: [:phoenix, :endpoint]
4438

lib/auth_web/live/groups_live.ex

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,28 @@
11
defmodule AuthWeb.GroupsLive do
22
use AuthWeb, :live_view
3+
alias Phoenix.Socket.Broadcast
4+
@topic "live"
35

46
def mount(_params, _session, socket) do
57
{:ok, socket}
68
end
9+
10+
11+
@impl true
12+
def handle_event("create", %{"name" => name, "desc" => desc}, socket) do
13+
# person_id = get_person_id(socket.assigns)
14+
15+
# Item.create_item_with_tags(%{
16+
# text: text,
17+
# # person_id: person_id,
18+
# status: 2,
19+
# tags: tags
20+
# })
21+
dbg(name)
22+
dbg(desc)
23+
24+
AuthWeb.Endpoint.broadcast(@topic, "update", :create)
25+
{:noreply, socket}
26+
end
27+
728
end
Lines changed: 67 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,67 @@
1-
<h1 class="w-full text-center text-2xl text-white font-bold
2-
bg-gradient-to-r from-green-400 to-blue-500 p-4">
3-
<!-- <a class="float-left" href="/">back to the app</a> -->
4-
Groups LiveView!
5-
</h1>
1+
<div class="text-center text-2xl text-white font-bold
2+
bg-emerald-400 p-4">
3+
<div class="inline-flex items-center px-2 py-1 mr-2 h-9
4+
text-gray-800 rounded-md"
5+
phx-click="delete" phx-value-id={}>
6+
<svg xmlns="http://www.w3.org/2000/svg" fill="none"
7+
viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"
8+
class="w-8 h-8 mr-2">
9+
<path stroke-linecap="round" stroke-linejoin="round"
10+
d="M18 18.72a9.094 9.094 0 003.741-.479 3 3 0 00-4.682-2.72m.94 3.198l.001.031c0 .225-.012.447-.037.666A11.944 11.944 0 0112 21c-2.17 0-4.207-.576-5.963-1.584A6.062 6.062 0 016 18.719m12 0a5.971 5.971 0 00-.941-3.197m0 0A5.995 5.995 0 0012 12.75a5.995 5.995 0 00-5.058 2.772m0 0a3 3 0 00-4.681 2.72 8.986 8.986 0 003.74.477m.94-3.197a5.971 5.971 0 00-.94 3.197M15 6.75a3 3 0 11-6 0 3 3 0 016 0zm6 3a2.25 2.25 0 11-4.5 0 2.25 2.25 0 014.5 0zm-13.5 0a2.25 2.25 0 11-4.5 0 2.25 2.25 0 014.5 0z" />
11+
</svg>
12+
Groups
13+
</div>
14+
</div>
15+
16+
17+
<!-- New Button Works just hiding it for now ...
18+
<button class="inline-flex items-center px-2 py-1 mr-2 h-9
19+
bg-gray-200 hover:bg-gray-300 text-gray-800 rounded-md"
20+
phx-click="delete" phx-value-id={}>
21+
<svg xmlns="http://www.w3.org/2000/svg" fill="none"
22+
viewBox="0 0 24 24"
23+
stroke-width="1.5" stroke="currentColor"
24+
class="w-6 h-6 float-right">
25+
<path stroke-linecap="round" stroke-linejoin="round"
26+
d="M12 4.5v15m7.5-7.5h-15" />
27+
</svg>
28+
New
29+
</button>
30+
-->
31+
32+
<div class="px-1">
33+
<form phx-submit="create"
34+
class="w-full lg:w-3/4 lg:max-w-lg text-center mx-auto">
35+
36+
<div class="py-2 px-2 border-2 border-indigo-600">
37+
<label>Group name:</label>
38+
<input type="text" placeholder="short and descriptive" name="name">
39+
</div>
40+
41+
<div class="py-2 px-2 border-2 border-red-600">
42+
<label>Description:</label>
43+
<input type="text" placeholder="more detail as needed" name="desc">
44+
</div>
45+
46+
<div class="flex justify-end mr-1">
47+
<button class="inline-flex items-center px-2 py-1 mt-1 h-9
48+
bg-green-700 hover:bg-green-800 text-white rounded-md">
49+
<svg xmlns="http://www.w3.org/2000/svg"
50+
class="h-5 w-5 mr-2" fill="none"
51+
viewBox="0 0 24 24" stroke="currentColor">
52+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
53+
d="M15 13l-3 3m0 0l-3-3m3 3V8m0 13a9 9 0 110-18 9 9 0 010 18z"
54+
/>
55+
</svg>
56+
Create
57+
</button>
58+
</div>
59+
60+
61+
<p class="pt-3">
62+
List the groups I am a member of,
63+
or hide this section.
64+
</p>
65+
66+
</form>
67+
</div>

0 commit comments

Comments
 (0)