Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix scrolling bug, enforce 3 level nesting in sheaf replies #135

Open
wants to merge 10 commits into
base: feat/context-gate/discuss-ui-state-handling
Choose a base branch
from
4 changes: 4 additions & 0 deletions lib/vyasa/sangh.ex
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,8 @@ defmodule Vyasa.Sangh do

# """
def update_sheaf(%Sheaf{} = sheaf, attrs) do
IO.puts("CHECKPOINT: update_sheaf")

sheaf
|> Sheaf.mutate_changeset(attrs)
|> Repo.update()
Expand All @@ -421,6 +423,8 @@ defmodule Vyasa.Sangh do
# """

def update_sheaf!(%Sheaf{} = sheaf, attrs) do
IO.puts("CHECKPOINT: update_sheaf!")

sheaf
|> Sheaf.mutate_changeset(attrs)
|> Repo.update!()
Expand Down
26 changes: 18 additions & 8 deletions lib/vyasa/sangh/sheaf.ex
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,19 @@ defmodule Vyasa.Sangh.Sheaf do
end

def mutate_changeset(%Sheaf{} = sheaf, attrs) do
sheaf
|> Vyasa.Repo.preload([:marks])
|> cast(attrs, [:id, :body, :active, :signature, :traits])
|> cast_path(attrs)
|> assoc_marks(attrs)
|> Map.put(:repo_opts, on_conflict: {:replace_all_except, [:id]}, conflict_target: :id)
|> validate_include_subset(:traits, ["personal", "draft", "published"])
IO.inspect(%{sheaf: sheaf, attrs: attrs}, label: "CHECKPOINT: mutate_changeset")

cs =
sheaf
|> Vyasa.Repo.preload([:marks])
|> cast(attrs, [:id, :body, :active, :signature, :traits])
|> cast_path(attrs)
|> assoc_marks(attrs)
|> Map.put(:repo_opts, on_conflict: {:replace_all_except, [:id]}, conflict_target: :id)
|> validate_include_subset(:traits, ["personal", "draft", "published"])

IO.inspect(cs, label: "CHECKPOINT: mutate changeset outcome changeset:")
cs
end

defp assoc_marks(sheaf, %{marks: [%Mark{} | _] = marks}) do
Expand All @@ -87,13 +93,17 @@ defmodule Vyasa.Sangh.Sheaf do
end

defp cast_path(%{changes: %{id: sheaf_id}} = sheaf, %{
parent: %Sheaf{id: p_sheaf_id, path: lpath}
parent: %Sheaf{id: p_sheaf_id, path: lpath} = parent
}) do
IO.inspect(parent, label: "SEE ME : cast_path, parent:")

sheaf
|> cast(%{parent_id: p_sheaf_id, path: encode_path(sheaf_id, lpath)}, [:parent_id, :path])
end

defp cast_path(%{changes: %{id: sheaf_id}} = sheaf, _) do
IO.inspect(sheaf, label: "SEE ME : cast_path, sheaf:")

sheaf
|> cast(%{path: encode_path(sheaf_id)}, [:path])
end
Expand Down
9 changes: 7 additions & 2 deletions lib/vyasa_web/components/contexts/discuss.ex
Original file line number Diff line number Diff line change
Expand Up @@ -597,8 +597,13 @@ defmodule VyasaWeb.Context.Discuss do
end

# FIXME: @ks0m1c this update function should be updating the parent for the current draft sheaf, but it doesn't seem to be
# doing so right now, can I leave this to you to check why the update isn't happening?
# else i'll eventually come back to it.
# doing so right now
# what it needs to do:
# 1. remove assoc b/w old parent and this sheaf
# 2. create new assoc b/w new parent and this sheaf:
# - updates path of child
IO.puts("CHECKPOINT: before updating sheaf")
Comment on lines 615 to +621
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need some support on this @ks0m1c


updated_draft_sheaf =
draft_sheaf
|> Sangh.update_sheaf!(%{
Expand Down