Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby
4.4 KB
Raw Blame
<head>
  <title><%= content_for(:title) || product_name %></title>

  <%= csrf_meta_tags %>
  <%= csp_meta_tag %>

  <%= stylesheet_link_tag "tailwind", "data-turbo-track": "reload" %>

  <%= combobox_style_tag %>

  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, viewport-fit=cover">

  <%# Applies the sidebar widths the user dragged to before the first paint;
      sidebar_resize_controller only runs once the page's JavaScript has
      loaded, so the sidebars drew at their default width and then jumped.
      It computes what the controller settles on when it connects: the bounds
      of utils/sidebar_resize.js, each sidebar clamped against the other one's
      width when that one is open (the left first, then the right, repeated
      until neither moves). It sits after the viewport tag, so innerWidth is
      the device's, not a default layout width. Without storage (blocked,
      private mode) each side takes its default, as the controller does.
      A Turbo visit that leaves this script unchanged doesn't run it again,
      while the window may have been resized on a page without the sidebars
      (settings), so it also runs before each Turbo render. %>
  <script nonce="<%= content_security_policy_nonce %>">
    (function () {
      var apply = function () {
        <%# The layout renders the right sidebar only while the assistant is enabled. %>
        var open = { left: <%= Current.user&.show_sidebar? ? "true" : "false" %>, right: <%= Current.user&.show_ai_sidebar? && Current.family&.assistant_enabled? ? "true" : "false" %> };
        var defaults = { left: 320, right: 400 }, absMax = { left: 480, right: 560 };
        var room = window.innerWidth - 84 - 400;
        var requested = {};
        ["left", "right"].forEach(function (side) {
          var stored = NaN;
          try {
            stored = parseInt(localStorage.getItem("sure.sidebarWidth." + side), 10);
          } catch (e) {}
          requested[side] = isFinite(stored) ? stored : defaults[side];
        });
        var clamp = function (side, otherWidth) {
          var max = Math.max(240, Math.min(absMax[side], room - otherWidth));
          return Math.round(Math.min(Math.max(requested[side], 240), max));
        };
        var width = { left: clamp("left", 0), right: clamp("right", 0) };
        for (var i = 0; i < 3; i++) {
          width.left = clamp("left", open.right ? width.right : 0);
          width.right = clamp("right", open.left ? width.left : 0);
        }
        ["left", "right"].forEach(function (side) {
          document.documentElement.style.setProperty("--" + side + "-sidebar-width", width[side] + "px");
        });
      };
      apply();
      <%# One listener at a time: a changed script (new preferences) replaces it. %>
      if (document.addEventListener) {
        document.removeEventListener("turbo:before-render", window.sureSidebarWidthsBeforeRender);
        window.sureSidebarWidthsBeforeRender = apply;
        document.addEventListener("turbo:before-render", apply);
      }
    })();
  </script>
  <%= javascript_importmap_tags %>
  <%= render "layouts/dark_mode_check" %>
  <%= render "layouts/privacy_mode_check" %>
  <%= turbo_refreshes_with method: :morph, scroll: :preserve %>

  <meta name="mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
  <meta name="apple-mobile-web-app-title" content="<%= product_name %>">
  <meta name="color-scheme" content="dark light">

  <%# Use theme colors that match both light and dark modes %>
  <meta name="msapplication-TileColor" content="#0B0B0B">
  <meta name="theme-color" content="#F9F9F9" media="(prefers-color-scheme: light)">
  <meta name="theme-color" content="#0B0B0B" media="(prefers-color-scheme: dark)">

  <link rel="manifest" href="<%= pwa_manifest_path %>">
  <%# Provide multiple iOS icons (standard 180x180 and larger) %>
  <link rel="apple-touch-icon" href="/apple-touch-icon.png">
  <link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
  <link rel="apple-touch-icon" sizes="512x512" href="/logo-pwa.png">
  <link rel="icon" sizes="192x192" type="image/png" href="/android-chrome-192x192.png">

  <% if posthog_enabled? && (posthog_config = Rails.configuration.x.posthog).try(:enabled) %>
    <%= render "shared/posthog", posthog_api_key: posthog_config.api_key, posthog_host: posthog_config.host %>
  <% end %>

  <%= yield :head %>
</head>