Skip to content

Commit

Permalink
cleanup: commit all changes before now
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayothegod committed May 15, 2024
1 parent e11dcc2 commit 6de0a84
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 62 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@
mkdir src/routes
touch src/routes/root.jsx

command line commands -- localforage match-sorter sort-by
command line commands -- localforage match-sorter sort-by

- ill be using urlQeryParams for changing the type of data to fetch, however i also want to learn how to use tabs, change tabs and use react lazy
- once i finish this shop page ill learn the above
2 changes: 1 addition & 1 deletion fasco/schemaTypes/clothType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const clothType = defineType({
validation: (rule) => rule.required().error(`All clothing item must have an image.`),
}),
defineField({
name: 'other-images',
name: 'otherImages',
type: 'array',
of: [{type: 'image'}],
}),
Expand Down
2 changes: 1 addition & 1 deletion src/components/build/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default function Footer() {
const year = new Date().getFullYear();
return (
<IsAuthPage>
<footer className="pageStyle pb-6 mt-24">
<footer className="pageStyle pb-6">
<div className=" flex flex-col md:flex-row justify-between ">
<h1 className="text-2xl sm:text-3xl md:text-4xl font-serif font-bold tracking-wide">
FASCO
Expand Down
8 changes: 8 additions & 0 deletions src/components/utils/UrlFor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import imageUrlBuilder from '@sanity/image-url';
import client from '../../sanity/client';

const builder = imageUrlBuilder(client);

export function urlFor(source: any) {
return builder.image(source);
}
22 changes: 12 additions & 10 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ import { createBrowserRouter, RouterProvider } from "react-router-dom";
import RootLayout, {
Loader as rootLayoutLoader,
} from "./layouts/RootLayout.tsx";
import Root, { Loader as rootLoader } from "./routes/root.tsx";
import Shop, {
Loader as shopLoader,
} from "./routes/shop.tsx";
import Root, { Loader as rootLoader } from "./routes/root.tsx";
import Shop, { Loader as shopLoader } from "./routes/shop.tsx";
import RegisterRoute, {
Loader as registerLoader,
Action as registerAction,
Expand All @@ -18,7 +16,10 @@ import LoginRoute, {
Loader as loginLoader,
Action as loginAction,
} from "./routes/login.tsx";
import LearnAppwrite, {Loader as LearnLoader} from "./routes/learn-appwrite.tsx";
import LearnAppwrite, {
Loader as LearnLoader,
} from "./routes/learn-appwrite.tsx";
import { Query } from "./routes/query.tsx";

const router = createBrowserRouter([
{
Expand All @@ -31,10 +32,14 @@ const router = createBrowserRouter([
errorElement: <ErrorPage />,
loader: rootLoader,
},
{
path: "/query",
element: <Query />,
},
{
path: "/shop",
element: <Shop />,
loader: shopLoader
loader: shopLoader,
},
{
path: "/register",
Expand All @@ -61,12 +66,9 @@ const router = createBrowserRouter([
ReactDOM.createRoot(document.getElementById("root")!).render(
// <React.StrictMode>
// </React.StrictMode>
<RouterProvider router={router} />
<RouterProvider router={router} />
);




// import React from "react";
// import ReactDOM from "react-dom/client";
// import "./index.css";
Expand Down
34 changes: 16 additions & 18 deletions src/routes/learn-appwrite.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
import { LoaderFunctionArgs, json } from "react-router-dom";
import client from "../sanity/client";
import { LoaderFunctionArgs, json, useSearchParams } from "react-router-dom";
import * as React from "react";

export async function Loader({ request }: LoaderFunctionArgs) {
// const data = await client.fetch(`*[_type == "event"]`)
// {
// title,
// slug,
// body,
// publishedAt,
// mainImage {
// asset -> {
// _id,
// url
// },
// alt,
// }
// } | order(publishedAt desc)
// console.log(data);
return json({ user: "user" });
}

export default function LearnAppwrite() {
// const data = useLoaderData();
const [input, setInput] = React.useState("")
let [searchParams, setSearchParams] = useSearchParams();

console.log(searchParams);

function handleSubmit(event: any) {
event.preventDefault();
console.log(input);
}

return (
<main className="min-h-[50vh]">
<main className="min-h-[50vh] px-8">
<p>Bro this is learn appwrite</p>
<form onSubmit={handleSubmit}>
<input className="mt-2 border border-red-600 rounded-md" type="text" onChange={(e) => setInput(e.target.value)} />
</form>
</main>
);
}
32 changes: 32 additions & 0 deletions src/routes/query.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { ChangeEvent } from "react";
import { useSearchParams } from "react-router-dom";

// Temporary key of my query parameter
const MY_QUERY_PARAMETER: string = "myQueryParameter";

export const Query = (props: any) => {
// Hook which returns a tuple. First element is the current URLSearchParams object and second element is the function to take in the new URLSearchParams object alongside a configuration object to either replace the query parameters or not alongside state.
const [currentQueryParameters, setSearchParams] = useSearchParams();
const newQueryParameters: URLSearchParams = new URLSearchParams();

console.log(currentQueryParameters.get(MY_QUERY_PARAMETER));

const onInputValueChangeEventHandler: (
event: ChangeEvent<HTMLInputElement>
) => void = ({ target: { value } }: ChangeEvent<HTMLInputElement>): void => {
if (value) newQueryParameters.set(MY_QUERY_PARAMETER, value);

setSearchParams(newQueryParameters);
};

return (
<div className="max-w-[800px] mx-auto px-8">

<input
className="mt-2 border"
type="text"
onChange={onInputValueChangeEventHandler}
/>
</div>
);
};
87 changes: 56 additions & 31 deletions src/routes/shop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import Filters from "../components/build/Filters";
// import Newsletter from "../components/build/Newsletter";
// import slider from "../fascoAsset/slider.png";
import Crucible from "../components/utils/Crucible";
import client from "../sanity/client";
// import client from "../sanity/client";
import { getAllCloths } from "../services/sanityActions";
import { Hammer, Menu } from "lucide-react";
import { urlFor } from "../components/utils/UrlFor";

export async function Loader() {
try {
const data = await client.fetch(`*[_type == "event"]`);
// console.log( data);
return json({ data: "data" });
const cloth = await getAllCloths();
// console.log(cloth);
return json(cloth);
} catch (error) {
return json({ error: "An error occured!" });
}
Expand All @@ -20,35 +23,57 @@ export default function Shop() {
const loaderData: any = useLoaderData();
console.log(loaderData);
return (
<main>
<section className="pageStyle ">
<h2 className="text-2xl sm:text-3xl md:text-2xl font-serif font-bold tracking-wide text-center">
Fashion
</h2>
<Crucible backLink="/" backTitle="Home" presentTitle="Fashion" />
</section>

<section className="pageStyle mt-8 flex">
{/* filter */}
<aside className="hidden md:block w-[25%] lg:w-[20%]">
<h3 className="text-xl font-serif font-bold tracking-wide">
Filters
</h3>
<Filters/>
</aside>

{/* products */}
</section>

{/* <section className="hidden md:block mt-16 mb-16">
<main className="min-h-[60vh]">

<section className="pageStyle ">
<h2 className="text-2xl sm:text-3xl md:text-2xl font-serif font-bold tracking-wide text-center">
Fashion
</h2>
<Crucible backLink="/" backTitle="Home" presentTitle="Fashion" />
</section>

<section className="pageStyle mt-8 flex divide-x-4">
{/* filter */}
<aside className="hidden md:block w-[25%] lg:w-[20%] px-2">
<h3 className="text-xl font-serif font-bold tracking-wide">
Filters
</h3>
<Filters />
</aside>

{/* products */}
<main className="px-2 w-full">
{/* top */}
<div className="flex items-center justify-between">
<p>Dropdown</p>
<div>
<Menu className="border h-8 w-8 p-1 rounded-md"/>
</div>
</div>

<div>
{
loaderData?.allCloths?.map((cloth: any) => (
<div key={cloth._id}>
<h3>{cloth.name}</h3>
<h3>#{cloth.price}</h3>
<img src={urlFor(cloth.image).width(300).url()} alt={cloth.slug || 'Image-alt'} />
</div>
))
}
</div>
</main>
</section>

{/* <section className="hidden md:block mt-16 mb-16">
<img src={slider} alt="top-banner-image" className="" />
</section> */}

{/* Follow us on instagram */}
{/* <FollowUs /> */}
{/* Follow us on instagram */}
{/* <FollowUs /> */}

{/* Newsletter */}
{/* <Newsletter /> */}
</main>
)
{/* Newsletter */}
{/* <Newsletter /> */}
</main>
);
}
21 changes: 21 additions & 0 deletions src/services/dbAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,24 @@ export const fetchData = {
}
},
};

// async function add(idea) {
// const response = await databases.createDocument(
// IDEAS_DATABASE_ID,
// IDEAS_COLLECTION_ID,
// ID.unique(),
// idea
// );
// }

// async function remove(id) {
// await databases.deleteDocument(IDEAS_DATABASE_ID, IDEAS_COLLECTION_ID, id);
// }

// async function init() {
// const response = await databases.listDocuments(
// IDEAS_DATABASE_ID,
// IDEAS_COLLECTION_ID,
// [Query.orderDesc("$createdAt"), Query.limit(10)]
// );
// }
22 changes: 22 additions & 0 deletions src/services/sanityActions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import client from "../sanity/client";
// update denim jackets tag from best-seller to best selling

export async function getAllCloths() {
try {
const query = `{
"allCloths": *[_type == "cloth" && "all-products" in tags]{name, _id, slug, price, image,tags, colors, sizes},
"bestSelling": *[_type == "cloth" && "best-selling" in tags]{name, _id, slug, price, image,tags, colors, sizes},
"newArrival": *[_type == "cloth" && "new-arrivals" in tags]{name, _id, slug, price, image,tags, colors, sizes},
}`
const cloth = await client.fetch(query);

return cloth;
} catch (error) {
console.log(error);
return error;
}
}

export const fetched = {
async fetch() {},
};

0 comments on commit 6de0a84

Please sign in to comment.