Skip to content

Commit

Permalink
Decide if choose is disabled on handle info
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin-Philip committed Dec 24, 2021
1 parent 3147714 commit 43a2cbc
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/livebook_web/live/session_live/persistence_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ defmodule LivebookWeb.SessionLive.PersistenceLive do
attrs: attrs,
new_attrs: attrs,
draft_file: nil,
choose_disabled: nil,
saved_file: nil
)}
end
Expand Down Expand Up @@ -116,7 +117,7 @@ defmodule LivebookWeb.SessionLive.PersistenceLive do
tabindex="-1">
Cancel
</button>
<%= unless String.at(@draft_file.path, -1) == "/" do %>
<%= unless @choose_disabled do %>
<button class="button-base button-blue"
phx-click="confirm_file"
tabindex="-1">
Expand Down Expand Up @@ -161,7 +162,8 @@ defmodule LivebookWeb.SessionLive.PersistenceLive do
@impl true
def handle_event("open_file_select", %{}, socket) do
file = socket.assigns.new_attrs.file || Livebook.Config.default_dir()
{:noreply, assign(socket, draft_file: file)}
choose_disabled = FileSystem.File.dir?(file)
{:noreply, assign(socket, draft_file: file, choose_disabled: choose_disabled)}
end

def handle_event("close_file_select", %{}, socket) do
Expand Down Expand Up @@ -224,7 +226,8 @@ defmodule LivebookWeb.SessionLive.PersistenceLive do

@impl true
def handle_info({:set_file, file, _file_info}, socket) do
{:noreply, assign(socket, draft_file: file)}
choose_disabled = FileSystem.File.dir?(file)
{:noreply, assign(socket, draft_file: file, choose_disabled: choose_disabled)}
end

def handle_info(:confirm_file, socket) do
Expand Down

0 comments on commit 43a2cbc

Please sign in to comment.