show error page puzzle link only for premium users

This commit is contained in:
2026-11-06 15:47:53 +01:00
parent 785e403370
commit bf176ebd42
9 changed files with 53 additions and 13 deletions
+2 -3
View File
@@ -6,6 +6,7 @@ defmodule ChesstrainerWeb.Layouts do
use ChesstrainerWeb, :html
alias Chesstrainer.Accounts.Role
alias Chesstrainer.Accounts.Scope
# Embed all files in layouts/* within this module.
# The default root.html.heex file contains the HTML
@@ -110,7 +111,7 @@ defmodule ChesstrainerWeb.Layouts do
defp nav_links(scope) do
marketing =
if premium?(scope) do
if Scope.premium?(scope) do
[
%{label: "Puzzle Search", href: "/endgames"}
]
@@ -147,8 +148,6 @@ defmodule ChesstrainerWeb.Layouts do
defp admin?(%{user: %{role: role}}), do: Role.admin?(role)
defp admin?(_scope), do: false
defp premium?(scope), do: match?(%{user: %{plan: :premium}}, scope)
# Signed-in users start a puzzle session; visitors browse the public list.
defp start_href(%{user: %{}}), do: ~p"/train"
defp start_href(_scope), do: ~p"/guest-train"
@@ -10,6 +10,8 @@ defmodule ChesstrainerWeb.ErrorHTML do
"""
use ChesstrainerWeb, :html
alias Chesstrainer.Accounts.Scope
embed_templates "error_html/*"
@doc """
@@ -22,7 +24,7 @@ defmodule ChesstrainerWeb.ErrorHTML do
attr :title, :string, required: true
attr :message, :string, required: true
attr :hint, :string, default: nil
attr :puzzles, :boolean, default: true
attr :current_scope, :map, default: nil
def error_page(assigns) do
~H"""
@@ -36,7 +38,7 @@ defmodule ChesstrainerWeb.ErrorHTML do
<.pill_button variant={:primary} href={~p"/"}>
Back to home <.icon_arrow />
</.pill_button>
<.pill_button :if={@puzzles} variant={:light} href={~p"/endgames"}>
<.pill_button :if={Scope.premium?(@current_scope)} variant={:light} href={~p"/endgames"}>
Browse puzzles
</.pill_button>
</div>
@@ -33,6 +33,7 @@
status={404}
title="This page isn't on the board"
message="The page you were looking for moved, or never existed. Check the address, or head back to the trainer."
current_scope={assigns[:current_scope]}
/>
<Layouts.footer />
@@ -34,6 +34,7 @@
title="Something went wrong"
message="An unexpected error stopped this page from loading. It's on us, not you — please try again in a moment."
hint={"If it keeps happening, email #{Branding.support_email()}."}
current_scope={assigns[:current_scope]}
/>
<Layouts.footer />
@@ -4,4 +4,5 @@
status={404}
title="This page isn't on the board"
message="The page you were looking for moved, or never existed. Check the address, or head back to the trainer."
current_scope={@current_scope}
/>
@@ -9,6 +9,7 @@ defmodule ChesstrainerWeb.EndgameLive.Train do
use ChesstrainerWeb, :live_view
alias Chesstrainer.Accounts.Scope
alias Chesstrainer.Puzzles
alias ChesstrainerWeb.EndgameLive.PlayCore
alias ChesstrainerWeb.PlayComponents
@@ -31,7 +32,7 @@ defmodule ChesstrainerWeb.EndgameLive.Train do
<.icon name="hero-x-mark" /> Stop session
</.button>
<.button
:if={premium?(@current_scope)}
:if={Scope.premium?(@current_scope)}
id="puzzle-search"
navigate={~p"/endgames"}
>
@@ -310,9 +311,6 @@ defmodule ChesstrainerWeb.EndgameLive.Train do
%{user | rating: socket.assigns.user_rating || user.rating}
end
defp premium?(%{user: %{plan: :premium}}), do: true
defp premium?(_scope), do: false
defp summarise(session, rating) do
%{
difficulty: session.difficulty,