Skip to content

Commit

Permalink
v1 added view more options
Browse files Browse the repository at this point in the history
  • Loading branch information
git-create-devben committed Jul 22, 2024
1 parent 30dfd41 commit 61fdca1
Show file tree
Hide file tree
Showing 14 changed files with 159 additions and 74 deletions.
2 changes: 1 addition & 1 deletion app/api/gemini/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async function getLocalServices(query: string, latitude: string, longitude: stri
);
}

return response.data.results.slice(0, 5).map((place: any) => ({
return response.data.results.slice(0, 8).map((place: any) => ({
name: place.name,
address: place.vicinity,
rating: place.rating,
Expand Down
36 changes: 19 additions & 17 deletions app/chat/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,31 @@ export default function Chat() {
});
return (
<main className=" flex h-screen w-[100%] bg-black">
<FirstVisitPopup />
<FirstVisitPopup />
<div className=" hidden lg:block">
<Sidebar />
</div>
<div className=" bg-[#1212] h-screen flex-1">
<div className="flex flex-col">
<nav className="flex justify-between p-4">
<span className="text-[#caccce] font-medium text-3xl cursor-pointer" onClick={() => window.location.href = "/"}>Loca</span>
<Image
src={image}
alt="user"
className="rounded-full"
width={50}
height={50}
/>
</nav>
<div className="self-center">
<Main />
<nav className="flex justify-between p-4">
<span
className="text-[#caccce] font-medium text-3xl cursor-pointer"
onClick={() => (window.location.href = "/")}
>
Loca
</span>
<Image
src={image}
alt="user"
className="rounded-full"
width={50}
height={50}
/>
</nav>
<div className="self-center">
<Main />
</div>
</div>

</div>


</div>
</main>
);
Expand Down
9 changes: 4 additions & 5 deletions auth.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import NextAuth from "next-auth"

export const { handlers, signIn, signOut, auth } = NextAuth({
providers: [],
})
export async function getServerSideProps(context: { req: { cookies: any; }; }) {
console.log('Cookies in getServerSideProps:', context.req.cookies);
return { props: {} };
}
32 changes: 18 additions & 14 deletions components/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ import { SkeletonCard } from "./loading";
import FirstVisitPopup from "./firstvisitpopup";
import ReactMarkdown from "react-markdown";
import { cn } from "@/lib/utils";
import ViewMore from "./viewmore";
import { Button } from "./ui/button";

type Location = {
latitude: number | null;
longitude: number | null;
}
};

const Main: React.FC = () => {
const [user, setUser] = useState(auth.currentUser);
Expand Down Expand Up @@ -157,7 +159,7 @@ const Main: React.FC = () => {
}
);

const data = response.data;
const data = response.data;
if (data.error) {
console.log(data.error);
throw new Error(data.error);
Expand All @@ -173,13 +175,13 @@ const Main: React.FC = () => {
{formattedResponse}
{data.services && data.services.length > 0 && (
<div className="mt-4 w-full">
<article>
Check this out or <Link href="/">View More</Link>
<article className="flex gap-2">
Check this out or <ViewMore data={data.services.slice(2)} />
</article>

{data.services && (
<div className="w-full grid grid-rows-2">
{data.services.slice(0, 2).map((service:ServiceItem ) => (
{data.services.slice(0, 2).map((service: ServiceItem) => (
<LocalServiceCard
key={service.place_id}
name={service.name}
Expand Down Expand Up @@ -488,7 +490,7 @@ const CardCarousel = () => {
);
};

const LocalServiceCard: React.FC<LocalServiceCardProps> = ({
export const LocalServiceCard: React.FC<LocalServiceCardProps> = ({
name,
address,
rating,
Expand All @@ -502,14 +504,16 @@ const LocalServiceCard: React.FC<LocalServiceCardProps> = ({
<p className="text-white">
Rating: {rating} ({user_ratings_total} reviews)
</p>
<Link
href={`https://www.google.com/maps/place/?q=place_id:${place_id}`}
target="_blank"
rel="noopener noreferrer"
className="text-blue-400 hover:text-blue-300"
>
View on Google Maps
</Link>
<Button className="bg-blue-400 rounded-full p-6 hover:bg-blue-300 text-black">
<Link
href={`https://www.google.com/maps/place/?q=place_id:${place_id}`}
target="_blank"
rel="noopener noreferrer"
className="text-black"
>
Book Now
</Link>
</Button>
</div>
);
};
8 changes: 6 additions & 2 deletions components/navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { useState, useEffect } from "react";

export default function Navbar() {
const [user, setUser] = useState(auth.currentUser);

useEffect(() => {
const unsubscribe = onAuthStateChanged(auth, (currentUser) => {
if(!currentUser){
Expand All @@ -18,6 +17,11 @@ export default function Navbar() {

return () => unsubscribe();
}, []);

const redirectToChat = () => {
window.location.href ="/chat"
console.log("redirect to chat")
}
return (
<div className="flex justify-between items-center p-5">
<span className="text-[#caccce] font-medium text-2xl">Loca</span>
Expand All @@ -26,7 +30,7 @@ export default function Navbar() {
{!user?(
<Button onClick={SignIn} className="bg-blue-400 rounded-full p-6 hover:bg-blue-300">SignIn </Button>
):(
<Button className="bg-blue-400 rounded-full p-6 hover:bg-blue-300"> <Link href="/chat">Chat</Link> </Button>
<Button className="bg-blue-400 rounded-full p-6 hover:bg-blue-300 cursor-pointer"><Link href={'/chat'}>Chat</Link></Button>
)}
</nav>
</div>
Expand Down
27 changes: 18 additions & 9 deletions components/viewmore.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from "react";
import {
Sheet,
SheetContent,
Expand All @@ -8,20 +7,30 @@ import {
SheetTrigger,
} from "@/components/ui/sheet";
import axios from "axios";
import { LocalServiceCard } from "./main";

const ViewMore = async () => {

const ViewMore: React.FC<ViewMoreProps> = ({ data }) => {
return (
<main>
<Sheet>
<SheetTrigger>Open</SheetTrigger>
<SheetContent>
<SheetHeader>
<SheetTitle>Are you absolutely sure?</SheetTitle>
<SheetTrigger>View More</SheetTrigger>
<SheetContent className="bg-[#1e1f20] text-white border-none">
<SheetHeader className="mt-5">
<SheetTitle className="text-white text-md">These are the Rest of Services find near you.</SheetTitle>
<SheetDescription>
This action cannot be undone. This will permanently delete your
account and remove your data from our servers.

</SheetDescription>

{data.map((service:ServiceItem ) => (
<LocalServiceCard
key={service.place_id}
name={service.name}
address={service.address}
rating={service.rating}
user_ratings_total={service.user_ratings_total}
place_id={service.place_id}
/>
))}
</SheetHeader>
</SheetContent>
</Sheet>
Expand Down
15 changes: 0 additions & 15 deletions lib/c.ts

This file was deleted.

59 changes: 59 additions & 0 deletions lib/c.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
'use server'
import { GoogleAuthProvider, signOut, signInWithPopup } from "firebase/auth";
import { auth } from "../lib/firebase";
import toast from "react-hot-toast";
import Cookies from "js-cookie";
import { useRouter } from "next/navigation";
import { setCookie } from "cookies-next";
import { cookies } from "next/headers";

const SignUpAction = () => {
const provider = new GoogleAuthProvider();
// const router = useRouter();
const cook = cookies()
signInWithPopup(auth, provider)
.then((res) => {
const credential = GoogleAuthProvider.credentialFromResult(res);
const token = credential?.accessToken;
const user = res.user;
console.log(user);
console.log(token);
if (token) {
console.log("Token received from Firebase:", token);

// Set the token as an HTTP-only cookie
// setCookie('token', token, {
// maxAge: 7 * 24 * 60 * 60, // 7 days
// path: '/',
// secure: process.env.NODE_ENV === 'production',
// httpOnly: true,
// sameSite: 'strict'
// });
cook.set({
name: "token",
value: token,
path: "/",
httpOnly: true,
});

console.log("Cookie set with token");

// window.localStorage.setItem("user", JSON.stringify(user));
toast.success("SignIn successful");
// router.push("/chat");
} else {
console.error("No token received from Firebase");
toast.error("SignIn failed: No token received");
}
})
.catch((error) => {
const errorCode = error.code;
const errorMessage = error.message;
const email = error.customData.email;
const credential = GoogleAuthProvider.credentialFromError(error);
console.error(error, errorCode, errorMessage, email, credential);
toast.error("SignIn failed");
});
};

export default SignUpAction
19 changes: 11 additions & 8 deletions lib/signIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { auth } from './firebase';
import toast from 'react-hot-toast';
import Cookies from 'js-cookie';
import { useRouter } from 'next/navigation';

import { setCookie } from 'cookies-next';
const signIn = () => {
const provider = new GoogleAuthProvider();
// const router = useRouter();
Expand All @@ -13,14 +13,17 @@ const signIn = () => {
const credential = GoogleAuthProvider.credentialFromResult(res);
const token = credential?.accessToken;
const user = res.user;
console.log(user);
console.log(token);


Cookies.set('token', String(token), {
expires: 7,
secure: true,
sameSite: 'strict',
});
setCookie('token', token, {
maxAge: 60 * 3 * 24,
expires: new Date(60 * 3 * 24)
})
// Cookies.set('token', String(token), {
// expires: 7,
// secure: true,
// sameSite: 'strict',
// });
window.localStorage.setItem('user', JSON.stringify(user));
toast.success('SignIn successful');
// router.push('/chat');
Expand Down
9 changes: 7 additions & 2 deletions middleware.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';
import Cookies from 'js-cookie';
import { getCookie, hasCookie} from 'cookies-next';
import { cookies } from 'next/headers';
import { auth } from './lib/firebase';


export function middleware(req: NextRequest) {
const res = NextResponse.next();
const token = req.cookies.get('token');

console.log('token', token);

if (!token && req.nextUrl.pathname === '/chat') {
// Redirect unauthorized users trying to access /chat
return NextResponse.redirect(new URL('/', req.url));
Expand Down
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"constants-browserify": "^1.0.0",
"cookies-next": "^4.2.1",
"crypto-browserify": "^3.12.0",
"embla-carousel-autoplay": "^8.1.6",
"embla-carousel-react": "^7.1.0",
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
"@/*": ["./*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts", "app/api/gemini/route.ts", "lib/c.ts"],
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts", "app/api/gemini/route.ts", "lib/c.tsx"],
"exclude": ["node_modules"]
}
3 changes: 3 additions & 0 deletions types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@
text: React.ReactNode;
};

interface ViewMoreProps {
data: ServiceItem[];
}

// export {ConversationItem, LocalServiceCardProps, ServiceItem,Location}

0 comments on commit 61fdca1

Please sign in to comment.