@@ -4,65 +4,7 @@ defmodule DiffWeb.DiffLiveView do
44 require Logger
55
66 def render ( assigns ) do
7- ~H"""
8- <%= if assigns [ :error ] do %>
9- < div class = "message-container " >
10- < h2 class = "message " > Error</ h2 >
11- < p > <%= @ error %> </ p >
12- </ div >
13- <% else %>
14- <%= if assigns [ :view_mode ] == :diffs_list do %>
15- < div class = "search-area " >
16- < h1 class = "package-header " > Package Diffs</ h1 >
17- < div >
18- <%= for { package , from , to , url } <- @ diffs do %>
19- < div >
20- < a href = { url } class = "package-name " >
21- <%= package %> (<%= from %> → <%= to %> )
22- </ a >
23- </ div >
24- <% end %>
25- </ div >
26- </ div >
27- <% else %>
28- < div class = "search-area " >
29- < div class = "diff-stats-header " >
30- < span class = "files-changed " > <%= @ metadata . files_changed %> files changed</ span >
31- < span class = "additions " > +<%= @ metadata . total_additions %> </ span >
32- < span class = "deletions " > -<%= @ metadata . total_deletions %> </ span >
33- </ div >
34- </ div >
35-
36- <%= if @ generating do %>
37- < div class = "message-container " >
38- < div class = "message " > Generating diff patches...</ div >
39- </ div >
40- <% end %>
41-
42- <%= if @ loading do %>
43- < div class = "message-container " >
44- < div class = "message " > Loading patches...</ div >
45- </ div >
46- <% end %>
47-
48-
49-
50- < div class = "ghd-container " id = "patch-list " >
51- <%= for patch_id <- @ loaded_patches do %>
52- < div id = { "patch-#{ patch_id } " } >
53- <%= raw ( load_patch_content ( @ package , @ from , @ to , patch_id ) ) %>
54- </ div >
55- <% end %>
56-
57- <%= if @ has_more_patches do %>
58- < div id = "loading-trigger " phx-hook = "InfiniteScroll " data-loaded = { length ( @ loaded_patches ) } >
59- Loading more patches...
60- </ div >
61- <% end %>
62- </ div >
63- <% end %>
64- <% end %>
65- """
7+ Phoenix.View . render ( DiffWeb.LiveView , "diff.html" , assigns )
668 end
679
6810 # Mount for single diff view
@@ -430,58 +372,6 @@ defmodule DiffWeb.DiffLiveView do
430372 _ -> nil
431373 end
432374
433- defp load_patch_content ( package , from , to , patch_id ) do
434- case Diff.Storage . get_patch ( package , from , to , patch_id ) do
435- { :ok , raw_content } ->
436- # Parse the stored content based on format
437- case Jason . decode ( raw_content ) do
438- { :ok , % { "type" => "too_large" , "file" => file_path } } ->
439- # Handle legacy too_large patches
440- Phoenix.View . render_to_string ( DiffWeb.RenderView , "too_large.html" , file: file_path )
441- |> sanitize_utf8 ( )
442-
443- { :ok , % { "diff" => raw_diff , "path_from" => path_from , "path_to" => path_to } } ->
444- # Handle new format with raw diff and base paths for relative conversion
445- case GitDiff . parse_patch ( raw_diff , relative_from: path_from , relative_to: path_to ) do
446- { :ok , [ ] } ->
447- "<div class='patch-info'>No changes in patch</div>"
448-
449- { :ok , patches } ->
450- # Take the first patch (should only be one per file)
451- patch = List . first ( patches )
452-
453- Phoenix.View . render_to_string ( DiffWeb.RenderView , "patch.html" , patch: patch )
454- |> sanitize_utf8 ( )
455-
456- { :error , reason } ->
457- Logger . error ( "Failed to parse patch #{ patch_id } : #{ inspect ( reason ) } " )
458- "<div class='patch-error'>Failed to parse patch</div>"
459- end
460-
461- _ ->
462- # Fallback: try parsing as raw diff without relative paths (legacy raw format)
463- case GitDiff . parse_patch ( raw_content ) do
464- { :ok , [ ] } ->
465- "<div class='patch-info'>No changes in patch</div>"
466-
467- { :ok , patches } ->
468- # Take the first patch (should only be one per file)
469- patch = List . first ( patches )
470-
471- Phoenix.View . render_to_string ( DiffWeb.RenderView , "patch.html" , patch: patch )
472- |> sanitize_utf8 ( )
473-
474- { :error , reason } ->
475- Logger . error ( "Failed to parse patch #{ patch_id } : #{ inspect ( reason ) } " )
476- "<div class='patch-error'>Failed to parse patch</div>"
477- end
478- end
479-
480- { :error , _reason } ->
481- "<div class='patch-error'>Failed to load patch</div>"
482- end
483- end
484-
485375 defp parse_diff ( diff ) do
486376 case String . split ( diff , ":" , trim: true ) do
487377 [ app , from , to ] -> { app , from , to , build_url ( app , from , to ) }
0 commit comments