Skip to content

Commit

Permalink
Revert "Upgraded Phoenix (#75)"
Browse files Browse the repository at this point in the history
This reverts commit 98fcf5e.
  • Loading branch information
lucapasquale committed Feb 5, 2024
1 parent 98fcf5e commit f9457bc
Show file tree
Hide file tree
Showing 51 changed files with 473 additions and 1,362 deletions.
6 changes: 2 additions & 4 deletions .formatter.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Used by "mix format"
[
import_deps: [:ecto, :ecto_sql, :phoenix],
subdirectories: ["priv/*/migrations"],
plugins: [Phoenix.LiveView.HTMLFormatter],
inputs: ["*.{heex,ex,exs}", "{config,lib,test}/**/*.{heex,ex,exs}", "priv/*/seeds.exs"]
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]
17 changes: 8 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# The directory Mix downloads your dependencies sources to.
/deps/

# Where 3rd-party dependencies like ExDoc output generated docs.
# Where third-party dependencies like ExDoc output generated docs.
/doc/

# Ignore .fetch files in case you like to edit your project deps locally.
Expand All @@ -19,21 +19,20 @@ erl_crash.dump
# Also ignore archive artifacts (built via "mix archive.build").
*.ez

# Temporary files, for example, from tests.
/tmp/

# Ignore package tarball (built via "mix hex.build").
botchini-*.tar

# Temporary files for e.g. tests
/tmp

# Ignore assets that are produced by build tools.
/priv/static/assets/

# Ignore digested assets cache.
/priv/static/cache_manifest.json

# In case you use Node.js/npm, you want to ignore these.
npm-debug.log
/assets/node_modules/
# Secrets
config/*.secret.exs

# Ignore secret env vars
/config/dev.secret.exs
# ElixirLS
.elixir_ls
2 changes: 0 additions & 2 deletions assets/css/app.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@import "tailwindcss/base";
@import "tailwindcss/components";
@import "tailwindcss/utilities";

/* This file is for your main application CSS */
Binary file added assets/favicon.ico
Binary file not shown.
Binary file added assets/images/twitch_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/youtube_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 6 additions & 6 deletions assets/js/app.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// We import the CSS which is extracted to its own file by esbuild.
// Remove this line if you add a your own CSS build pipeline (e.g postcss).

// If you want to use Phoenix channels, run `mix help phx.gen.channel`
// to get started and then uncomment the line below.
// import "./user_socket.js"
Expand All @@ -23,15 +26,12 @@ import {LiveSocket} from "phoenix_live_view"
import topbar from "../vendor/topbar"

let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content")
let liveSocket = new LiveSocket("/live", Socket, {
longPollFallbackMs: 2500,
params: {_csrf_token: csrfToken}
})
let liveSocket = new LiveSocket("/live", Socket, {params: {_csrf_token: csrfToken}})

// Show progress bar on live navigation and form submits
topbar.config({barColors: {0: "#29d"}, shadowColor: "rgba(0, 0, 0, .3)"})
window.addEventListener("phx:page-loading-start", _info => topbar.show(300))
window.addEventListener("phx:page-loading-stop", _info => topbar.hide())
window.addEventListener("phx:page-loading-start", info => topbar.show())
window.addEventListener("phx:page-loading-stop", info => topbar.hide())

// connect if there are any LiveViews on the page
liveSocket.connect()
Expand Down
5 changes: 5 additions & 0 deletions assets/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
#
# To ban all spiders from the entire site uncomment the next two lines:
# User-agent: *
# Disallow: /
72 changes: 8 additions & 64 deletions assets/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -1,80 +1,24 @@
const colors = require("tailwindcss/colors");

// See the Tailwind configuration guide for advanced usage
// https://tailwindcss.com/docs/configuration

const colors = require("tailwindcss/colors")
const plugin = require("tailwindcss/plugin")
const fs = require("fs")
const path = require("path")

