adding in stuff to make search work but still testing and stuff
This commit is contained in:
@@ -1,16 +1,14 @@
|
||||
import { $authTokens, $searchQuery } from "./recoil";
|
||||
import { useMutation, useQuery } from "react-query";
|
||||
|
||||
import { $authTokens } from "./recoil";
|
||||
import SearchResponse from "@nirvana/core/responses/search.response";
|
||||
import { User } from "@nirvana/core/models";
|
||||
import axios from "axios";
|
||||
import { nirvanaApi } from "./nirvanaApi";
|
||||
import { queryClient } from "../nirvanaApp";
|
||||
import { useRecoilValue } from "recoil";
|
||||
|
||||
export enum Querytypes {
|
||||
GET_USER_DETAILS = "GET_USER_DETAILS",
|
||||
}
|
||||
|
||||
// =========== API
|
||||
export const localHost = "http://localhost:5000/api";
|
||||
|
||||
const getUserDetails = async (
|
||||
@@ -22,6 +20,20 @@ const getUserDetails = async (
|
||||
});
|
||||
};
|
||||
|
||||
const search = async (
|
||||
idToken: string,
|
||||
searchQuery: string
|
||||
): Promise<SearchResponse> => {
|
||||
return await axios.get(localHost + `/search?query=${searchQuery}`, {
|
||||
headers: { Authorization: idToken },
|
||||
});
|
||||
};
|
||||
|
||||
// ====== QUERIES
|
||||
export enum Querytypes {
|
||||
GET_USER_DETAILS = "GET_USER_DETAILS",
|
||||
GET_SEARCH_RESULTS = "GET_SEARCH_RESULTS",
|
||||
}
|
||||
export function useGetUserDetails() {
|
||||
const authTokens = useRecoilValue($authTokens);
|
||||
|
||||
@@ -34,6 +46,16 @@ export function useGetUserDetails() {
|
||||
);
|
||||
}
|
||||
|
||||
export function useSearch() {
|
||||
const authTokens = useRecoilValue($authTokens);
|
||||
const searchQuery = useRecoilValue($searchQuery);
|
||||
|
||||
return useQuery(Querytypes.GET_SEARCH_RESULTS, () =>
|
||||
search(authTokens.idToken, searchQuery)
|
||||
);
|
||||
}
|
||||
|
||||
// =========== MUTATIONS
|
||||
export function useCreateUser() {
|
||||
return useMutation(nirvanaApi.user.createUser, {
|
||||
onSettled: (data, error) => {
|
||||
|
||||
@@ -8,3 +8,8 @@ export const $authTokens = atom<{
|
||||
key: "AUTH_TOKENS", // unique ID (with respect to other atoms/selectors)
|
||||
default: null, // default value (aka initial value)
|
||||
});
|
||||
|
||||
export const $searchQuery = atom<string>({
|
||||
key: "SEARCH_QUERY",
|
||||
default: "",
|
||||
});
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
import {
|
||||
Add,
|
||||
CardGiftcardRounded,
|
||||
ContactsRounded,
|
||||
LinkRounded,
|
||||
PushPinRounded,
|
||||
} from "@mui/icons-material";
|
||||
|
||||
export default function Conversations() {
|
||||
return (
|
||||
<>
|
||||
{/* actions navbar */}
|
||||
<div className="flex justify-end mx-10 mt-5 space-x-3">
|
||||
<span className="hover:bg-slate-500 p-1 rounded-full cursor-pointer flex justify-center items-center">
|
||||
<ContactsRounded className="text-slate-100" fontSize="small" />
|
||||
</span>
|
||||
|
||||
<span className="hover:bg-slate-500 p-1 rounded-full cursor-pointer flex justify-center items-center">
|
||||
<LinkRounded className="text-slate-100" fontSize="small" />
|
||||
</span>
|
||||
|
||||
<span className="hover:bg-slate-500 p-1 rounded-full cursor-pointer flex justify-center items-center">
|
||||
<CardGiftcardRounded className="text-pink-100" fontSize="small" />
|
||||
</span>
|
||||
<span className="hover:bg-slate-500 p-1 rounded-full cursor-pointer flex justify-center items-center">
|
||||
<Add className="text-slate-100" fontSize="small" />
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* pinned conversations */}
|
||||
<div className="m-5 bg-slate-500 shadow-lg rounded">
|
||||
<span className="flex flex-row justify-start p-4 items-center">
|
||||
<PushPinRounded className="text-slate-100" />
|
||||
<span className="tracking-wider text-slate-100 uppercase text-sm font-semibold">
|
||||
Pinned
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import Logo, { LogoType } from "../../../components/Logo";
|
||||
|
||||
import { $searchQuery } from "../../../controller/recoil";
|
||||
import { useGetUserDetails } from "../../../controller/index";
|
||||
import { useRecoilState } from "recoil";
|
||||
|
||||
export default function Header() {
|
||||
const { data: user } = useGetUserDetails();
|
||||
const [searchQuery, setSearchQuery] = useRecoilState($searchQuery);
|
||||
|
||||
return (
|
||||
<div className="flex flex-row items-center bg-slate-800 h-20">
|
||||
<Logo type={LogoType.small} className="scale-[0.4]" />
|
||||
<input
|
||||
placeholder="type / to search"
|
||||
className="placeholder:text-slate-400 bg-transparent outline-none text-slate-100"
|
||||
value={searchQuery}
|
||||
onChange={(e) => setSearchQuery(e.target.value)}
|
||||
/>
|
||||
|
||||
<button className="ml-auto hover:scale-110 bg-slate-600 text-teal-500 py-1 px-2 rounded-lg text-sm">
|
||||
flow state
|
||||
</button>
|
||||
|
||||
<span className="relative mx-5">
|
||||
<img
|
||||
src={user.picture}
|
||||
className="rounded-lg h-8 hover:bg-slate-200 hover:cursor-pointer hover:scale-110"
|
||||
alt="cannot find"
|
||||
/>
|
||||
<span className="absolute bottom-0 -right-1.5 rounded-full bg-emerald-600 h-3 w-3"></span>
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,69 +1,23 @@
|
||||
import {
|
||||
Add,
|
||||
CardGiftcardRounded,
|
||||
ContactsRounded,
|
||||
LinkRounded,
|
||||
PushPinRounded,
|
||||
} from "@mui/icons-material";
|
||||
import Logo, { LogoType } from "../../components/Logo";
|
||||
|
||||
import { $searchQuery } from "../../controller/recoil";
|
||||
import Conversations from "./conversations";
|
||||
import Header from "./header";
|
||||
import Search from "./search";
|
||||
import { useEffect } from "react";
|
||||
import { useGetUserDetails } from "../../controller/index";
|
||||
import { useGetUserDetails } from "../../controller/";
|
||||
import { useRecoilValue } from "recoil";
|
||||
|
||||
export default function Home() {
|
||||
const { data: user } = useGetUserDetails();
|
||||
const searchQuery = useRecoilValue($searchQuery);
|
||||
|
||||
return (
|
||||
<div className="h-screen w-screen bg-slate-700">
|
||||
{/* header */}
|
||||
<div className="flex flex-row items-center bg-slate-800 h-20">
|
||||
<Logo type={LogoType.small} className="scale-[0.4]" />
|
||||
<input
|
||||
placeholder="type / to search"
|
||||
className="placeholder:text-slate-400 bg-transparent outline-none text-slate-100"
|
||||
/>
|
||||
<Header />
|
||||
|
||||
<button className="ml-auto hover:scale-110 bg-slate-600 text-teal-500 py-1 px-2 rounded-lg text-sm">
|
||||
flow state
|
||||
</button>
|
||||
|
||||
<span className="relative mx-5">
|
||||
<img
|
||||
src={user.picture}
|
||||
className="rounded-lg h-8 hover:bg-slate-200 hover:cursor-pointer hover:scale-110"
|
||||
alt="cannot find"
|
||||
/>
|
||||
<span className="absolute bottom-0 -right-1.5 rounded-full bg-emerald-600 h-3 w-3"></span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* actions navbar */}
|
||||
<div className="flex justify-end mx-10 mt-5 space-x-3">
|
||||
<span className="hover:bg-slate-500 p-1 rounded-full cursor-pointer flex justify-center items-center">
|
||||
<ContactsRounded className="text-slate-100" fontSize="small" />
|
||||
</span>
|
||||
|
||||
<span className="hover:bg-slate-500 p-1 rounded-full cursor-pointer flex justify-center items-center">
|
||||
<LinkRounded className="text-slate-100" fontSize="small" />
|
||||
</span>
|
||||
|
||||
<span className="hover:bg-slate-500 p-1 rounded-full cursor-pointer flex justify-center items-center">
|
||||
<CardGiftcardRounded className="text-pink-100" fontSize="small" />
|
||||
</span>
|
||||
<span className="hover:bg-slate-500 p-1 rounded-full cursor-pointer flex justify-center items-center">
|
||||
<Add className="text-slate-100" fontSize="small" />
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* pinned conversations */}
|
||||
<div className="m-5 bg-slate-500 shadow-lg rounded">
|
||||
<span className="flex flex-row justify-start p-4 items-center">
|
||||
<PushPinRounded className="text-slate-100" />
|
||||
<span className="tracking-wider text-slate-100 uppercase text-sm font-semibold">
|
||||
Pinned
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
{searchQuery ? <Search /> : <Conversations />}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import { $searchQuery } from "../../../controller/recoil";
|
||||
import { useEffect } from "react";
|
||||
import { useSearch } from "../../../controller";
|
||||
|
||||
export default function Search() {
|
||||
const { data: searchResultsResponse, isLoading, isError } = useSearch();
|
||||
useEffect(() => {}, []);
|
||||
|
||||
if (!searchResultsResponse?.users) {
|
||||
return (
|
||||
<span className="text-white">
|
||||
no results. please try someone's email or name.
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
{searchResultsResponse.users?.map((user) => {
|
||||
return <span>{user.name}</span>;
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import { useSetRecoilState } from "recoil";
|
||||
|
||||
export default function Login({ onReady }: { onReady: Function }) {
|
||||
const setAuthTokens = useSetRecoilState($authTokens);
|
||||
const [isLoading, setIsLoading] = useState<boolean>(false);
|
||||
|
||||
const continueAuth = () => {
|
||||
setIsLoading(true);
|
||||
@@ -26,6 +27,8 @@ export default function Login({ onReady }: { onReady: Function }) {
|
||||
}) => {
|
||||
setAuthTokens(tokens);
|
||||
|
||||
console.log(tokens.idToken);
|
||||
|
||||
onReady();
|
||||
};
|
||||
|
||||
@@ -34,8 +37,6 @@ export default function Login({ onReady }: { onReady: Function }) {
|
||||
window.electronAPI.store
|
||||
.get(STORE_ITEMS.AUTH_TOKENS)
|
||||
.then((tokensFromStore: any) => {
|
||||
console.log(tokensFromStore);
|
||||
|
||||
if (tokensFromStore) {
|
||||
setIsLoading(true);
|
||||
|
||||
@@ -68,8 +69,6 @@ export default function Login({ onReady }: { onReady: Function }) {
|
||||
// };
|
||||
}, []);
|
||||
|
||||
const [isLoading, setIsLoading] = useState<boolean>(false);
|
||||
|
||||
return (
|
||||
<div className="container flex flex-col space-y-5 justify-center items-center h-screen bg-slate-900">
|
||||
<Logo className="scale-50" />
|
||||
|
||||
Reference in New Issue
Block a user