Improve loading states + hack fix seemingly spurious issue with code mirror ranges

This commit is contained in:
bkellam 2024-09-24 10:19:52 -07:00
parent fa8ff8088a
commit f5651515b2
3 changed files with 36 additions and 15 deletions

View file

@ -123,9 +123,6 @@ export default function SearchPage() {
size="sm"
defaultQuery={searchQuery}
/>
{isLoading && (
<SymbolIcon className="h-4 w-4 animate-spin" />
)}
</div>
<SettingsDropdown
menuButtonClassName="w-8 h-8"
@ -155,15 +152,22 @@ export default function SearchPage() {
{/* Search Results & Code Preview */}
<ResizablePanelGroup direction="horizontal">
<ResizablePanel minSize={20}>
<SearchResultsPanel
fileMatches={fileMatches}
onOpenFileMatch={(fileMatch) => {
setSelectedFile(fileMatch);
}}
onMatchIndexChanged={(matchIndex) => {
setSelectedMatchIndex(matchIndex);
}}
/>
{isLoading ? (
<div className="flex flex-col items-center justify-center h-full gap-2">
<SymbolIcon className="h-6 w-6 animate-spin" />
<p className="font-semibold text-center">Searching...</p>
</div>
) : (
<SearchResultsPanel
fileMatches={fileMatches}
onOpenFileMatch={(fileMatch) => {
setSelectedFile(fileMatch);
}}
onMatchIndexChanged={(matchIndex) => {
setSelectedMatchIndex(matchIndex);
}}
/>
)}
</ResizablePanel>
<ResizableHandle withHandle={selectedFile !== undefined} />
<ResizablePanel

View file

@ -28,6 +28,15 @@ export const SearchResultsPanel = ({
onOpenFileMatch,
onMatchIndexChanged,
}: SearchResultsPanelProps) => {
if (fileMatches.length === 0) {
return (
<div className="flex flex-col items-center justify-center h-full">
<p className="text-sm text-muted-foreground">No results found</p>
</div>
);
}
return (
<ScrollArea className="h-full">
{fileMatches.map((fileMatch, index) => (

View file

@ -17,9 +17,17 @@ export function useExtensionWithDependency(
useEffect(() => {
if (view) {
view.dispatch({
effects: compartment.reconfigure(extensionFactory()),
});
try {
view.dispatch({
effects: compartment.reconfigure(extensionFactory()),
});
// @note: we were getting "RangeError: Position X is out of range for changeset of length Y" errors
// spuriously for some reason. This is a dirty hack to prevent codemirror from crashing the app
// in those cases.
} catch (error) {
console.error(error);
}
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, deps);