module.exports = {
darkMode: "class",
content: [
"./js/**/*.js",
"../lib/botchini_web.ex",
"../lib/botchini_web/**/*.*ex"
'./js/**/*.js',
'../lib/*_web.ex',
'../lib/*_web/**/*.*ex',
"../deps/petal_components/**/*.*ex",
],
theme: {
extend: {
colors: {
brand: "#FD4F00",

primary: colors.blue,
secondary: colors.pink,
}
},
},
},
plugins: [
require("@tailwindcss/forms"),
// Allows prefixing tailwind classes with LiveView classes to add rules
// only when LiveView classes are applied, for example:
//
// <div class="phx-click-loading:animate-ping">
//
plugin(({addVariant}) => addVariant("phx-no-feedback", [".phx-no-feedback&", ".phx-no-feedback &"])),
plugin(({addVariant}) => addVariant("phx-click-loading", [".phx-click-loading&", ".phx-click-loading &"])),
plugin(({addVariant}) => addVariant("phx-submit-loading", [".phx-submit-loading&", ".phx-submit-loading &"])),
plugin(({addVariant}) => addVariant("phx-change-loading", [".phx-change-loading&", ".phx-change-loading &"])),

// Embeds Heroicons (https://heroicons.com) into your app.css bundle
// See your `CoreComponents.icon/1` for more information.
//
plugin(function({matchComponents, theme}) {
let iconsDir = path.join(__dirname, "../deps/heroicons/optimized")
let values = {}
let icons = [
["", "/24/outline"],
["-solid", "/24/solid"],
["-mini", "/20/solid"],
["-micro", "/16/solid"]
]
icons.forEach(([suffix, dir]) => {
fs.readdirSync(path.join(iconsDir, dir)).forEach(file => {
let name = path.basename(file, ".svg") + suffix
values[name] = {name, fullPath: path.join(iconsDir, dir, file)}
})
})
matchComponents({
"hero": ({name, fullPath}) => {
let content = fs.readFileSync(fullPath).toString().replace(/\r?\n|\r/g, "")
let size = theme("spacing.6")
if (name.endsWith("-mini")) {
size = theme("spacing.5")
} else if (name.endsWith("-micro")) {
size = theme("spacing.4")
}
return {
[`--hero-${name}`]: `url('data:image/svg+xml;utf8,${content}')`,
"-webkit-mask": `var(--hero-${name})`,
"mask": `var(--hero-${name})`,
"mask-repeat": "no-repeat",
"background-color": "currentColor",
"vertical-align": "middle",
"display": "inline-block",
"width": size,
"height": size
}
}
}, {values})
})
require('@tailwindcss/forms')
]
}
42 changes: 17 additions & 25 deletions assets/vendor/topbar.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @license MIT
* topbar 2.0.0, 2023-02-04
* topbar 1.0.0, 2021-01-06
* https://buunguyen.github.io/topbar
* Copyright (c) 2021 Buu Nguyen
*/
Expand Down Expand Up @@ -35,11 +35,10 @@
})();

