Skip to content

Commit

Permalink
improvement: upgrade to 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed Apr 3, 2024
1 parent 6a943f2 commit 2221ef8
Show file tree
Hide file tree
Showing 59 changed files with 381 additions and 548 deletions.
84 changes: 49 additions & 35 deletions assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,43 @@ import { LiveSocket } from "phoenix_live_view";
import topbar from "../vendor/topbar";

function setCookie(name, value) {
document.cookie = name + "=" + value + ";path=/;" + "expires=Fri, 31 Dec 9999 23:59:59 GMT;";
document.cookie =
name + "=" + value + ";path=/;" + "expires=Fri, 31 Dec 9999 23:59:59 GMT;";
}

function getCookie(name) {
const cookie = document.cookie.split("; ").find((row) => row.startsWith(name + "="))
const cookie = document.cookie
.split("; ")
.find((row) => row.startsWith(name + "="));
if (cookie) {
return cookie.split("=")[1]
return cookie.split("=")[1];
}
}

function cookiesAreAllowed() {
return getCookie("cookieconsent_status") === "allow"
return getCookie("cookieconsent_status") === "allow";
}

function get_platform() {
// 2022 way of detecting. Note : this userAgentData feature is available only in secure contexts (HTTPS)
if (typeof navigator.userAgentData !== 'undefined' && navigator.userAgentData != null) {
if (
typeof navigator.userAgentData !== "undefined" &&
navigator.userAgentData != null
) {
return navigator.userAgentData.platform;
}
// Deprecated but still works for most of the browser
if (typeof navigator.platform !== 'undefined') {
if (typeof navigator.userAgent !== 'undefined' && /android/.test(navigator.userAgent.toLowerCase())) {
if (typeof navigator.platform !== "undefined") {
if (
typeof navigator.userAgent !== "undefined" &&
/android/.test(navigator.userAgent.toLowerCase())
) {
// android device's navigator.platform is often set as 'linux', so let's use userAgent for them
return 'android';
return "android";
}
return navigator.platform;
}
return 'unknown';
return "unknown";
}

let platform = get_platform();
Expand Down Expand Up @@ -110,13 +119,15 @@ let scrolled = false;

Hooks.RightNav = {
mounted() {
this.intersectionObserver =
new IntersectionObserver((entries) =>
this.onScrollChange(entries), { rootMargin: "-10% 0px -89% 0px" }
);
this.intersectionObserver = new IntersectionObserver(
(entries) => this.onScrollChange(entries),
{ rootMargin: "-10% 0px -89% 0px" },
);

this.observeElements()
window.addEventListener("hashchange", (event) => { this.handleHashChange(); });
this.observeElements();
window.addEventListener("hashchange", (event) => {
this.handleHashChange();
});
},
updated() {
this.intersectionObserver.disconnect();
Expand All @@ -129,7 +140,9 @@ Hooks.RightNav = {
},
onScrollChange(entries) {
// Wait for scrolling from initial page load to complete
if (!scrolled) { return; }
if (!scrolled) {
return;
}

for (entry of entries) {
if (entry.isIntersecting) {
Expand All @@ -139,19 +152,21 @@ Hooks.RightNav = {
},
handleHashChange() {
if (window.location.hash) {
this.setAriaCurrent(window.location.hash.substring(1))
this.setAriaCurrent(window.location.hash.substring(1));

// Disable the insersection observer for 1s while the browser
// scrolls the selected element to the top.
scrolled = false;
setTimeout(() => { scrolled = true }, 1000);
setTimeout(() => {
scrolled = true;
}, 1000);
}
},
setAriaCurrent(id) {
const el = document.getElementById("right-nav-" + id);
if (el) {
for (elem of document.querySelectorAll('#right-nav a[aria-current]')) {
elem.removeAttribute('aria-current');
for (elem of document.querySelectorAll("#right-nav a[aria-current]")) {
elem.removeAttribute("aria-current");
}
el.setAttribute("aria-current", "true");
}
Expand Down Expand Up @@ -201,9 +216,9 @@ window.addEventListener("phx:page-loading-start", ({ detail }) => {
scrolled = false;

// close mobile sidebar on navigation
mobileSideBar = document.getElementById("mobile-sidebar-hide")
mobileSideBar = document.getElementById("mobile-sidebar-hide");
if (mobileSideBar) {
mobileSideBar.click()
mobileSideBar.click();
}

if (!topBarScheduled) {
Expand All @@ -219,13 +234,17 @@ window.addEventListener("phx:page-loading-stop", ({ detail }) => {
if (detail.kind === "initial" && window.location.hash) {
scrollEl = document.getElementById(window.location.hash.substring(1));
} else if (detail.kind == "patch" && !window.location.hash) {
scrollEl = document.querySelector("#docs-window .nav-anchor") || document.querySelector("#docs-window h1");
scrollEl =
document.querySelector("#docs-window .nav-anchor") ||
document.querySelector("#docs-window h1");
}
if (scrollEl) {
Hooks.RightNav.setAriaCurrent(scrollEl.id);
// Not using scroll polyfill here - doesn't respect scroll-padding-top CSS
scrollEl.scrollIntoView({ block: 'start' })
setTimeout(() => { scrolled = true; }, 1000);
scrollEl.scrollIntoView({ block: "start" });
setTimeout(() => {
scrolled = true;
}, 1000);
} else {
scrolled = true;
}
Expand All @@ -243,13 +262,6 @@ window.addEventListener("phx:js:scroll-to", (e) => {
});
});

window.addEventListener("phx:selected-types", (e) => {
if (cookiesAreAllowed()) {
const cookie = e.detail.types.join(",");
setCookies("selected_types", cookie)
}
});

window.addEventListener("keydown", (event) => {
if ((event.metaKey || event.ctrlKey) && event.key === "k") {
document.getElementById("search-button").click();
Expand All @@ -258,9 +270,11 @@ window.addEventListener("keydown", (event) => {
});
window.addEventListener("keydown", (event) => {
if (event.key === "Escape") {
const closeSearchVersions = document.getElementById("close-search-versions");
const closeSearchVersions = document.getElementById(
"close-search-versions",
);
if (closeSearchVersions && closeSearchVersions.offsetParent !== null) {
closeSearchVersions.click()
closeSearchVersions.click();
} else {
document.getElementById("close-search").click();
}
Expand Down Expand Up @@ -288,7 +302,7 @@ liveSocket.connect();
// >> liveSocket.disableLatencySim()
window.liveSocket = liveSocket;

window.addEventListener("load", function() {
window.addEventListener("load", function () {
window.cookieconsent.initialise({
content: {
message:
Expand Down
3 changes: 1 addition & 2 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ config :ash_appsignal,
config :appsignal, :config, revision: "test-4"

config :ash_hq,
ash_apis: [
ash_domains: [
AshHq.Accounts,
AshHq.Blog,
AshHq.Docs,
Expand All @@ -40,7 +40,6 @@ config :ash_hq, AshHq.Repo,

config :spark, :formatter,
remove_parens?: true,
"Ash.Registry": [],
"Ash.Resource": [
type: Ash.Resource,
section_order: [
Expand Down
9 changes: 3 additions & 6 deletions lib/ash_hq/accounts/accounts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@ defmodule AshHq.Accounts do
@moduledoc """
Handles user and user token related operations/state
"""
use Ash.Api, otp_app: :ash_hq

authorization do
authorize :by_default
end
use Ash.Domain, otp_app: :ash_hq

resources do
registry AshHq.Accounts.Registry
resource AshHq.Accounts.User
resource AshHq.Accounts.UserToken
end
end
11 changes: 0 additions & 11 deletions lib/ash_hq/accounts/registry.ex

This file was deleted.

26 changes: 0 additions & 26 deletions lib/ash_hq/accounts/resources/user/changes/remove_all_tokens.ex

This file was deleted.

20 changes: 0 additions & 20 deletions lib/ash_hq/accounts/resources/user/policies.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,5 @@ defmodule AshHq.Accounts.User.Policies do
policy action(:read) do
authorize_if(expr(id == ^actor(:id)))
end

policy action(:update_email) do
description("A logged in user can update their email")
authorize_if(expr(id == ^actor(:id)))
end

policy action(:resend_confirmation_instructions) do
description("A logged in user can request an email confirmation")
authorize_if(expr(id == ^actor(:id)))
end

policy action(:change_password) do
description("A logged in user can reset their password")
authorize_if(expr(id == ^actor(:id)))
end

policy action(:update_merch_settings) do
description("A logged in user can update their merch settings")
authorize_if(expr(id == ^actor(:id)))
end
end
end
Loading

0 comments on commit 2221ef8

Please sign in to comment.