Skip to content

Commit fe58e27

Browse files
committed
Add route to show specific <chap, verse>
1 parent c6e5c66 commit fe58e27

File tree

4 files changed

+56
-2
lines changed

4 files changed

+56
-2
lines changed

lib/vyasa/corpus/gita.ex

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,26 @@ defmodule Vyasa.Corpus.Gita do
5050
@verses[String.to_atom(to_string(chapter_no))]
5151
|> Enum.map(&struct!(Gita.Verse, &1))
5252
end
53+
5354
def verses(chapter_no) do
5455
@verses[String.to_atom(chapter_no)]
5556
|> Enum.map(&struct!(Gita.Verse, &1))
5657
end
5758

59+
def verse(chapter_no, verse_no) when is_binary(verse_no) and is_binary(chapter_no) do
60+
IO.puts("testing... #{chapter_no}, #{verse_no} \n\n")
61+
62+
verse = @verses[String.to_atom(chapter_no)]
63+
|> Enum.find(fn %{:verse_number => verse_num} -> Integer.to_string(verse_num) === verse_no end)
64+
65+
IO.inspect(verse)
66+
67+
verse
68+
end
69+
70+
def verse(_,_) do
71+
%Vyasa.Corpus.Gita.Verse{}
72+
73+
end
74+
5875
end

lib/vyasa_web/live/gita_live/show.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ defmodule VyasaWeb.GitaLive.Show do
2626
end
2727
#<.link patch={~p"/gita/#{@chapter.id}"} phx-click={JS.push_focus()}> <.button>Annotate</.button> </.link>
2828
@impl true
29-
def handle_params(%{"id" => id}, _, socket) do
29+
def handle_params(%{"chapter_id" => id}, _, socket) do
3030
{:noreply, socket
3131
|> assign(:chapter, Gita.chapters(id))
3232
|> stream(:verses, Gita.verses(id))}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
defmodule VyasaWeb.GitaLive.ShowVerse do
2+
use VyasaWeb, :live_view
3+
alias Vyasa.Corpus.Gita
4+
5+
@impl true
6+
def mount(_params, _session, socket) do
7+
{:ok, socket}
8+
end
9+
10+
@impl true
11+
def render(assigns) do
12+
~H"""
13+
<.header >
14+
<:subtitle><%= @verse.chapter_number %>:<%= @verse.verse_number %></:subtitle>
15+
<p class="font-dn text-2xl"><%= @verse.text |> String.split("।।") |> List.first() %></p>
16+
</.header>
17+
<br/>
18+
<p><%= @verse.transliteration %></p>
19+
<br/>
20+
<p><%= @verse.word_meanings %></p>
21+
22+
<.back navigate={~p"/gita/#{@verse.chapter_number}"}>Back to Gita Chapter <%= @verse.chapter_number%></.back>
23+
<.back navigate={~p"/gita"}>Back to Gita</.back>
24+
"""
25+
end
26+
27+
# <.link patch={~p"/gita/#{@chapter.id}"} phx-click={JS.push_focus()}> <.button>Annotate</.button> </.link>
28+
@impl true
29+
def handle_params(%{"chapter_id" => chapter_no, "verse_id" => verse_no}, _, socket) do
30+
{:noreply,
31+
socket
32+
|> assign(:chapter, Gita.chapters(chapter_no))
33+
|> stream(:verses, Gita.verses(chapter_no))
34+
|> assign(:verse, Gita.verse(chapter_no, verse_no))}
35+
end
36+
end

lib/vyasa_web/router.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ defmodule VyasaWeb.Router do
1919

2020
get "/", PageController, :home
2121
live "/gita/", GitaLive.Index, :index
22-
live "/gita/:id", GitaLive.Show, :show
22+
live "/gita/:chapter_id", GitaLive.Show, :show
23+
live "/gita/:chapter_id/:verse_id", GitaLive.ShowVerse, :show_verse
2324
live "/texts", TextLive.Index, :index
2425
live "/texts/new", TextLive.Index, :new
2526
live "/texts/:id/edit", TextLive.Index, :edit

0 commit comments

Comments
 (0)