var canvas,
progressTimerId,
fadeTimerId,
currentProgress,
showing,
progressTimerId = null,
fadeTimerId = null,
delayTimerId = null,
addEvent = function (elem, type, handler) {
if (elem.addEventListener) elem.addEventListener(type, handler, false);
else if (elem.attachEvent) elem.attachEvent("on" + type, handler);
Expand Down Expand Up @@ -96,26 +95,21 @@
for (var key in opts)
if (options.hasOwnProperty(key)) options[key] = opts[key];
},
show: function (delay) {
show: function () {
if (showing) return;
if (delay) {
if (delayTimerId) return;
delayTimerId = setTimeout(() => topbar.show(), delay);
} else {
showing = true;
if (fadeTimerId !== null) window.cancelAnimationFrame(fadeTimerId);
if (!canvas) createCanvas();
canvas.style.opacity = 1;
canvas.style.display = "block";
topbar.progress(0);
if (options.autoRun) {
(function loop() {
progressTimerId = window.requestAnimationFrame(loop);
topbar.progress(
"+" + 0.05 * Math.pow(1 - Math.sqrt(currentProgress), 2)
);
})();
}
showing = true;
if (fadeTimerId !== null) window.cancelAnimationFrame(fadeTimerId);
if (!canvas) createCanvas();
canvas.style.opacity = 1;
canvas.style.display = "block";
topbar.progress(0);
if (options.autoRun) {
(function loop() {
progressTimerId = window.requestAnimationFrame(loop);
topbar.progress(
"+" + 0.05 * Math.pow(1 - Math.sqrt(currentProgress), 2)
);
})();
}
},
progress: function (to) {
Expand All @@ -131,8 +125,6 @@
return currentProgress;
},
hide: function () {
clearTimeout(delayTimerId);
delayTimerId = null;
if (!showing) return;
showing = false;
if (progressTimerId != null) {
Expand Down
53 changes: 15 additions & 38 deletions config/config.exs
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
# This file is responsible for configuring your application
# and its dependencies with the aid of the Config module.
#
# This configuration file is loaded before any dependency and
# is restricted to this project.

# General application configuration
import Config

config :botchini,
Expand All @@ -25,37 +18,31 @@ config :botchini, Botchini.Scheduler,
# Configures the endpoint
config :botchini, BotchiniWeb.Endpoint,
url: [host: "localhost"],
adapter: Bandit.PhoenixAdapter,
render_errors: [
formats: [html: BotchiniWeb.ErrorHTML, json: BotchiniWeb.ErrorJSON],
layout: false
],
render_errors: [view: BotchiniWeb.ErrorView, accepts: ~w(html json), layout: false],
pubsub_server: Botchini.PubSub,
live_view: [signing_salt: "yFQUW8gj"]

# Configures the mailer
#
# By default it uses the "Local" adapter which stores the emails
# locally. You can see the emails in your browser, at "/dev/mailbox".
#
# For production it's recommended to configure a different adapter
# at the `config/runtime.exs`.
config :botchini, Botchini.Mailer, adapter: Swoosh.Adapters.Local
live_view: [signing_salt: "ZIYuYInA"]

# Configure esbuild (the version is required)
config :esbuild,
version: "0.17.11",
botchini: [
version: "0.14.29",
default: [
args:
~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__)}
]

# Configure tailwind (the version is required)
# Configures Elixir's Logger
config :logger, :console,
format: "$time $metadata[$level] $message\n",
metadata: [:request_id, :interaction_data, :guild_id, :channel_id, :user_id]

# Use Jason for JSON parsing in Phoenix
config :phoenix, :json_library, Jason

config :tailwind,
version: "3.4.0",
botchini: [
version: "3.1.2",
default: [
args: ~w(
--config=tailwind.config.js
--input=css/app.css
Expand All @@ -64,14 +51,4 @@ config :tailwind,
cd: Path.expand("../assets", __DIR__)
]

# Configures Elixir's Logger
config :logger, :console,
format: "$time $metadata[$level] $message\n",
metadata: [:request_id, :interaction_data, :guild_id, :channel_id, :user_id]

# Use Jason for JSON parsing in Phoenix
config :phoenix, :json_library, Jason

# Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
import_config "#{config_env()}.exs"
import_config "#{Mix.env()}.exs"
12 changes: 5 additions & 7 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ if config_env() == :prod do
For example: ecto://USER:PASS@HOST/DATABASE
"""

maybe_ipv6 = if System.get_env("ECTO_IPV6") in ~w(true 1), do: [:inet6], else: []
maybe_ipv6 = if System.get_env("ECTO_IPV6"), do: [:inet6], else: []

config :botchini, Botchini.Repo,
# ssl: true,
ssl: false,
url: database_url,
pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10"),
socket_options: maybe_ipv6
socket_options: maybe_ipv6,
pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10")

# The secret key base is used to sign/encrypt cookies and other secrets.
# A default value is used in config/dev.exs and config/test.exs but you
Expand All @@ -51,14 +51,12 @@ if config_env() == :prod do
host = System.get_env("PHX_HOST") || "example.com"
port = String.to_integer(System.get_env("PORT") || "4000")

config :botchini, :dns_cluster_query, System.get_env("DNS_CLUSTER_QUERY")

config :botchini, BotchiniWeb.Endpoint,
url: [host: host, port: 443, scheme: "https"],
http: [
# Enable IPv6 and bind on all interfaces.
# Set it to {0, 0, 0, 0, 0, 0, 0, 1} for local network only access.
# See the documentation on https://hexdocs.pm/bandit/Bandit.html#t:options/0
# See the documentation on https://hexdocs.pm/plug_cowboy/Plug.Cowboy.html
# for details about using IPv6 vs IPv4 and loopback vs public addresses.
ip: {0, 0, 0, 0, 0, 0, 0, 0},
port: port
Expand Down
23 changes: 6 additions & 17 deletions lib/botchini/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,16 @@ defmodule Botchini.Application do
def start(_type, _args) do
children =
[
BotchiniWeb.Telemetry,
Botchini.Repo,
Botchini.Cache,
Botchini.Scheduler,
Botchini.Services.Twitch.AuthMiddleware,
{DNSCluster, query: Application.get_env(:botchini, :dns_cluster_query) || :ignore},
# Start the Telemetry supervisor
BotchiniWeb.Telemetry,
# Start the PubSub system
{Phoenix.PubSub, name: Botchini.PubSub},
# Start the Finch HTTP client for sending emails
{Finch, name: Botchini.Finch},
# Start a worker by calling: Botchini.Worker.start_link(arg)
# {Botchini.Worker, arg},
# Start to serve requests, typically the last entry
BotchiniWeb.Endpoint
BotchiniWeb.Endpoint,
# Twitch auth middleware
Botchini.Services.Twitch.AuthMiddleware
]
|> start_nostrum(Application.fetch_env!(:botchini, :environment))

Expand All @@ -33,12 +30,4 @@ defmodule Botchini.Application do

defp start_nostrum(children, :test), do: children
defp start_nostrum(children, _env), do: children ++ [BotchiniDiscord.Consumer]

# Tell Phoenix to update the endpoint configuration
# whenever the application is updated.
@impl true
def config_change(changed, _new, removed) do
BotchiniWeb.Endpoint.config_change(changed, removed)
:ok
end
end
Loading

0 comments on commit f9457bc

Please sign in to comment.