Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default async function Page({ searchParams }: PageProps) {
const resolvedParams = await searchParams;

const events = await getAllEvents({
query: resolvedParams.query,
query: resolvedParams.query?.trim() || undefined,
mode: resolvedParams.mode,
tag: resolvedParams.tag,
sortBy: resolvedParams.sortBy,
Expand Down
8 changes: 5 additions & 3 deletions components/SearchFilters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ export default function SearchFilters() {
const [search, setSearch] = useState(searchParams.get("query") || "");

const handleFilterChange = useCallback((key: string, value: string) => {
const trimmedValue = value.trim();
const params = new URLSearchParams(searchParams.toString());
if (value && value !== "All") params.set(key, value);
if (trimmedValue && trimmedValue !== "All") params.set(key, trimmedValue);
else params.delete(key);
if (key !== "page") params.delete("page");

const queryString = params.toString();
router.push(queryString ? `${pathname}?${queryString}` : pathname, { scroll: false });
captureEvent(POSTHOG_EVENTS.EVENT_FILTER_CHANGED, { filter: key, value });
captureEvent(POSTHOG_EVENTS.EVENT_FILTER_CHANGED, { filter: key, value: trimmedValue });
}, [pathname, router, searchParams]);

const handleClearFilters = useCallback(() => {
Expand All @@ -52,7 +53,7 @@ export default function SearchFilters() {
const activeMode = searchParams.get("mode") || "All";
const activeTag = searchParams.get("tag") || "All";
const activeSort = searchParams.get("sortBy") || "";
const hasActiveFilters = Boolean(search || (activeMode !== "All") || (activeTag !== "All") || activeSort);
const hasActiveFilters = Boolean(search.trim() || activeMode !== "All" || activeTag !== "All" || activeSort);
Comment thread
coderabbitai[bot] marked this conversation as resolved.

const selectClass =
"rounded-lg border border-border bg-card px-3 py-1.5 text-sm text-foreground transition cursor-pointer focus:outline-none focus:ring-2 focus:ring-ring";
Expand All @@ -76,6 +77,7 @@ export default function SearchFilters() {
{hasActiveFilters && (
<button
type="button"
id="clear-filters-btn"
onClick={handleClearFilters}
className="inline-flex shrink-0 items-center gap-1.5 rounded-xl border border-border bg-card px-4 py-3 text-xs font-semibold text-muted-foreground hover:bg-accent hover:text-foreground transition cursor-pointer shadow-sm"
aria-label="Clear all filters"
Expand Down
5 changes: 3 additions & 2 deletions lib/actions/event.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ const escapeRegex = (text: string) => text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "
function buildFilter(filters?: EventFilters): QueryFilter<IEvent> {
const queryCondition: QueryFilter<IEvent> = {};

if (filters?.query) {
const safeQuery = escapeRegex(filters.query);
const trimmedQuery = filters?.query?.trim();
if (trimmedQuery) {
const safeQuery = escapeRegex(trimmedQuery);
queryCondition.$or = [
{ title: { $regex: safeQuery, $options: "i" } },
{ description: { $regex: safeQuery, $options: "i" } },
Expand Down