noahsettersten commited on
Commit
8f4c6f0
1 Parent(s): aaa724e

refactor: Clean up state in HomeLive.Index mount/3 call

Browse files
lib/medical_transcription_web/live/home_live/index.ex CHANGED
@@ -1,21 +1,21 @@
1
  defmodule MedicalTranscriptionWeb.HomeLive.Index do
2
  use MedicalTranscriptionWeb, :live_view
3
- # alias MedicalTranscriptionWeb.HomeLive.Index.SampleResults
4
 
5
  @impl Phoenix.LiveView
6
  def mount(_params, _session, socket) do
7
  # We're storing atoms in `:status` as LiveView's AsyncResult doesn't support modeling a "pending" state, but only
8
  # loading / ok / failed.
 
 
 
 
 
 
 
9
  socket =
10
  socket
11
- |> assign(:current_recording_id, 0)
12
- |> assign(:uploaded_file_name, nil)
13
- |> assign(:status, :pending)
14
- |> assign(:summary_keywords, [])
15
  |> stream(:transcription_rows, [])
16
- # To test the success UI, replace the two lines above with these:
17
- # |> stream(:transcription_rows, SampleResults.get_sample_results())
18
- # |> assign(:status, :success)
19
  |> allow_upload(:audio, accept: ~w(.mp3), max_entries: 1)
20
 
21
  {:ok, socket}
 
1
  defmodule MedicalTranscriptionWeb.HomeLive.Index do
2
  use MedicalTranscriptionWeb, :live_view
 
3
 
4
  @impl Phoenix.LiveView
5
  def mount(_params, _session, socket) do
6
  # We're storing atoms in `:status` as LiveView's AsyncResult doesn't support modeling a "pending" state, but only
7
  # loading / ok / failed.
8
+ initial_state = %{
9
+ current_recording_id: 0,
10
+ uploaded_file_name: nil,
11
+ status: :pending,
12
+ summary_keywords: []
13
+ }
14
+
15
  socket =
16
  socket
17
+ |> assign(initial_state)
 
 
 
18
  |> stream(:transcription_rows, [])
 
 
 
19
  |> allow_upload(:audio, accept: ~w(.mp3), max_entries: 1)
20
 
21
  {:ok, socket}
lib/medical_transcription_web/live/home_live/sample_results.ex CHANGED
@@ -1,6 +1,14 @@
1
  defmodule MedicalTranscriptionWeb.HomeLive.Index.SampleResults do
2
  @moduledoc """
3
  Contains sample data that can be displayed in HomeLive for prototyping UI.
 
 
 
 
 
 
 
 
4
  """
5
 
6
  alias AudioTagger.Structs.TagResult
 
1
  defmodule MedicalTranscriptionWeb.HomeLive.Index.SampleResults do
2
  @moduledoc """
3
  Contains sample data that can be displayed in HomeLive for prototyping UI.
4
+
5
+ To test the success UI, replace the status assignment with:
6
+
7
+ status: :success
8
+
9
+ And the `transcription_rows` stream with:
10
+
11
+ |> stream(:transcription_rows, MedicalTranscriptionWeb.HomeLive.Index.SampleResults.get_sample_results())
12
  """
13
 
14
  alias AudioTagger.Structs.TagResult