Skip to content

Commit

Permalink
code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
artemelyashevich committed May 13, 2024
1 parent 36685aa commit c22cde9
Show file tree
Hide file tree
Showing 21 changed files with 193 additions and 176 deletions.
5 changes: 4 additions & 1 deletion app/actions/favorite-actions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
"use server"

import { revalidatePath } from "next/cache"
import { createFavorite, unfavoriteHome } from "../repo/favorite-repo"
import {
createFavorite,
unfavoriteHome
} from "../repo/favorite-repo"

export async function addToFavorite(formData: FormData) {
const pathname = String(formData.get("pathname"))
Expand Down
8 changes: 7 additions & 1 deletion app/actions/home-actions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
"use server"

import { redirect } from "next/navigation"
import { createHome, findHomeByUserId, updateHomeCategory, updateHomeDescription, updateHomeLocation } from "../repo/home-repo"
import {
createHome,
findHomeByUserId,
updateHomeCategory,
updateHomeDescription,
updateHomeLocation
} from "../repo/home-repo"

export async function createAirbnbHome({ userId }: { userId: string }) {
const data = await findHomeByUserId(userId)
Expand Down
6 changes: 0 additions & 6 deletions app/actions/reservation-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ import { redirect } from "next/navigation"
import { createReservation } from "../repo/reservation-repo"

export async function setReservation(formData: FormData) {
const userId = String(formData.get("userId"))
const homeId = String(formData.get("homeId"))
const startDate = String(formData.get("startDate"))
const endDate = String(formData.get("endDate"))

const data = await createReservation(formData)

redirect("/")
}
5 changes: 4 additions & 1 deletion app/api/auth/creation/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { createUser, getUserById } from "@/app/repo/user-repo";
import {
createUser,
getUserById
} from "@/app/repo/user-repo";
import { getKindeServerSession } from "@kinde-oss/kinde-auth-nextjs/server";
import { NextResponse } from "next/server";

Expand Down
5 changes: 4 additions & 1 deletion app/components/Creation/Counter.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
"use client"

import { Button } from "@/components/ui/button";
import { Minus, Plus } from "lucide-react";
import {
Minus,
Plus
} from "lucide-react";
import { useState } from "react";

export function Counter({ name }: { name: string }) {
Expand Down
10 changes: 7 additions & 3 deletions app/components/Creation/Map.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
"use client"

import { MapContainer, Marker, TileLayer } from 'react-leaflet'
import {
MapContainer,
Marker,
TileLayer
} from 'react-leaflet'
import "leaflet/dist/leaflet.css"
import { useCountries } from '../../lib/hooks'
import { icon } from 'leaflet'

const ICON = icon({
iconUrl: "https://cdn-icons-png.freepik.com/256/399/399396.png?semt=ais_hybrid",
iconSize: [20, 20]
iconSize: [20, 20]
})

export default function Map({ locationValue }: { locationValue: string }) {
Expand All @@ -24,7 +28,7 @@ export default function Map({ locationValue }: { locationValue: string }) {
attribution='&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
/>
<Marker position={position} icon={ICON}/>
<Marker position={position} icon={ICON} />
</MapContainer>
)
}
5 changes: 4 additions & 1 deletion app/components/Creation/MapFilterItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import Link from "next/link";
import { categoryItems } from "../../lib/categories";
import Image from "next/image";
import { usePathname, useSearchParams } from "next/navigation";
import {
usePathname,
useSearchParams
} from "next/navigation";
import { useCallback } from "react";
import { cn } from "@/lib/utils";
import { ICategory } from "../../types";
Expand Down
10 changes: 8 additions & 2 deletions app/components/Home/HomeCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@ import Image from "next/image";
import { IHome } from "../../types";
import Link from "next/link";
import { useCountries } from "../../lib/hooks";
import { FavoriteButton, UnfavoriteButton } from "../Creation/SubmitButtons";
import { addToFavorite, unfavorite } from "../../actions/favorite-actions";
import {
FavoriteButton,
UnfavoriteButton
} from "../Creation/SubmitButtons";
import {
addToFavorite,
unfavorite
} from "../../actions/favorite-actions";

interface IProps extends IHome {
userId: string | undefined,
Expand Down
1 change: 0 additions & 1 deletion app/components/Home/SelectCalendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'react-date-range/dist/theme/default.css';
import { DateRange } from 'react-date-range';
import { useState } from 'react';
import { eachDayOfInterval } from 'date-fns';
import { start } from 'repl';

export function SelectCalendar({
reservation
Expand Down
33 changes: 0 additions & 33 deletions app/components/Navs/FirstStep.tsx

This file was deleted.

20 changes: 18 additions & 2 deletions app/components/Navs/SearchModal.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
"use client"

import { useCountries } from "@/app/lib/hooks";
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog";
import { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectTrigger, SelectValue } from "@/components/ui/select";
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger
} from "@/components/ui/dialog";
import {
Select,
SelectContent,
SelectGroup,
SelectItem,
SelectLabel,
SelectTrigger,
SelectValue
} from "@/components/ui/select";
import { Search } from "lucide-react";
import { useState } from "react";
import { HomeMap } from "../Home/HomeMap";
Expand Down
14 changes: 12 additions & 2 deletions app/components/Navs/UserNav.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@

import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
import { LoginLink, LogoutLink, RegisterLink } from "@kinde-oss/kinde-auth-nextjs/components";
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuSeparator,
DropdownMenuTrigger
} from "@/components/ui/dropdown-menu";
import {
LoginLink,
LogoutLink,
RegisterLink
} from "@kinde-oss/kinde-auth-nextjs/components";
import { getKindeServerSession } from "@kinde-oss/kinde-auth-nextjs/server";
import { MenuIcon } from "lucide-react";
import Link from "next/link";
Expand Down
4 changes: 1 addition & 3 deletions app/create/[id]/description/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { setDescription } from "@/app/actions/home-actions";
import { BottomBar } from "@/app/components/Creation/BottomBar";
import { Counter } from "@/app/components/Creation/Counter";
import { DescriptionItem } from "@/app/components/Creation/DescriptionItem";
import { descriptionItems } from "@/app/lib/description-items";
import { updateHomeDescription } from "@/app/repo/home-repo";
import { Card, CardHeader } from "@/components/ui/card";
import { Card } from "@/components/ui/card";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { Textarea } from "@/components/ui/textarea";
Expand Down
10 changes: 9 additions & 1 deletion app/create/[id]/location/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@
import { setLocation } from "@/app/actions/home-actions";
import { BottomBar } from "@/app/components/Creation/BottomBar";
import { useCountries } from "@/app/lib/hooks";
import { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectTrigger, SelectValue } from "@/components/ui/select";
import {
Select,
SelectContent,
SelectGroup,
SelectItem,
SelectLabel,
SelectTrigger,
SelectValue
} from "@/components/ui/select";
import { Skeleton } from "@/components/ui/skeleton";
import dynamic from "next/dynamic";
import { useState } from "react";
Expand Down
2 changes: 0 additions & 2 deletions app/favorites/loading.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { Skeleton } from "@/components/ui/skeleton";
import { SkeletonLoading } from "../components/Loading/SkeletonLoading";
import SkeletonItem from "../components/Loading/SkeletonItem";

export default function FavoritesLoading() {
Expand Down
1 change: 0 additions & 1 deletion app/favorites/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { getKindeServerSession } from "@kinde-oss/kinde-auth-nextjs/server"
import { getFavorites } from "../repo/favorite-repo"
import { redirect } from "next/navigation"
import HomeCard from "../components/Home/HomeCard"
import { it } from "node:test"

export default async function Favorites() {
const { getUser } = getKindeServerSession()
Expand Down
2 changes: 1 addition & 1 deletion app/home/[id]/loading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default function HomeLoading() {
<Skeleton className="h-4 w-1/3 mt-3" />
</div>
<div className="w-1/3">
<Skeleton className="w-full h-72"/>
<Skeleton className="w-full h-72" />
</div>
</div>
</div>
Expand Down
Loading

0 comments on commit c22cde9

Please sign in to comment.