8000 feat: return to where you came from after sign in, else your groups' agenda with Nearby by MichaelDimmitt · Pull Request #679 · huddlz-hq/huddlz · GitHub
[go: up one dir, main page]

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions assets/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -3223,6 +3223,72 @@ body .cal-toolbar {

body .cal-scope { margin-bottom: 16px; }

/* One quiet line under the chips saying what the Nearby scope is showing
and where to go for more. Only Nearby needs it: RSVPs and Groups are
self-explanatory from the chip alone. */
body .cal-scope-note {
display: flex;
flex-wrap: wrap;
align-items: baseline;
gap: 4px 8px;
margin: -6px 0 16px;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}

body .cal-scope-note strong { color: var(--text); font-weight: 600; }

body .cal-scope-note-link {
display: inline-flex;
align-items: center;
gap: 3px;
color: var(--accent-ink);
font-weight: 600;
text-decoration: none;
transition: opacity 120ms ease;
}

body .cal-scope-note-link:hover { opacity: 0.75; }

body .cal-scope-note-link:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
border-radius: var(--radius-sm);
}

/* Placeholder rows while the Nearby search is out: the agenda's own
shape, so nothing moves when the real rows replace them. Held back by
the same delay the card skeletons use, so a fast search never flashes. */
body .cal-agenda-skeleton { animation: skeleton-in 120ms ease 250ms both; }
body .cal-agenda-entry.is-skeleton {
display: grid;
grid-template-columns: 128px minmax(0, 1fr) auto;
gap: 16px;
align-items: center;
padding: 12px 20px 12px 16px;
pointer-events: none;
}

body .cal-agenda-entry.is-skeleton .cal-agenda-body {
display: flex;
flex-direction: column;
gap: 6px;
}

body .cal-agenda-skeleton .skel-weekday { width: 28px; }
body .cal-agenda-skeleton .skel-daynum { width: 36px; height: 24px; margin-top: 6px; }
body .cal-agenda-skeleton .skel-clock { width: 64px; }
body .cal-agenda-skeleton .skel-place { width: 46%; }
body .cal-agenda-skeleton .skel-wide { width: 72%; }
body .cal-agenda-skeleton .skel-mid { width: 54%; }
body .cal-agenda-skeleton .skel-narrow { width: 63%; }

@media (prefers-reduced-motion: reduce) {
body .cal-agenda-skeleton { animation: none; }
body .cal-scope-note-link { transition: none; }
}

body .cal-nav { display: flex; gap: 4px; }

body .cal-nav-btn {
Expand Down
20 changes: 20 additions & 0 deletions lib/huddlz_web/auth_return_to.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,26 @@ defmodule HuddlzWeb.AuthReturnTo do

def validate(_path), do: nil

@doc """
The sign-in address that brings the person back to `destination` after
signing in, or the bare sign-in address when `destination` is not a safe
local path. Accepts a path or a request's `URI`.
"""
@spec sign_in_path(URI.t() | String.t() | nil) :: String.t()
def sign_in_path(%URI{path: path, query: query}) when query in [nil, ""], do: sign_in_path(path)

def sign_in_path(%URI{path: path, query: query}) when is_binary(path),
do: sign_in_path(path <> "?" <> query)

def sign_in_path(%URI{}), do: "/sign-in"

def sign_in_path(destination) do
case validate(destination) do
nil -> "/sign-in"
return_to -> "/sign-in?" <> URI.encode_query(return_to: return_to)
end
end

defp local_path?(%URI{scheme: nil, host: nil, path: "/" <> _}, path) do
not String.starts_with?(path, "//") and
not String.contains?(String.downcase(path), ["\\", "%2f", "%5c"])
Expand Down
28 changes: 26 additions & 2 deletions lib/huddlz_web/components/layouts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,24 @@ defmodule HuddlzWeb.Layouts do
doc: "groups the current_user organizes — rendered as sb-org-row entries"

attr :query, :string, default: "", doc: "current search query — prefilled in topbar input"

attr :return_to, :string,
default: nil,
doc: """
where the topbar's sign-in and sign-up links should send the person back
to once they are signed in. A page worth returning to passes its own
address; anything else leaves this nil and the links stay bare. Always
re-checked through `HuddlzWeb.AuthReturnTo.validate/1` here, so a page
cannot hand the header an off-site destination.
"""

slot :inner_block, required: true

def app(assigns) do
assigns =
assigns
|> assign_new(:signed_in, fn -> assigns.current_user != nil end)
|> assign(:return_to, HuddlzWeb.AuthReturnTo.validate(assigns[:return_to]))

~H"""
<.skip_link />
Expand Down Expand Up @@ -339,8 +351,12 @@ defmodule HuddlzWeb.Layouts do
</span>
</.link>
<% else %>
<.link class="btn-secondary" navigate={~p"/sign-in"}>Sign in</.link>
<.link class="btn-primary" navigate={~p"/register"}>Sign up</.link>
<.link class="btn-secondary" navigate={auth_path(~p"/sign-in", @return_to)}>
Sign in
</.link>
<.link class="btn-primary" navigate={auth_path(~p"/register", @return_to)}>
Sign up
</.link>
<% end %>
</div>
</header>
Expand Down Expand Up @@ -460,6 +476,14 @@ defmodule HuddlzWeb.Layouts do
]
end

# A signed-out person reading a huddl or a group has somewhere they mean to
# come back to. The topbar's sign-in and sign-up carry it so the trip
# through auth does not cost them the page. `@return_to` has already been
# through `AuthReturnTo.validate/1` in `app/1`; nil means there is nothing
# worth returning to and the bare path is right.
defp auth_path(path, nil), do: path
defp auth_path(path, return_to), do: path <> "?" <> URI.encode_query(return_to: return_to)

defp theme_current(%{theme_preference: theme}) when theme in [:light, :dark], do: theme
defp theme_current(_user), do: :system

Expand Down
4 changes: 2 additions & 2 deletions lib/huddlz_web/endpoint.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ defmodule HuddlzWeb.Endpoint do
]

@live_connect_info if(Application.compile_env(:huddlz, :sql_sandbox?, false),
do: [:user_agent, session: @session_options],
else: [session: @session_options]
do: [:uri, :user_agent, session: @session_options],
else: [:uri, session: @session_options]
)

socket "/live", Phoenix.LiveView.Socket,
Expand Down
Loading
Loading
0