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

App html show html style fix #21

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25,663 changes: 0 additions & 25,663 deletions .elixir-tools/next-ls.log

This file was deleted.

44 changes: 44 additions & 0 deletions .github/check-format-and-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Check Format and Run Tests

on:
pull_request:
paths:
- '**/*.ex'
- '**/*.exs'
- 'mix.exs'
- '.formatter.exs'

jobs:
format-and-test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Elixir
uses: erlef/setup-elixir@v2
with:
elixir-version: '1.14'
otp-version: '25'

- name: Debug Environment
run: |
mix --version
elixir --version
otp --version
env

- name: Install dependencies
run: mix deps.get

- name: Check code formatting
run: |
mix format --check-formatted
if [ $? -ne 0 ]; then
echo "Code is not formatted correctly. Please run 'mix format' and commit your changes."
exit 1
fi

- name: Run tests
run: mix test
30 changes: 30 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,33 @@ polly-*.tar
npm-debug.log
/assets/node_modules/

.elixir_ls/
*.plt
credo_report/
.elixir-tools

# Ignore directories created by editors and IDEs
*.swp
*.swo
.idea/
.vscode/
*.sublime-project
*.sublime-workspace

# Ignore node_modules (if using assets with Node.js)
assets/node_modules/

# Ignore logs and temporary files
/log
/tmp

