Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix mounting woes by rendering content as live_component within DM (#86)
basically took the whole day, a bunch of refactoring has happened # How to Verify / Test 1. navigate through the thing, if you change the mode then navigate into other parts of the content (e.g. :show_sources -> :show_chapters -> :show_verses) then the ControlPanel mode should be the same, no dismount and remounting or anything either 2. handshake gets done properly. The handshake will init when you're in the :show_verses content view and only then does the audio load. Note that once the audio is loaded, any content navigation will never kill the audio playback either. In fact the audio playback will continue and scribing and all that fun stuff will still happen # Workplan Notes ``` ***** Approach 2: ContentLiveview :LOGBOOK: CLOCK: [2024-08-16 Fri 08:39]--[2024-08-16 Fri 17:39] => 9:00 :END: ****** Test: 1. navigate through content without overlay states being affected ****** 0. Redefine Router, let everything point to DM ****** 1. Add content liveview - all 3 added - [LOW IMPORTANCE] TOVERIFY: seems like it's correct to preload the stream content @ the liveview then pass it onto a live_component? ([[https://elixirforum.com/t/how-to-use-phoenix-1-7-streams-on-livecomponent-preload/54454][ref]]) my own implementations: PRELOAD @ #+begin_src elixir # preload @ display_manager/display_live defp apply_action( %Socket{} = socket, :show_chapters, %{"source_title" => source_title} = params ) do [%Chapter{source: src} | _] = chapters = Written.get_chapters_by_src(source_title) socket |> assign(:content_action, :show_chapters) |> assign(:page_title, to_title_case(src.title)) |> assign(:source, src) |> assign(:meta, %{ title: to_title_case(src.title), description: "Explore the #{to_title_case(src.title)}", type: "website", image: url(~p"/og/#{VyasaWeb.OgImageController.get_by_binding(%{source: src})}"), url: url(socket, ~p"/explore/#{src.title}") }) |> stream_configure(:chapters, dom_id: &"Chapter-#{&1.no}") |> stream(:chapters, chapters |> Enum.sort_by(fn chap -> chap.no end)) end #+end_src INJECT INTO LIVE_COMPONENT: #+begin_src elixir <%= if @content_action == :show_chapters do%> <div> SHOW CHAPTERS <.live_component module={VyasaWeb.Content.Chapters} id={"content-sources"} source={@source} chapters={@streams.chapters} /> </div> <% end %> #+end_src ****** 2. defdelegate or add contentFetcher to separate out the repo logic SKIPPED this, not too important ****** 3. test the push_patch() for this WORKSSSS ``` ---- * [WIP]: basic DM, demo state & assigned components Still have no idea how the VyasaWeb.SourceLive.Chapter.Index is supposed to be rendered as @inner_content within the new display_manager.html.heex * Rename CommandGroup -> ControlPanel * Initial Wire up %UserMode{} to Control Panel * Switch modes, add user_mode.ex to tw config * Prevent full page-reloads via push_navigate() This prevents the socket from being killed at every navigation, so the overlay's states is still managed without any issue. Actually, currently, there's a issue with definitions on the router-side problem: if I do a push_navigate to the path matching =/explore/:source_title/:chap_no= from =/explore/:source_title/=, it will trigger a socket error: =phx-F-vfg0fv3-NR4yFB error: unauthorized live_redirect. Falling back to page request -= Hunch: it's because of the router defining two different live_session scopes (anon vs sangh) so it's not allowing a =push_navigate()= and hence it's reverting to a full page reload. Do you know a quick fix to this? live_session :gen_anon_session, on_mount: [{VyasaWeb.Session, :anon}] do live "/explore/", SourceLive.Index, :index live "/explore/:source_title/", SourceLive.Show, :show #live "/explore/:source_title/:chap_no", SourceLive.Chapter.Index, :index live "/explore/:source_title/:chap_no", SourceLive.Chapter.Index, :index live "/explore/:source_title/:chap_no/:verse_no", SourceLive.Chapter.ShowVerse, :show end live_session :gen_sangh_session, on_mount: [{VyasaWeb.Session, :sangh}] do live "/explore/:source_title/:chap_no", SourceLive.Chapter.Index, :index end * [temp] shift all from anon session to sangh sess * Minor changes * [WIP, Attempt] Shift from layout to heex template Still the thing dies on me * Trigger DIFF * Use DM @ router actions, load data :show_sources * Add data load for :show_chapters action on DM * Use push_patch() @ :show_sources -> :show_chapters * Handle data load & nav:show_chapters->:show_verses * Create VyasaWeb.Content.Verses live_component * Wire up handshakes successfully, shift to patches Also done: 1. use maybe_stream_configure/3 (see note in definition) 2. change backlinks from navigate -> patch so that a full-page reload is NOT done. This is also what allows the state of ControlPanel and ActionBar to be maintained despite going back and forth content. 3. actually wiring up the event handlers and stuff that allowed the handshakes to happen TODOs: 1. fix css nonsense with how the content is being displayed. 2. future iteration needs a cleanup, this module is too fat. * Fix css issues * More minor css fixes
- Loading branch information