Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit 3dffc0a

Browse files
committed
fix(c11n): sidebar index should have no def-value
1 parent 6c505ec commit 3dffc0a

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

lib/mastani_server_web/resolvers/accounts_resolver.ex

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,7 @@ defmodule MastaniServerWeb.Resolvers.Accounts do
6262
# end
6363

6464
def set_customization(_root, ~m(customization)a = args, %{context: %{cur_user: cur_user}}) do
65-
sidebar_communities_index =
66-
try do
67-
args
68-
|> Map.get(:sidebar_communities_index, [])
69-
|> Enum.map(fn %{community: c, index: i} -> {c, i} end)
70-
|> Map.new()
71-
rescue
72-
_ -> %{}
73-
end
74-
75-
customization =
76-
Map.merge(customization, %{sidebar_communities_index: sidebar_communities_index})
77-
65+
customization = add_c11n_communities_index_ifneed(args)
7866
Accounts.set_customization(cur_user, customization)
7967
end
8068

@@ -285,4 +273,25 @@ defmodule MastaniServerWeb.Resolvers.Accounts do
285273
def search_users(_root, %{name: name}, _info) do
286274
Accounts.search_users(%{name: name})
287275
end
276+
277+
defp add_c11n_communities_index_ifneed(~m(customization)a = args) do
278+
case Map.has_key?(args, :sidebar_communities_index) do
279+
true ->
280+
sidebar_communities_index =
281+
try do
282+
args
283+
|> Map.get(:sidebar_communities_index, [])
284+
|> Enum.map(fn %{community: c, index: i} -> {c, i} end)
285+
|> Map.new()
286+
rescue
287+
_ -> %{}
288+
end
289+
290+
customization =
291+
Map.merge(customization, %{sidebar_communities_index: sidebar_communities_index})
292+
293+
false ->
294+
customization
295+
end
296+
end
288297
end

0 commit comments

Comments
 (0)