# Ignore secrets and environment variables
config/*.secret.exs
.env
.env.*

# Ignore compiled output
*.beam
*.ez

.elixir-tools/
4 changes: 4 additions & 0 deletions assets/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@
overflow: hidden;
clip: rect(0, 0, 0, 0);
border: 0;
}

.flex-col {
flex-direction: column;
}
5 changes: 3 additions & 2 deletions lib/polly/polls.ex
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ defmodule Polly.Polls do
|> do_update_poll(poll)
end

defp do_update_poll({:ok, %Poll{} = updated_poll}, _poll) do
:ok = Polly.PollsManager.update_poll(updated_poll)
defp do_update_poll({:ok, %Poll{} = updated_poll}, poll_id) do
:ok = Polly.PollsManager.update_poll(poll_id, updated_poll)
{:ok, updated_poll}
end


defp do_update_poll({:error, changeset}, _poll) do
{:error, changeset}
end
Expand Down
24 changes: 11 additions & 13 deletions lib/polly/polls_manager.ex
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
defmodule Polly.PollsManager do
alias Polly.Schema.Poll
# alias Polly.StorageBehaviour

@storage_module Application.compile_env(:polly, :storage_module, Polly.ETSStorage)

def init() do
@storage_module.init()
end
Expand All @@ -21,7 +20,7 @@ defmodule Polly.PollsManager do
end
end

@spec list_polls_with_ids :: Keyword.t()
@spec list_polls_with_ids() :: Keyword.t()
def list_polls_with_ids() do
@storage_module.list_polls_with_ids()
|> Enum.map(fn {id, poll} ->
Expand Down Expand Up @@ -73,21 +72,20 @@ defmodule Polly.PollsManager do

@spec update_poll(binary(), Poll.t()) :: :ok | {:error, atom()}
def update_poll(poll_id, %Poll{} = updated_poll) do
if @storage_module.get_poll!(poll_id) do
@storage_module.update_poll(poll_id, updated_poll)
else
{:error, :poll_not_found}
try do
if @storage_module.get_poll!(poll_id) do
@storage_module.update_poll(poll_id, updated_poll)
else
{:error, :poll_not_found}
end
rescue
ArgumentError ->
{:error, :poll_not_found}
end
end

@spec change_poll(Poll.t(), map()) :: Ecto.Changeset.t()
def change_poll(%Poll{} = poll, attrs \\ %{}) do
Poll.changeset(poll, attrs)
end


@spec update_poll(Poll.t()) :: :ok | {:error, any()}
def update_poll(%Poll{} = _poll) do
# Your ETS or other storage logic to update the poll
end
end
1 change: 0 additions & 1 deletion lib/polly/storage/behaviour.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ defmodule Polly.StorageBehaviour do
@callback safe_lookup_element(binary()) :: integer()
@callback update_poll(binary(), Poll.t()) :: :ok | {:error, atom()}
# @callback replace_option_votes(Poll.t(), boolean()) :: Poll.t()

end
24 changes: 20 additions & 4 deletions lib/polly/storage/ets_storage.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,21 @@ defmodule Polly.ETSStorage do
@impl Polly.StorageBehaviour
def init() do
:ets.new(@polls, [:public, :named_table, write_concurrency: true, read_concurrency: true])
:ets.new(@polls_votes, [:public, :named_table, write_concurrency: true, read_concurrency: true])
:ets.new(@polls_options_votes, [:public, :named_table, write_concurrency: true, read_concurrency: true])

:ets.new(@polls_votes, [
:public,
:named_table,
write_concurrency: true,
read_concurrency: true
])

:ets.new(@polls_options_votes, [
:public,
:named_table,
write_concurrency: true,
read_concurrency: true
])

:ok
end

Expand Down Expand Up @@ -53,14 +66,17 @@ defmodule Polly.ETSStorage do

@impl Polly.StorageBehaviour
def get_poll_votes!(poll_id) do
:ets.lookup_element(@polls_votes, poll_id, 2)
case :ets.lookup(:polls_votes, poll_id) do
[{^poll_id, votes}] -> votes
[] -> []
end
end

def replace_option_votes(poll, true) do
updated_options =
Enum.map(poll.options, fn option ->
Map.replace(option, :votes, safe_lookup_element(option.id))
end)

Map.replace(poll, :options, updated_options)
end

Expand Down
31 changes: 21 additions & 10 deletions lib/polly_web/components/core_components.ex
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ defmodule PollyWeb.CoreComponents do
<.icon name="hero-x-mark-solid" class="h-5 w-5" />
</button>
</div>

<div id={"#{@id}-content"}>
<%= render_slot(@inner_block) %>
</div>
Expand Down Expand Up @@ -121,10 +122,11 @@ defmodule PollyWeb.CoreComponents do
>
<p :if={@title} class="flex items-center gap-1.5 text-sm font-semibold leading-6">
<.icon :if={@kind == :info} name="hero-information-circle-mini" class="h-4 w-4" />
<.icon :if={@kind == :error} name="hero-exclamation-circle-mini" class="h-4 w-4" />
<%= @title %>
<.icon :if={@kind == :error} name="hero-exclamation-circle-mini" class="h-4 w-4" /> <%= @title %>
</p>

<p class="mt-2 text-sm leading-5"><%= msg %></p>

<button type="button" class="group absolute top-1 right-1 p-2" aria-label={gettext("close")}>
<.icon name="hero-x-mark-solid" class="h-5 w-5 opacity-40 group-hover:opacity-70" />
</button>
Expand Down Expand Up @@ -286,9 +288,9 @@ defmodule PollyWeb.CoreComponents do
checked={@checked}
class="rounded border-zinc-300 text-zinc-900 focus:ring-0"
{@rest}
/>
<%= @label %>
/> <%= @label %>
</label>

<.error :for={msg <- @errors}><%= msg %></.error>
</div>
"""
Expand All @@ -298,6 +300,7 @@ defmodule PollyWeb.CoreComponents do
~H"""
<div phx-feedback-for={@name}>
<.label for={@id}><%= @label %></.label>

<select
id={@id}
name={@name}
Expand All @@ -306,8 +309,9 @@ defmodule PollyWeb.CoreComponents do
{@rest}
>
<option :if={@prompt} value=""><%= @prompt %></option>
<%= Phoenix.HTML.Form.options_for_select(@options, @value) %>
<%= Phoenix.HTML.Form.options_for_select(@options, @value) %>
</select>

<.error :for={msg <- @errors}><%= msg %></.error>
</div>
"""
Expand All @@ -317,7 +321,7 @@ defmodule PollyWeb.CoreComponents do
~H"""
<div phx-feedback-for={@name}>
<.label for={@id}><%= @label %></.label>
<textarea
<textarea
id={@id}
name={@name}
class={[
Expand All @@ -338,6 +342,7 @@ defmodule PollyWeb.CoreComponents do
~H"""
<div phx-feedback-for={@name}>
<.label for={@id}><%= @label %></.label>

<input
type={@type}
name={@name}
Expand Down Expand Up @@ -378,8 +383,9 @@ defmodule PollyWeb.CoreComponents do
def error(assigns) do
~H"""
<p class="mt-3 flex gap-3 text-sm leading-6 text-rose-600 phx-no-feedback:hidden">
<.icon name="hero-exclamation-circle-mini" class="mt-0.5 h-5 w-5 flex-none" />
<%= render_slot(@inner_block) %>
<.icon name="hero-exclamation-circle-mini" class="mt-0.5 h-5 w-5 flex-none" /> <%= render_slot(
@inner_block
) %>
</p>
"""
end
Expand All @@ -400,10 +406,12 @@ defmodule PollyWeb.CoreComponents do
<h1 class="text-xl font-semibold leading-8 text-zinc-800">
<%= render_slot(@inner_block) %>
</h1>

<p :if={@subtitle != []} class="mt-2 text-md leading-6 text-zinc-600">
<%= render_slot(@subtitle) %>
</p>
</div>

<div class="flex-none"><%= render_slot(@actions) %></div>
</header>
"""
Expand Down Expand Up @@ -446,9 +454,11 @@ defmodule PollyWeb.CoreComponents do
<thead class="text-sm text-left leading-6 text-zinc-500">
<tr>
<th :for={col <- @col} class="p-0 pr-6 pb-4 font-normal"><%= col[:label] %></th>

<th class="relative p-0 pb-4"><span class="sr-only"><%= gettext("Actions") %></span></th>
</tr>
</thead>

<tbody
id={@id}
phx-update={match?(%Phoenix.LiveView.LiveStream{}, @rows) && "stream"}
Expand All @@ -467,6 +477,7 @@ defmodule PollyWeb.CoreComponents do
</span>
</div>
</td>

<td :if={@action != []} class="relative w-14 p-0">
<div class="relative whitespace-nowrap py-4 text-right text-sm font-medium">
<span class="absolute -inset-y-px -right-4 left-0 group-hover:bg-zinc-50 sm:rounded-r-xl" />
Expand Down Expand Up @@ -505,6 +516,7 @@ defmodule PollyWeb.CoreComponents do
<dl class="-my-4 divide-y divide-zinc-100">
<div :for={item <- @item} class="flex gap-4 py-4 text-sm leading-6 sm:gap-8">
<dt class="w-1/4 flex-none text-zinc-500"><%= item.title %></dt>

<dd class="text-zinc-700"><%= render_slot(item) %></dd>
</div>
</dl>
Expand All @@ -529,8 +541,7 @@ defmodule PollyWeb.CoreComponents do
navigate={@navigate}
class="text-sm font-semibold leading-6 text-zinc-900 hover:text-zinc-700"
>
<.icon name="hero-arrow-left-solid" class="h-3 w-3" />
<%= render_slot(@inner_block) %>
<.icon name="hero-arrow-left-solid" class="h-3 w-3" /> <%= render_slot(@inner_block) %>
</.link>
</div>
"""
Expand Down
Loading