PageSourceSearch

https://fragua.app/assets/controllers/time_zone_detector_controller-1ca04578.js

js fragua.app collected 2026-10-04 23:44:54 UTC 1,755 bytes, 40 lines download raw bytes

1import { Controller } from "@hotwired/stimulus"
2
3// Pre-fills the time-zone select with the browser's detected zone and persists
4// it — once per user, ever.
5//
6// The `resolved` value is what makes "once" true. A blank select used to be the
7// whole trigger, but blank is also what "Use server default" stores, so a user
8// who deliberately chose the default had it overwritten by their browser on
9// every single page load, toast and all. The server now records that the
10// question was settled (`users.time_zone_resolved_at`) and passes it here.
11//
12// It submits the form ITSELF rather than dispatching a `change` for the
13// `auto-submit` controller beside it. Stimulus connects controllers in
14// left-to-right token order and binds actions during connect, so a synthetic
15// change fired from this controller's connect() reaches a select that
16// auto-submit has not bound yet — it only worked because auto_submit's module
17// happened to resolve first, and renaming a file would have silently stopped the
18// detected zone from ever saving. `flag` carries `auto_detected` so the
19// controller can skip the "Settings saved." toast: the user saved nothing here.
20export default class extends Controller {
21  static targets = ["select", "flag"]
22  static values = { resolved: Boolean }
23
24  connect() {
25    if (this.resolvedValue) return
26    if (this.selectTarget.disabled) return
27    if (this.selectTarget.value) return
28
29    const zone = Intl.DateTimeFormat().resolvedOptions().timeZone
30    if (!zone || !this.hasOption(zone)) return
31
32    this.selectTarget.value = zone
33    this.flagTarget.value = "1"
34    this.element.requestSubmit()
35  }
36
37  hasOption(value) {
38    return Array.from(this.selectTarget.options).some((option) => option.value === value)
39  }
40}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.