diff --git a/lib/accumulator/notes.ex b/lib/accumulator/notes.ex index 8c9f4a4..6182438 100644 --- a/lib/accumulator/notes.ex +++ b/lib/accumulator/notes.ex @@ -86,6 +86,12 @@ defmodule Accumulator.Notes do Repo.all(Workspace) |> Enum.map(&convert_timestamps_tz/1) end + def get_public_workspaces() do + from(w in Workspace, where: w.is_public == true) + |> Repo.all() + |> Enum.map(&convert_timestamps_tz/1) + end + def get_workspace_by_id(id) do Repo.get!(Workspace, id) end @@ -99,8 +105,7 @@ defmodule Accumulator.Notes do %Workspace{} |> Workspace.changeset(params) |> Repo.insert() end - def rename_workspace(id, params) do - # TODO: think about writing a query instead that changes the name without getting the workspace by its id first + def update_workspace(id, params) do get_workspace_by_id(id) |> Workspace.changeset(params) |> Repo.update() diff --git a/lib/accumulator/notes/workspace.ex b/lib/accumulator/notes/workspace.ex index 755255a..5fa9cdc 100644 --- a/lib/accumulator/notes/workspace.ex +++ b/lib/accumulator/notes/workspace.ex @@ -4,13 +4,14 @@ defmodule Accumulator.Notes.Workspace do schema "workspaces" do field(:title, :string) + field(:is_public, :boolean) has_many(:notes, Accumulator.Notes.Note) timestamps(type: :utc_datetime) end def changeset(workspace, params \\ %{}) do workspace - |> cast(params, [:title]) + |> cast(params, [:title, :is_public]) |> validate_length(:title, min: 2) end end diff --git a/lib/accumulator_web/components/layouts/root.html.heex b/lib/accumulator_web/components/layouts/root.html.heex index d92934c..643fddd 100644 --- a/lib/accumulator_web/components/layouts/root.html.heex +++ b/lib/accumulator_web/components/layouts/root.html.heex @@ -25,6 +25,7 @@ <.navbar_link to={~p"/redirect"} label="redirect" /> <.navbar_link :if={@current_user} to={~p"/bin"} label="bin" /> <.navbar_link :if={@current_user} to={~p"/notes"} label="notes" /> + <.navbar_link :if={!@current_user} to={~p"/notes/public/default"} label="notes" /> <.navbar_link :if={@current_user} to={~p"/sessions"} label="session" /> <.navbar_link :if={@current_user} to={~p"/livedashboard"} label="livedashboard" /> diff --git a/lib/accumulator_web/live/notes_live/notes_live.ex b/lib/accumulator_web/live/notes_live/notes_live.ex index 40ae32f..a40bab9 100644 --- a/lib/accumulator_web/live/notes_live/notes_live.ex +++ b/lib/accumulator_web/live/notes_live/notes_live.ex @@ -19,7 +19,6 @@ defmodule AccumulatorWeb.NotesLive do form: create_empty_form(:note), workspace_form: nil, editing_note_id: nil, - uploaded_files: [], search: to_form(%{"search" => ""}), page_error: nil, # Existing note editing state @@ -269,7 +268,7 @@ defmodule AccumulatorWeb.NotesLive do socket = if workspace_edit_id != nil do - case Notes.rename_workspace(workspace_edit_id, workspace_params) do + case Notes.update_workspace(workspace_edit_id, workspace_params) do {:ok, _} -> workspaces = Notes.get_all_workspaces() diff --git a/lib/accumulator_web/live/notes_live/notes_live.html.heex b/lib/accumulator_web/live/notes_live/notes_live.html.heex index f82213a..7e00a99 100644 --- a/lib/accumulator_web/live/notes_live/notes_live.html.heex +++ b/lib/accumulator_web/live/notes_live/notes_live.html.heex @@ -62,6 +62,7 @@ phx-submit="workspace-form-submit" > <.input label="Title" field={@workspace_form[:title]} /> + <.input type="checkbox" label="Public?" field={@workspace_form[:is_public]} /> <.button>Save diff --git a/lib/accumulator_web/live/notes_live/notes_public_live.ex b/lib/accumulator_web/live/notes_live/notes_public_live.ex new file mode 100644 index 0000000..700e114 --- /dev/null +++ b/lib/accumulator_web/live/notes_live/notes_public_live.ex @@ -0,0 +1,167 @@ +defmodule AccumulatorWeb.NotesPublicLive do + use AccumulatorWeb, :live_view + + alias Accumulator.{Notes} + + @impl true + def render(assigns) do + ~H""" +