Skip to content

Commit 30dd539

Browse files
Merge pull request #55 from lumpinif/main
[fix] Improved instruction selector loading state handling
2 parents 6c4f798 + 3c6f99d commit 30dd539

File tree

5 files changed

+95
-84
lines changed

5 files changed

+95
-84
lines changed

extensions/changelog.md

+9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
# Changelog of the extensions
44

5+
## fix: Instruction Selector Loading State - 12/3/2024 - @lumpinif
6+
7+
### Bug Fixes
8+
9+
- Improved loading state handling in instruction selector
10+
- Fixed loading state visibility during data fetching
11+
- Added empty state check to prevent UI flickering
12+
- Enhanced state transitions between loading and loaded states
13+
514
## feat: Instruction Selector - 12/2/2024 - @lumpinif
615

716
### New Feature Implementation

extensions/chrome/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "thinking-claude",
3-
"version": "3.2.0",
3+
"version": "3.2.1",
44
"description": "Chrome extension for letting Claude think like a real human",
55
"type": "module",
66
"scripts": {

extensions/chrome/public/manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"manifest_version": 3,
33
"name": "Thinking Claude",
4-
"version": "3.2.0",
4+
"version": "3.2.1",
55
"description": "Chrome extension for letting Claude think like a real human",
66
"background": {
77
"service_worker": "background.js"

extensions/chrome/src/components/instruction-selector/index.tsx

+79-79
Original file line numberDiff line numberDiff line change
@@ -77,92 +77,92 @@ export function InstructionSelect() {
7777
const selectedInstruction = instructions.find((inst) => inst.value === value)
7878
const displayedInstruction = hoveredInstruction || selectedInstruction
7979

80-
if (isLoading) {
81-
return <LoadingState isLoading={isLoading} />
82-
}
83-
8480
return (
8581
<div className="tc-min-w-24">
86-
<Select
87-
key={key}
88-
value={value}
89-
onValueChange={(value) => {
90-
handleInstructionClick(
91-
instructions.find((inst) => inst.value === value)!
92-
)
93-
}}
94-
>
95-
<SelectTrigger className="inline-flex items-center justify-center relative shrink-0 ring-offset-2 ring-offset-bg-300 ring-accent-main-100 focus-visible:outline-none focus-visible:ring-1 tc-shadow-none disabled:pointer-events-none disabled:opacity-50 disabled:shadow-none disabled:drop-shadow-none max-w-full min-w-0 pl-1.5 pr-1 h-7 ml-0.5 mr-1 hover:bg-bg-200 hover:border-border-400 border-0.5 text-sm rounded-md border-transparent transition text-text-500 hover:text-text-200 font-tiempos !tc-font-normal tc-gap-x-1">
96-
<SelectValue placeholder="Let Claude think" />
97-
</SelectTrigger>
98-
<SelectContent className="z-50 bg-bg-200 backdrop-blur-xl border-0.5 border-border-300 rounded-xl min-w-[12rem] overflow-hidden p-1 text-text-200 shadow-[0_0_0_0.5px_rgba(0,0,0,0.1),0_0_20px_rgba(0,0,0,0.05),0_1px_5px_rgba(0,0,0,0.1)] w-64 sm:w-[28rem] md:tc-w-[32rem] !z-30">
99-
<div className="sm:flex justify-between items-center flex-1 text-xs font-medium text-text-300 px-1.5 pt-1 pb-1.5 min-h-5">
100-
<div className="translate-y-[0.5px]">
101-
Which model instruction should Claude use?
102-
</div>
103-
<a
104-
href="https://github.com/richards199999/Thinking-Claude"
105-
target="_blank"
106-
rel="noopener noreferrer"
107-
>
108-
<Badge
109-
variant="default"
110-
className="border-0.5 border-border-300 tc-flex tc-items-center tc-gap-2 tc-cursor-pointer hover:!bg-accent-main-100 hover:!text-oncolor-100 hover:!border-transparent transition tc-font-normal tc-text-xs tc-flex-nowrap"
82+
{isLoading || instructions.length === 0 ? (
83+
<LoadingState isLoading={true} />
84+
) : (
85+
<Select
86+
key={key}
87+
value={value}
88+
onValueChange={(value) => {
89+
handleInstructionClick(
90+
instructions.find((inst) => inst.value === value)!
91+
)
92+
}}
93+
>
94+
<SelectTrigger className="inline-flex items-center justify-center relative shrink-0 ring-offset-2 ring-offset-bg-300 ring-accent-main-100 focus-visible:outline-none focus-visible:ring-1 tc-shadow-none disabled:pointer-events-none disabled:opacity-50 disabled:shadow-none disabled:drop-shadow-none max-w-full min-w-0 pl-1.5 pr-1 h-7 ml-0.5 mr-1 hover:bg-bg-200 hover:border-border-400 border-0.5 text-sm rounded-md border-transparent transition text-text-500 hover:text-text-200 font-tiempos !tc-font-normal tc-gap-x-1">
95+
<SelectValue placeholder="Let Claude think" />
96+
</SelectTrigger>
97+
<SelectContent className="z-50 bg-bg-200 backdrop-blur-xl border-0.5 border-border-300 rounded-xl min-w-[12rem] overflow-hidden p-1 text-text-200 shadow-[0_0_0_0.5px_rgba(0,0,0,0.1),0_0_20px_rgba(0,0,0,0.05),0_1px_5px_rgba(0,0,0,0.1)] w-64 sm:w-[28rem] md:tc-w-[32rem] !z-30">
98+
<div className="sm:flex justify-between items-center flex-1 text-xs font-medium text-text-300 px-1.5 pt-1 pb-1.5 min-h-5">
99+
<div className="translate-y-[0.5px]">
100+
Which model instruction should Claude use?
101+
</div>
102+
<a
103+
href="https://github.com/richards199999/Thinking-Claude"
104+
target="_blank"
105+
rel="noopener noreferrer"
111106
>
112-
<span
113-
title="Open-souced on GitHub"
114-
className="tc-flex tc-items-center tc-justify-center"
107+
<Badge
108+
variant="default"
109+
className="border-0.5 border-border-300 tc-flex tc-items-center tc-gap-2 tc-cursor-pointer hover:!bg-accent-main-100 hover:!text-oncolor-100 hover:!border-transparent transition tc-font-normal tc-text-xs tc-flex-nowrap"
115110
>
116-
<GitHubLogoIcon className="tc-size-3" />
117-
</span>
118-
<span className="tc-flex tc-items-center tc-justify-center">
119-
{starsCount && (
120-
<span
121-
className="tc-text-xs"
122-
title={`${starsCount.toLocaleString()} stars`}
123-
>
124-
{formatStarCount(starsCount)}
125-
</span>
126-
)}
127-
<StarFilledIcon className="tc-size-3" />
128-
</span>
129-
</Badge>
130-
</a>
131-
</div>
132-
<div className="grid sm:grid-cols-2 tc-gap-2 mt-0.5 pb-1 px-1">
133-
<div className="min-h-0">
134-
<div className="overflow-x-visible overflow-y-auto scroll-pb-6 min-h-[0px] [scrollbar-color:hsl(var(--text-500))] scroll-smooth overscroll-contain [-webkit-overflow-scrolling:touch] [&::-webkit-scrollbar]:mt-4 [&::-webkit-scrollbar]:w-[0.25rem] [&::-webkit-scrollbar-track]:bg-transparent [&::-webkit-scrollbar-track]:my-1 [&::-webkit-scrollbar-thumb]:rounded-[1em] [&::-webkit-scrollbar-thumb]:border-[0.25rem] [&::-webkit-scrollbar-thumb]:border-transparent [&::-webkit-scrollbar-thumb]:bg-clip-padding [&::-webkit-scrollbar-thumb]:bg-text-500/80 [&::-webkit-scrollbar-thumb:hover]:bg-text-500 sm:mr-1 min-h-40 max-h-64">
135-
<SelectGroup>
136-
{instructions.map((instruction) => (
137-
<div
138-
key={instruction.value}
139-
onMouseEnter={() => setHoveredInstruction(instruction)}
140-
onMouseLeave={() => setHoveredInstruction(null)}
141-
>
142-
<InstructionItem
143-
value={instruction.value}
144-
label={instruction.label}
145-
/>
146-
</div>
147-
))}
148-
<button
149-
onClick={handleClear}
150-
className="py-1 px-2 rounded-md cursor-pointer whitespace-nowrap overflow-hidden text-ellipsis grid grid-cols-[minmax(0,_1fr)_auto] gap-2 items-center outline-none select-none [&[data-highlighted]]:bg-bg-300 [&[data-highlighted]]:text-text-000 bg-transparent border-0.5 border-border-300 hover:!bg-accent-main-100 hover:!text-oncolor-100 hover:!border-transparent transition mb-1 mt-4 !rounded-lg text-center text-sm font-medium w-full"
111+
<span
112+
title="Open-souced on GitHub"
113+
className="tc-flex tc-items-center tc-justify-center"
151114
>
152-
Clear selection
153-
</button>
154-
</SelectGroup>
155-
</div>
115+
<GitHubLogoIcon className="tc-size-3" />
116+
</span>
117+
<span className="tc-flex tc-items-center tc-justify-center">
118+
{starsCount && (
119+
<span
120+
className="tc-text-xs"
121+
title={`${starsCount} stars`}
122+
>
123+
{formatStarCount(starsCount)}
124+
</span>
125+
)}
126+
<StarFilledIcon className="tc-size-3" />
127+
</span>
128+
</Badge>
129+
</a>
156130
</div>
157-
<div className="flex flex-col">
158-
<InstructionDescription
159-
error={error}
160-
selectedInstruction={displayedInstruction}
161-
/>
131+
<div className="grid sm:grid-cols-2 tc-gap-2 mt-0.5 pb-1 px-1">
132+
<div className="min-h-0">
133+
<div className="overflow-x-visible overflow-y-auto scroll-pb-6 min-h-[0px] [scrollbar-color:hsl(var(--text-500))] scroll-smooth overscroll-contain [-webkit-overflow-scrolling:touch] [&::-webkit-scrollbar]:mt-4 [&::-webkit-scrollbar]:w-[0.25rem] [&::-webkit-scrollbar-track]:bg-transparent [&::-webkit-scrollbar-track]:my-1 [&::-webkit-scrollbar-thumb]:rounded-[1em] [&::-webkit-scrollbar-thumb]:border-[0.25rem] [&::-webkit-scrollbar-thumb]:border-transparent [&::-webkit-scrollbar-thumb]:bg-clip-padding [&::-webkit-scrollbar-thumb]:bg-text-500/80 [&::-webkit-scrollbar-thumb:hover]:bg-text-500 sm:mr-1 min-h-40 max-h-64">
134+
<SelectGroup>
135+
{instructions.map((instruction) => (
136+
<div
137+
key={instruction.value}
138+
onMouseEnter={() => setHoveredInstruction(instruction)}
139+
onMouseLeave={() => setHoveredInstruction(null)}
140+
>
141+
<InstructionItem
142+
value={instruction.value}
143+
label={instruction.label}
144+
/>
145+
</div>
146+
))}
147+
<button
148+
onClick={handleClear}
149+
className="py-1 px-2 rounded-md cursor-pointer whitespace-nowrap overflow-hidden text-ellipsis grid grid-cols-[minmax(0,_1fr)_auto] gap-2 items-center outline-none select-none [&[data-highlighted]]:bg-bg-300 [&[data-highlighted]]:text-text-000 bg-transparent border-0.5 border-border-300 hover:!bg-accent-main-100 hover:!text-oncolor-100 hover:!border-transparent transition mb-1 mt-4 !rounded-lg text-center text-sm font-medium w-full"
150+
>
151+
Clear selection
152+
</button>
153+
</SelectGroup>
154+
</div>
155+
</div>
156+
<div className="flex flex-col">
157+
<InstructionDescription
158+
error={error}
159+
selectedInstruction={displayedInstruction}
160+
/>
161+
</div>
162162
</div>
163-
</div>
164-
</SelectContent>
165-
</Select>
163+
</SelectContent>
164+
</Select>
165+
)}
166166
</div>
167167
)
168168
}

extensions/chrome/src/hooks/use-model-instructions.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ export const useModelInstructions = () => {
2323

2424
const fetchModelInstructions = async (signal: AbortSignal) => {
2525
try {
26-
setIsLoading(true)
2726
setError(null)
2827

2928
const response = await fetch(GITHUB_API_URL, { signal })
@@ -95,8 +94,6 @@ export const useModelInstructions = () => {
9594
err instanceof Error ? err.message : "Failed to load model instructions"
9695
)
9796
setInstructions([])
98-
} finally {
99-
setIsLoading(false)
10097
}
10198
}
10299

@@ -140,6 +137,11 @@ export const useModelInstructions = () => {
140137
fetchStarsCount(signal),
141138
fetchModelInstructions(signal),
142139
])
140+
} catch (err) {
141+
// Handle any errors from the parallel fetches
142+
if (err instanceof Error && err.name !== "AbortError") {
143+
console.error("Error during parallel fetches:", err)
144+
}
143145
} finally {
144146
setIsLoading(false)
145147
}

0 commit comments

Comments
 (0)