mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-10-06 03:34:57 +08:00
Reset autosave interval when changing file system (#1689)
This commit is contained in:
parent
5f6e7176fc
commit
5d651cf5c7
1 changed files with 19 additions and 33 deletions
|
@ -112,10 +112,6 @@ defmodule LivebookWeb.SessionLive.PersistenceLive do
|
||||||
end
|
end
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def handle_event("clear_file", %{}, socket) do
|
|
||||||
{:noreply, socket |> put_new_file(nil) |> assign(draft_file: nil)}
|
|
||||||
end
|
|
||||||
|
|
||||||
def handle_event(
|
def handle_event(
|
||||||
"set_options",
|
"set_options",
|
||||||
%{"persist_outputs" => persist_outputs, "autosave_interval_s" => autosave_interval_s},
|
%{"persist_outputs" => persist_outputs, "autosave_interval_s" => autosave_interval_s},
|
||||||
|
@ -143,7 +139,24 @@ defmodule LivebookWeb.SessionLive.PersistenceLive do
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def handle_info({:set_file, file, _file_info}, socket) do
|
def handle_info({:set_file, file, _file_info}, socket) do
|
||||||
{:noreply, assign(socket, draft_file: file)}
|
current_file_system = socket.assigns.draft_file.file_system
|
||||||
|
|
||||||
|
autosave_interval_s =
|
||||||
|
case file.file_system do
|
||||||
|
^current_file_system ->
|
||||||
|
socket.assigns.new_attrs.autosave_interval_s
|
||||||
|
|
||||||
|
%FileSystem.Local{} ->
|
||||||
|
Livebook.Notebook.default_autosave_interval_s()
|
||||||
|
|
||||||
|
_other ->
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
|
{:noreply,
|
||||||
|
socket
|
||||||
|
|> assign(draft_file: file)
|
||||||
|
|> put_new_attr(:autosave_interval_s, autosave_interval_s)}
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_info(:confirm_file, socket) do
|
def handle_info(:confirm_file, socket) do
|
||||||
|
@ -166,9 +179,7 @@ defmodule LivebookWeb.SessionLive.PersistenceLive do
|
||||||
Session.set_notebook_attributes(assigns.session.pid, diff)
|
Session.set_notebook_attributes(assigns.session.pid, diff)
|
||||||
end
|
end
|
||||||
|
|
||||||
if draft_file do
|
Session.save_sync(assigns.session.pid)
|
||||||
Session.save_sync(assigns.session.pid)
|
|
||||||
end
|
|
||||||
|
|
||||||
{:noreply, push_patch(socket, to: Routes.session_path(socket, :page, assigns.session.id))}
|
{:noreply, push_patch(socket, to: Routes.session_path(socket, :page, assigns.session.id))}
|
||||||
end
|
end
|
||||||
|
@ -180,31 +191,6 @@ defmodule LivebookWeb.SessionLive.PersistenceLive do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp put_new_file(socket, file) do
|
|
||||||
new_attrs = socket.assigns.new_attrs
|
|
||||||
current_file_system = new_attrs.file && new_attrs.file.file_system
|
|
||||||
new_file_system = file && file.file_system
|
|
||||||
|
|
||||||
autosave_interval_s =
|
|
||||||
case new_file_system do
|
|
||||||
^current_file_system ->
|
|
||||||
new_attrs.autosave_interval_s
|
|
||||||
|
|
||||||
nil ->
|
|
||||||
Livebook.Notebook.default_autosave_interval_s()
|
|
||||||
|
|
||||||
%FileSystem.Local{} ->
|
|
||||||
Livebook.Notebook.default_autosave_interval_s()
|
|
||||||
|
|
||||||
_other ->
|
|
||||||
nil
|
|
||||||
end
|
|
||||||
|
|
||||||
socket
|
|
||||||
|> put_new_attr(:file, file)
|
|
||||||
|> put_new_attr(:autosave_interval_s, autosave_interval_s)
|
|
||||||
end
|
|
||||||
|
|
||||||
defp put_new_attr(socket, key, value) do
|
defp put_new_attr(socket, key, value) do
|
||||||
new_attrs = socket.assigns.new_attrs
|
new_attrs = socket.assigns.new_attrs
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue