Skip to content

Commit

Permalink
Merge pull request #17 from daveminer/daisy-ui
Browse files Browse the repository at this point in the history
Daisy UI
  • Loading branch information
daveminer authored Jul 7, 2024
2 parents af28264 + c58091e commit 2f66429
Show file tree
Hide file tree
Showing 41 changed files with 683 additions and 503 deletions.
7 changes: 3 additions & 4 deletions .formatter.exs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
[
import_deps: [:ecto, :ecto_sql, :phoenix, :surface],
import_deps: [:ecto, :ecto_sql, :phoenix],
subdirectories: ["priv/*/migrations"],
plugins: [Phoenix.LiveView.HTMLFormatter, Surface.Formatter.Plugin],
plugins: [Phoenix.LiveView.HTMLFormatter],
inputs: [
"*.{heex,ex,exs}",
"{config,lib,test}/**/*.{heex,ex,exs}",
"priv/*/seeds.exs",
"{lib,test}/**/*.sface"
"priv/*/seeds.exs"
]
]
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@ npm-debug.log

# Ignore generated CSS file for components
assets/css/_components.css

# Editor config
.vscode/

1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ the following tools and patterns:
- [Phoenix Presence](https://hexdocs.pm/phoenix/presence.html)
- [Pow](https://github.com/pow-auth/pow)
- Search Autocomplete (in LiveView)
- [Surface UI](https://surface-ui.org/)
- [WebSockex](https://github.com/Azolo/websockex)

Basket also serves as a reference for testing patterns:
Expand Down
3 changes: 0 additions & 3 deletions assets/css/app.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/* Import scoped CSS rules for components */
@import "./_components.css";

@import "tailwindcss/base";
@import "tailwindcss/components";
@import "tailwindcss/utilities";
Expand Down
2 changes: 1 addition & 1 deletion assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import "phoenix_html"
// Establish Phoenix Socket and LiveView configuration.
import { Socket } from "phoenix"
import { LiveSocket } from "phoenix_live_view"
import topbar from "../vendor/topbar"
import Hooks from "./_hooks"
import topbar from "../vendor/topbar"
import { toggleDarkMode } from "./darkMode"

let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content")
Expand Down
5 changes: 5 additions & 0 deletions assets/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"devDependencies": {
"daisyui": "^4.12.10"
}
}
85 changes: 85 additions & 0 deletions assets/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 15 additions & 22 deletions assets/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,27 @@ const plugin = require("tailwindcss/plugin")
const fs = require("fs")
const path = require("path")

/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
"./js/**/*.js",
"./node_modules/daisyui/dist/*.js",
"../lib/basket_web.ex",
"../lib/basket_web/**/*.*ex"
"../lib/basket_web/**/*.*ex",
],
darkMode: "class",
theme: {
extend: {
colors: {
primary: {
light: colors.emerald-800,
dark: colors.emerald-800
},
secondary: '#7a869a',
accent: '#ff5630',
background: {
light: colors.white,
dark: colors.emerald-800
},
surface: '#2c313a',
onSurface: '#ffffff',
error: '#de350b',
},
},
daisyui: {
themes: false, // true: all themes | false: only light + dark | array: specific themes like this ["light", "dark", "cupcake"]
darkTheme: "dark", // name of one of the included themes for dark mode
base: true, // applies background color and foreground color for root element by default
styled: true, // include daisyUI colors and design decisions for all components
utils: true, // adds responsive and modifier utility classes
rtl: false, // rotate style direction from left-to-right to right-to-left. You also need to add dir="rtl" to your html tag and install `tailwindcss-flip` plugin for Tailwind CSS.
prefix: "", // prefix for daisyUI classnames (components, modifiers and responsive class names. Not colors)
logs: false, // <-- to remove logs from the console.
},
plugins: [
require("@tailwindcss/forms"),
require('daisyui'),
//require("@tailwindcss/forms"),
// Allows prefixing tailwind classes with LiveView classes to add rules
// only when LiveView classes are applied, for example:
//
Expand Down Expand Up @@ -77,6 +70,6 @@ module.exports = {
}
}
}, {values})
})
}),
]
}
11 changes: 3 additions & 8 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,11 @@ config :esbuild,
~w(js/app.js --bundle --target=es2017 --outdir=../priv/static/assets --external:/fonts/* --external:/images/*),
cd: Path.expand("../assets", __DIR__),
env: %{"NODE_PATH" => Path.expand("../deps", __DIR__)}
],
catalogue: [
args:
~w(../deps/surface_catalogue/assets/js/app.js --bundle --target=es2016 --minify --outdir=../priv/static/assets/catalogue),
cd: Path.expand("../assets", __DIR__),
env: %{"NODE_PATH" => Path.expand("../deps", __DIR__)}
]

# Configure tailwind (the version is required)
config :tailwind,
version: "3.3.5",
version: "3.4.4",
default: [
args: ~w(
--config=tailwind.config.js
Expand All @@ -68,8 +62,9 @@ config :logger, :console,
config :phoenix, :json_library, Jason

config :basket, :pow,
web_module: BasketWeb,
web_mailer_module: BasketWeb,
user: Basket.Users.User,
user: Basket.User,
repo: Basket.Repo,
extensions: [PowResetPassword, PowEmailConfirmation],
controller_callbacks: Pow.Extension.Phoenix.ControllerCallbacks,
Expand Down
5 changes: 2 additions & 3 deletions config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,12 @@ config :basket, BasketWeb.Endpoint,

# Watch static and templates for browser reloading.
config :basket, BasketWeb.Endpoint,
reloadable_compilers: [:gettext, :elixir, :app, :surface],
reloadable_compilers: [:gettext, :elixir, :app],
live_reload: [
patterns: [
~r"priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$",
~r"priv/gettext/.*(po)$",
~r"lib/basket_web/(controllers|live|components)/.*(ex|heex|sface|js)$",
~r"priv/catalogue/.*(ex)$"
~r"lib/basket_web/(controllers|live|components)/.*(ex|heex|js)$"
]
]

Expand Down
13 changes: 13 additions & 0 deletions lib/basket/club.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
defmodule Basket.Club do
@moduledoc false

use Ecto.Schema

@type t :: %__MODULE__{}

schema "clubs" do
many_to_many :users, Basket.User, join_through: "club_members"

timestamps()
end
end
54 changes: 54 additions & 0 deletions lib/basket/club_ticker.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
defmodule Basket.ClubTicker do
@moduledoc """
These tickers belong to a club; every club member can view the club's
portfolio.
"""

use Ecto.Schema

import Ecto.{Changeset, Query}

alias Basket.{Club, Repo}

@type t :: %__MODULE__{}

schema "club_tickers" do
field :ticker, :string
belongs_to :club, Club

timestamps()
end

@doc false
def changeset(ticker_or_changeset, attrs) do
ticker_or_changeset
|> Ecto.Changeset.change()
|> cast(attrs, [:ticker, :user_id])
|> validate_required([:ticker, :user_id])
|> unique_constraint([:ticker, :user_id])
end

@spec add!(club :: Club.t(), ticker: String.t()) :: __MODULE__.t()
def add!(club, ticker) do
ticker = %__MODULE__{ticker: ticker, club_id: club.id}
Repo.insert!(ticker)
end

@spec for_club(user :: Club.t()) :: [Basket.Ticker.t()]
def for_club(nil), do: []

def for_club(club) do
from(t in __MODULE__,
where: t.club_id == ^club.id
)
|> Repo.all()
end

@spec remove(club :: Club.t(), ticker: String.t()) :: {non_neg_integer(), nil | [term()]}
def remove(club, ticker) do
from(t in __MODULE__,
where: t.club_id == ^club.id and t.ticker == ^ticker
)
|> Repo.delete_all()
end
end
15 changes: 3 additions & 12 deletions lib/basket/ticker.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule Basket.Ticker do
import Ecto.{Changeset, Query}

alias Basket.Repo
alias Basket.Users.User
alias Basket.User

@type t :: %__MODULE__{}

Expand All @@ -28,18 +28,12 @@ defmodule Basket.Ticker do
|> unique_constraint([:ticker, :user_id])
end

@doc """
Adds a ticker to a User's basket of stocks.
"""
@spec add(user :: User.t(), ticker: String.t()) :: __MODULE__.t()
def add(user, ticker) do
@spec add!(user :: User.t(), ticker: String.t()) :: __MODULE__.t()
def add!(user, ticker) do
ticker = %__MODULE__{ticker: ticker, user_id: user.id}
Repo.insert!(ticker)
end

@doc """
Returns a list of Tickers for a given user.
"""
@spec for_user(user :: User.t()) :: [Basket.Ticker.t()]
def for_user(nil), do: []

Expand All @@ -50,9 +44,6 @@ defmodule Basket.Ticker do
|> Repo.all()
end

@doc """
Removes a ticker from a User's basket of stocks.
"""
@spec remove(user :: User.t(), ticker: String.t()) :: {non_neg_integer(), nil | [term()]}
def remove(user, ticker) do
from(t in __MODULE__,
Expand Down
37 changes: 37 additions & 0 deletions lib/basket/user.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
defmodule Basket.User do
@moduledoc false

use Ecto.Schema
use Pow.Ecto.Schema

use Pow.Extension.Ecto.Schema,
extensions: [PowResetPassword, PowEmailConfirmation]

alias Basket.Repo

@type t :: %__MODULE__{}

def changeset(user_or_changeset, attrs) do
user_or_changeset
|> pow_changeset(attrs)
|> pow_extension_changeset(attrs)
end

def toggle_club_view!(user, value) when value in ["club", "individual"] do
updated_settings = Map.put(user.settings, "ticker_view_toggle", value)
changeset = Ecto.Changeset.change(user, settings: updated_settings)
Repo.update!(changeset)
end

schema "users" do
many_to_many :clubs, Basket.Club, join_through: "club_members"

many_to_many :offices, Basket.Club, join_through: "club_officers"

field :settings, :map

pow_user_fields()

timestamps()
end
end
Loading

0 comments on commit 2f66429

Please sign in to comment.