fixed some statuses and filters
This commit is contained in:
1 parent
34e8fef9b6
commit
edf503e329
20 files changed
+355
-214
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import * as CollapsiblePrimitive from "@radix-ui/react-collapsible";
|
||||
import * as PopoverPrimitive from "@radix-ui/react-popover";
|
||||
import { Check, ChevronsUpDown, Search, X, Loader2 } from "lucide-react";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
@@ -20,25 +20,14 @@ export interface InfiniteSelectProps {
|
||||
required?: boolean;
|
||||
error?: string;
|
||||
disabled?: boolean;
|
||||
/** True while the first page is being fetched. */
|
||||
loading?: boolean;
|
||||
/** True while the next page is being fetched. */
|
||||
isLoadingMore?: boolean;
|
||||
/** Whether more pages are available to load. */
|
||||
hasNextPage?: boolean;
|
||||
/** Called when the user scrolls to the bottom of the list. */
|
||||
onLoadMore?: () => void;
|
||||
/** Controlled search text; drives server-side search + page reset. */
|
||||
searchValue?: string;
|
||||
onSearchChange?: (value: string) => void;
|
||||
}
|
||||
|
||||
// ─── Collapsible aliases ──────────────────────────────────────────────────────
|
||||
|
||||
const Collapsible = CollapsiblePrimitive.Root;
|
||||
const CollapsibleTrigger = CollapsiblePrimitive.Trigger;
|
||||
const CollapsibleContent = CollapsiblePrimitive.Content;
|
||||
|
||||
/**
|
||||
* Searchable select with infinite scroll.
|
||||
*
|
||||
@@ -81,14 +70,12 @@ export function InfiniteSelect({
|
||||
|
||||
const loadingRef = useRef(false);
|
||||
|
||||
// Reset loading ref when the query transitions out of loading state
|
||||
useEffect(() => {
|
||||
if (!isLoadingMore) {
|
||||
loadingRef.current = false;
|
||||
}
|
||||
}, [isLoadingMore]);
|
||||
|
||||
// ── Infinite scroll: load more when the sentinel becomes visible ──
|
||||
useEffect(() => {
|
||||
if (!open || !sentinelRef.current || !hasNextPage || isLoadingMore) return;
|
||||
const el = sentinelRef.current;
|
||||
@@ -114,18 +101,18 @@ export function InfiniteSelect({
|
||||
</label>
|
||||
)}
|
||||
|
||||
<Collapsible
|
||||
<PopoverPrimitive.Root
|
||||
open={open}
|
||||
onOpenChange={(next) => {
|
||||
if (!disabled) setOpen(next);
|
||||
}}
|
||||
>
|
||||
<CollapsibleTrigger asChild>
|
||||
<PopoverPrimitive.Trigger asChild>
|
||||
<button
|
||||
type="button"
|
||||
disabled={disabled}
|
||||
className={cn(
|
||||
"flex h-8 w-full items-center justify-between rounded-md border bg-background px-3 py-2",
|
||||
"flex h-8 w-full items-center justify-between rounded-md border border-input bg-transparent dark:bg-input/30 px-3 py-2",
|
||||
"text-sm ring-offset-background transition-colors duration-150",
|
||||
"focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-0",
|
||||
"disabled:cursor-not-allowed disabled:opacity-50",
|
||||
@@ -133,7 +120,7 @@ export function InfiniteSelect({
|
||||
open && !error && "ring-2 ring-ring ring-offset-0 border-transparent",
|
||||
)}
|
||||
>
|
||||
<span className={cn("truncate text-left", !selected && "text-muted-foreground/60")}>
|
||||
<span className={cn("truncate text-left", !selected && "text-muted-foreground")}>
|
||||
{selected ? selected.label : placeholder}
|
||||
</span>
|
||||
|
||||
@@ -154,75 +141,85 @@ export function InfiniteSelect({
|
||||
/>
|
||||
</div>
|
||||
</button>
|
||||
</CollapsibleTrigger>
|
||||
</PopoverPrimitive.Trigger>
|
||||
|
||||
<CollapsibleContent className="absolute z-50 top-full left-0 right-0 mt-1 rounded-md border border-border bg-card shadow-lg overflow-hidden">
|
||||
{onSearchChange && (
|
||||
<div className="flex items-center gap-2 px-3 py-2 border-b border-border bg-muted/20">
|
||||
<Search size={13} className="text-muted-foreground shrink-0" />
|
||||
<input
|
||||
type="text"
|
||||
value={searchValue ?? ""}
|
||||
onChange={(e) => onSearchChange(e.target.value)}
|
||||
placeholder={searchPlaceholder}
|
||||
className="flex-1 bg-transparent text-sm text-foreground placeholder:text-muted-foreground/50 focus:outline-none"
|
||||
/>
|
||||
{searchValue && (
|
||||
<button
|
||||
type="button"
|
||||
tabIndex={-1}
|
||||
onMouseDown={() => onSearchChange?.("")}
|
||||
className="text-muted-foreground hover:text-foreground transition-colors"
|
||||
>
|
||||
<X size={12} />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="max-h-60 overflow-y-auto scrollbar-thin py-1">
|
||||
{loading && options.length === 0 ? (
|
||||
<p className="px-3 py-4 text-sm text-muted-foreground text-center flex items-center justify-center gap-2">
|
||||
<Loader2 size={14} className="animate-spin" /> Loading...
|
||||
</p>
|
||||
) : options.length === 0 ? (
|
||||
<p className="px-3 py-4 text-sm text-muted-foreground text-center">Netije tapylmady</p>
|
||||
) : (
|
||||
options.map((opt) => {
|
||||
const isSelected = opt.value === value;
|
||||
return (
|
||||
<PopoverPrimitive.Portal>
|
||||
<PopoverPrimitive.Content
|
||||
align="start"
|
||||
side="bottom"
|
||||
sideOffset={4}
|
||||
collisionPadding={16}
|
||||
avoidCollisions
|
||||
style={{ width: "var(--radix-popover-trigger-width)" }}
|
||||
className="z-50 rounded-md border border-border bg-card shadow-lg overflow-hidden max-h-[var(--radix-popover-content-available-height)] flex flex-col"
|
||||
>
|
||||
{onSearchChange && (
|
||||
<div className="flex items-center gap-2 px-3 py-2 border-b border-border bg-muted/20 shrink-0">
|
||||
<Search size={13} className="text-muted-foreground shrink-0" />
|
||||
<input
|
||||
type="text"
|
||||
value={searchValue ?? ""}
|
||||
onChange={(e) => onSearchChange(e.target.value)}
|
||||
placeholder={searchPlaceholder}
|
||||
className="flex-1 bg-transparent text-sm text-foreground placeholder:text-muted-foreground/50 focus:outline-none"
|
||||
/>
|
||||
{searchValue && (
|
||||
<button
|
||||
key={opt.value}
|
||||
type="button"
|
||||
onMouseDown={(e) => {
|
||||
e.preventDefault();
|
||||
handleSelect(opt.value);
|
||||
}}
|
||||
className={cn(
|
||||
"flex items-center justify-between w-full text-left px-3 py-2 text-sm transition-colors",
|
||||
"hover:bg-accent hover:text-accent-foreground",
|
||||
isSelected && "text-primary font-medium bg-primary/10",
|
||||
)}
|
||||
tabIndex={-1}
|
||||
onMouseDown={() => onSearchChange?.("")}
|
||||
className="text-muted-foreground hover:text-foreground transition-colors"
|
||||
>
|
||||
<span>{opt.label}</span>
|
||||
{isSelected && <Check size={13} className="text-primary shrink-0" />}
|
||||
<X size={12} />
|
||||
</button>
|
||||
);
|
||||
})
|
||||
)}
|
||||
|
||||
{hasNextPage && (
|
||||
<div ref={sentinelRef} className="px-3 py-2 text-xs text-muted-foreground text-center">
|
||||
{isLoadingMore && (
|
||||
<span className="inline-flex items-center gap-1.5">
|
||||
<Loader2 size={12} className="animate-spin" /> Loading...
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</CollapsibleContent>
|
||||
</Collapsible>
|
||||
|
||||
<div className="max-h-60 overflow-y-auto scrollbar-thin py-1">
|
||||
{loading && options.length === 0 ? (
|
||||
<p className="px-3 py-4 text-sm text-muted-foreground text-center flex items-center justify-center gap-2">
|
||||
<Loader2 size={14} className="animate-spin" /> Loading...
|
||||
</p>
|
||||
) : options.length === 0 ? (
|
||||
<p className="px-3 py-4 text-sm text-muted-foreground text-center">Netije tapylmady</p>
|
||||
) : (
|
||||
options.map((opt) => {
|
||||
const isSelected = opt.value === value;
|
||||
return (
|
||||
<button
|
||||
key={opt.value}
|
||||
type="button"
|
||||
onMouseDown={(e) => {
|
||||
e.preventDefault();
|
||||
handleSelect(opt.value);
|
||||
}}
|
||||
className={cn(
|
||||
"flex items-center justify-between w-full text-left px-3 py-2 text-sm transition-colors",
|
||||
"hover:bg-accent hover:text-accent-foreground",
|
||||
isSelected && "text-primary font-medium bg-primary/10",
|
||||
)}
|
||||
>
|
||||
<span>{opt.label}</span>
|
||||
{isSelected && <Check size={13} className="text-primary shrink-0" />}
|
||||
</button>
|
||||
);
|
||||
})
|
||||
)}
|
||||
|
||||
{hasNextPage && (
|
||||
<div ref={sentinelRef} className="px-3 py-2 text-xs text-muted-foreground text-center">
|
||||
{isLoadingMore && (
|
||||
<span className="inline-flex items-center gap-1.5">
|
||||
<Loader2 size={12} className="animate-spin" /> Loading...
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</PopoverPrimitive.Content>
|
||||
</PopoverPrimitive.Portal>
|
||||
</PopoverPrimitive.Root>
|
||||
|
||||
{error && (
|
||||
<p className="mt-1.5 text-xs text-destructive font-medium flex items-center gap-1.5">
|
||||
|
||||
Reference in new issue
Block a user