-
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
webapp/preferences: allow user to choose UTC or local time
Closes #161.
- Loading branch information
Showing
6 changed files
with
146 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
// SPDX-FileCopyrightText: (C) 2023 Jason Ish <[email protected]> | ||
// SPDX-License-Identifier: MIT | ||
|
||
import { For, Show } from "solid-js"; | ||
import { For, Show, createMemo } from "solid-js"; | ||
import { SearchLink } from "./common/SearchLink"; | ||
import { parse_timestamp } from "./datetime"; | ||
import { EventSource } from "./types"; | ||
import { formatAddress } from "./formatters"; | ||
import { BiDashCircle, BiFilter, BiPlusCircle } from "./icons"; | ||
import { PREFS } from "./preferences"; | ||
import dayjs from "dayjs"; | ||
|
||
// Creates a table where the first column is a count, and the second | ||
// column is value. | ||
|
@@ -221,17 +223,47 @@ export function FilterStrip(props: { filters: any; setFilters: any }) { | |
); | ||
} | ||
|
||
export function FormattedTimestamp(props: { | ||
timestamp: string; | ||
withMillis?: boolean; | ||
}) { | ||
const timestamp = createMemo(() => { | ||
return parse_timestamp(props.timestamp); | ||
}); | ||
|
||
const formatted = createMemo(() => { | ||
let formatString = "YYYY-MM-DD HH:mm:ss"; | ||
if (props.withMillis === true) { | ||
formatString += ".SSS"; | ||
} | ||
|
||
if (PREFS().timestamp_format === "utc") { | ||
return timestamp().utc().format(formatString) + "Z"; | ||
} else { | ||
return timestamp().format(formatString); | ||
} | ||
}); | ||
|
||
return <>{formatted}</>; | ||
} | ||
|
||
export function TimestampCell(props: { | ||
timestamp: string; | ||
addFilter?: (what: string, op: string, value: string) => void; | ||
}) { | ||
let timestamp = parse_timestamp(props.timestamp); | ||
let formatted = timestamp.format("YYYY-MM-DD HH:mm:ss"); | ||
const timestamp = createMemo(() => { | ||
return parse_timestamp(props.timestamp); | ||
}); | ||
|
||
const formatted = createMemo(() => { | ||
return <FormattedTimestamp timestamp={props.timestamp} />; | ||
}); | ||
|
||
return ( | ||
<div title={props.timestamp}> | ||
{timestamp.format("YYYY-MM-DD HH:mm:ss")} | ||
{formatted()} | ||
<br /> | ||
<span class={"small"}>{timestamp.fromNow()}</span>{" "} | ||
<span class={"small"}>{timestamp().fromNow()}</span>{" "} | ||
<Show when={props.addFilter}> | ||
<span class="dropdown" onclick={(e) => e.stopPropagation()}> | ||
<span data-bs-toggle="dropdown"> | ||
|
@@ -245,7 +277,7 @@ export function TimestampCell(props: { | |
props.addFilter!("@from", "", props.timestamp); | ||
}} | ||
> | ||
Filter for from {formatted} | ||
Filter for from {formatted()} | ||
</a> | ||
</li> | ||
<li> | ||
|
@@ -255,7 +287,7 @@ export function TimestampCell(props: { | |
props.addFilter!("@to", "", props.timestamp); | ||
}} | ||
> | ||
Filter for to {formatted} | ||
Filter for to {formatted()} | ||
</a> | ||
</li> | ||
</ul> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// SPDX-FileCopyrightText: (C) 2025 Jason Ish <[email protected]> | ||
// SPDX-License-Identifier: MIT | ||
|
||
import { createSignal } from "solid-js"; | ||
|
||
export const [PREFS, SET_PREFS] = createSignal<ClientPreferences>( | ||
getClientPreferences() | ||
); | ||
|
||
export interface ClientPreferences { | ||
timestamp_format?: "utc" | "local"; | ||
} | ||
|
||
export function createDefaultClientPreferences(): ClientPreferences { | ||
return { | ||
timestamp_format: "local", | ||
}; | ||
} | ||
|
||
export function getClientPreferences(): ClientPreferences { | ||
let prefs: any = localStorage.getItem("clientPreferences"); | ||
if (!prefs) { | ||
console.log("Did not find localStorage clientPreferences, return defaults"); | ||
return createDefaultClientPreferences(); | ||
} | ||
try { | ||
prefs = JSON.parse(prefs) as ClientPreferences; | ||
// Merge in defaults. | ||
prefs = { ...createDefaultClientPreferences(), ...prefs }; | ||
return prefs; | ||
} catch (e) { | ||
return createDefaultClientPreferences(); | ||
} | ||
} | ||
|
||
export function saveClientPreferences(prefs: ClientPreferences) { | ||
localStorage.setItem("clientPreferences", JSON.stringify(prefs)); | ||
SET_PREFS(prefs); | ||
} |