-
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
7d97276
commit 1b3acf7
Showing
9 changed files
with
79 additions
and
68 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,11 +1,2 @@ | ||
defmodule Calm do | ||
def welcome_message(name, greeting \\ "Hello") | ||
|
||
def welcome_message(nil, _greeting) do | ||
nil | ||
end | ||
|
||
def welcome_message(name, greeting) do | ||
"#{greeting}, #{name}!" | ||
end | ||
end |
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 |
---|---|---|
@@ -1,41 +1,30 @@ | ||
defmodule Calm.WWW.Actions.HomePage do | ||
use Raxx.SimpleServer | ||
use Calm.WWW.Layout, arguments: [:greeting, :csrf_token] | ||
alias Raxx.Session | ||
use Calm.WWW.Layout, arguments: [:latest] | ||
|
||
@impl Raxx.SimpleServer | ||
def handle_request(request = %{method: :GET}, state) do | ||
{:ok, session} = Session.extract(request, state.session_config) | ||
def handle_request(request = %{method: :GET}, config) do | ||
{:ok, session} = Raxx.Session.extract(request, config.session_config) | ||
session = session || %{threads: %{}} | ||
thread_ids = Map.keys(session.threads) | ||
|
||
{csrf_token, session} = Session.get_csrf_token(session) | ||
{flash, session} = Session.pop_flash(session) | ||
|
||
greeting = Calm.welcome_message(session[:name]) | ||
latest = load_latest(thread_ids) | ||
|
||
response(:ok) | ||
|> Session.embed(session, state.session_config) | ||
|> render(greeting, csrf_token, flash: flash) | ||
|> render(latest) | ||
end | ||
|
||
def handle_request(request = %{method: :POST}, state) do | ||
data = URI.decode_query(request.body) | ||
{:ok, session} = Session.extract(request, data["_csrf_token"], state.session_config) | ||
|
||
case data do | ||
%{"name" => name} -> | ||
session = | ||
session | ||
|> Map.put(:name, name) | ||
|> Session.put_flash(:info, "Successfully changed name") | ||
def load_latest(thread_ids) do | ||
import Ecto.Query | ||
|
||
redirect("/") | ||
|> Session.embed(session, state.session_config) | ||
query = | ||
Calm.Message | ||
|> order_by([m], desc: m.inserted_at) | ||
|> join(:inner, [m], i in Calm.Invite, on: m.invite_id == i.id) | ||
|> where([m, i], i.thread_id in ^thread_ids) | ||
|> preload(invite: :thread) | ||
|> distinct([m, i], i.thread_id) | ||
|
||
_ -> | ||
redirect("/") | ||
end | ||
Calm.Repo.all(query) | ||
end | ||
|
||
# Template helper functions. | ||
# Add shared helper functions to Calm.WWW.Layout. | ||
end |
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,16 +1,38 @@ | ||
<main class="p-6"> | ||
<header class="p-4 text-2xl"> | ||
<h1>Calm</h1> | ||
<div class="flex flex-col h-full overflow-y-hidden mx-auto max-w-3xl bg-white shadow-2xl overflow-hidden"> | ||
<header class="bg-gray-300"> | ||
<h1 class="p-4 text-2xl truncate">Calm: A better way to talk!!!</h1> | ||
</header> | ||
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p> | ||
<textarea class="block border-2 w-full" ></textarea> | ||
<h2 class="text-2xl ">View my inbox</h2> | ||
<!-- <form action="/" method="post"> | ||
<input type="hidden" name="_csrf_token" value="<%= csrf_token %>"> | ||
<label> | ||
<span>tell us your name</span> | ||
<input type="text" name="name" value="" autofocus> | ||
</label> | ||
<button type="submit">Submit</button> | ||
</form> --> | ||
</main> | ||
<div id="updates" class="flex-auto overflow-y-auto"> | ||
<article class="mx-4 my-4"> | ||
<!-- <header class="my-2"> | ||
<span class="inline-block mr-2 px-4 rounded bg-blue-700 text-white">The team</span> | ||
<span class="text-gray-500">2020</span> | ||
</header> --> | ||
<p class="whitespace-pre-line">An experiment to keep in touch while respecting everyones time and attention.</p> | ||
</article> | ||
<div class="mx-4"> | ||
<hr class="w-1/2 mx-auto"> | ||
</div> | ||
<%= if latest == [] do %> | ||
<article class="mx-4 my-4"> | ||
<p class="whitespace-pre-line">You don't have any new messages.</p> | ||
</article> | ||
<% end %> | ||
<%= for update <- latest do %> | ||
<a class="block mx-4 my-6 border-l-2 pl-4 border-black cursor-pointer" href="/t/<%= update.invite.thread_id %>"> | ||
<header class=""> | ||
<span class="inline-block mr-2 font-bold"><%= update.invite.thread.subject %></span> | ||
<!-- <span class="inline-block mr-2 px-4 rounded bg-<%= update.invite.color %>-700 text-white"><%= update.invite.nickname %></span> --> | ||
<span class="text-gray-500"><%= Calm.WWW.Actions.ThreadPage.update_time(update) %></span> | ||
</header> | ||
<p class="whitespace-pre-line text-gray-600"><%= update.invite.nickname %>: <%= hd(String.split(update.text, ~r/\R/, parts: 2)) %></p> | ||
<!-- <p class="whitespace-pre-line"><%= update.invite.nickname %>: <%= update.text %></p> --> | ||
</a> | ||
<% end %> | ||
</div> | ||
<footer class=""> | ||
<div class="mx-4 my-4 text-right"> | ||
<a class="text-blue-500" href="#">View on Github</a> | ||
</div> | ||
</footer> | ||
</div> |
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