Repository navigation
Let each environment use a user-chosen badge glyph #28155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
repparw
wants to merge
5
commits into
pingdotgg:main
Choose a base branch
from
repparw:t3/greek-letter-environment-icons
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+318
−31
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0c2a63b
Add device-local per-environment badge glyphs
repparw c3455e3
ci: retrigger web tests after unrelated PDF preview timeout
repparw dcca12a
chore: merge main into environment glyph branch
maria-rcks 99a14c5
fix(web): make environment glyphs editable for local environments
maria-rcks cdaa456
Merge remote-tracking branch 'github/main' into t3/greek-letter-envir…
maria-rcks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,32 @@ | ||
| import type { EnvironmentId, EnvironmentMachineKind } from "@t3tools/contracts"; | ||
|
|
||
| import { useEnvironmentGlyphStore } from "../environmentGlyphStore"; | ||
| import { cn } from "~/lib/utils"; | ||
| import { EnvironmentMachineIcon } from "./EnvironmentMachineIcon"; | ||
|
|
||
| /** A device-local glyph overrides the machine icon without changing server settings. */ | ||
| export function EnvironmentBadgeIcon({ | ||
| environmentId, | ||
| kind, | ||
| className, | ||
| }: { | ||
| readonly environmentId: EnvironmentId; | ||
| readonly kind: EnvironmentMachineKind; | ||
| readonly className?: string; | ||
| }) { | ||
| const glyph = useEnvironmentGlyphStore((state) => state.byId[environmentId]); | ||
|
|
||
| return glyph ? ( | ||
| <span | ||
| aria-hidden | ||
| className={cn( | ||
| "inline-flex shrink-0 items-center justify-center text-xs leading-none font-medium select-none", | ||
| className, | ||
| )} | ||
| > | ||
| {glyph} | ||
| </span> | ||
| ) : ( | ||
| <EnvironmentMachineIcon aria-hidden kind={kind} className={className} /> | ||
| ); | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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
62 changes: 62 additions & 0 deletions
62
apps/web/src/components/settings/EnvironmentGlyphInput.tsx
This file contains hidden or 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,62 @@ | ||
| import type { EnvironmentId } from "@t3tools/contracts"; | ||
| import { useRef, useState } from "react"; | ||
|
|
||
| import { normalizeEnvironmentGlyph, useEnvironmentGlyphStore } from "~/environmentGlyphStore"; | ||
| import { Input } from "../ui/input"; | ||
|
|
||
| /** Edit the local glyph without changing the server-backed machine icon. */ | ||
| export function EnvironmentGlyphInput({ | ||
| environmentId, | ||
| label, | ||
| }: { | ||
| readonly environmentId: EnvironmentId; | ||
| readonly label: string; | ||
| }) { | ||
| const [draft, setDraft] = useState( | ||
| () => useEnvironmentGlyphStore.getState().byId[environmentId] ?? "", | ||
| ); | ||
| const composing = useRef(false); | ||
| const setGlyph = (value: string) => { | ||
| useEnvironmentGlyphStore.getState().setGlyph(environmentId, value); | ||
| }; | ||
|
|
||
| const finish = (value: string) => { | ||
| composing.current = false; | ||
| const normalized = normalizeEnvironmentGlyph(value) ?? ""; | ||
| setDraft(normalized); | ||
| setGlyph(normalized); | ||
| }; | ||
|
|
||
| return ( | ||
| <div className="w-12 shrink-0 text-center"> | ||
| <Input | ||
| aria-label={`Badge glyph for ${label}`} | ||
| title="One character or emoji (this device only). Clear to use the machine icon." | ||
| value={draft} | ||
| onChange={(event) => { | ||
| const value = event.currentTarget.value; | ||
| setDraft(value); | ||
| if (!composing.current) setGlyph(value); | ||
| }} | ||
| onFocus={(event) => event.currentTarget.select()} | ||
| onCompositionStart={() => { | ||
| composing.current = true; | ||
| }} | ||
| onCompositionEnd={(event) => { | ||
| composing.current = false; | ||
| const value = event.currentTarget.value; | ||
| setDraft(value); | ||
| setGlyph(value); | ||
| }} | ||
| onBlur={(event) => finish(event.currentTarget.value)} | ||
| onKeyDown={(event) => { | ||
| if (event.key === "Enter" && !composing.current && !event.nativeEvent.isComposing) { | ||
| event.currentTarget.blur(); | ||
| } | ||
| }} | ||
| placeholder="α" | ||
| size="sm" | ||
| /> | ||
| </div> | ||
| ); | ||
| } | ||
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.