Skip to content

Commit

Permalink
update search
Browse files Browse the repository at this point in the history
  • Loading branch information
ocitocit committed Oct 17, 2023
1 parent c428356 commit 58385b1
Showing 1 changed file with 46 additions and 3 deletions.
49 changes: 46 additions & 3 deletions components/navbar/Search.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,53 @@
'use client';

import useCountries from '@/hooks/useCountries';
import useSearchModal from '@/hooks/useSearchModal';
import { differenceInDays } from 'date-fns';
import { useSearchParams } from 'next/navigation';
import { useMemo } from 'react';
import { BiSearch } from 'react-icons/bi';

const Search = () => {
const searchModal = useSearchModal();
const params = useSearchParams();
const { getByValue } = useCountries();

const locationValue = params?.get('locationValue');
const startDate = params?.get('startDate');
const endDate = params?.get('endDate');
const guestCount = params?.get('guestCount');

const locationLabel = useMemo(() => {
if (locationValue) {
return getByValue(locationValue as string)?.label;
}

return 'Anywhere';
}, [locationValue, getByValue])

const durationLabel = useMemo(() => {
if (startDate && endDate) {
const start = new Date(startDate as string);
const end = new Date(endDate as string);
let diff = differenceInDays(end, start);

if (diff === 0) {
diff = 1;
}

return `${diff} Days`;
}

return 'Any week';
}, [startDate, endDate])

const guestLabel = useMemo(() => {
if (guestCount) {
return `${guestCount} Guests`;
}

return 'Add Guests';
}, [guestCount])

return (
<div
Expand Down Expand Up @@ -36,7 +79,7 @@ const Search = () => {
font-semibold
"
>
Anywhere
{locationLabel}
</div>
<div
className="
Expand All @@ -50,7 +93,7 @@ const Search = () => {
sm:block
"
>
Any Week
{durationLabel}
</div>
<div
className="
Expand All @@ -64,7 +107,7 @@ const Search = () => {
text-gray-600
"
>
<div className="hidden sm:block"> Add Guest</div>
<div className="hidden sm:block">{guestLabel}</div>
<div
className="
rounded-full
Expand Down

0 comments on commit 58385b1

Please sign in to comment.