Closed cemgunay closed 1 year ago
This is great!! Took a look at everything and it's perfect, also checked out the branch to run it on my end and everything seems to be working perfectly.
Here are few thoughts/potential changes I had, not saying we absolutely have to make these changes or anything like that, just some thoughts. Let me know what you think!
/pages/listing/[listingId]
page, we should probably memoize the computed state variables (at lines 56-70) to make sure they're only re-computed when the listing
prop changes and not with every single re-render. Something like this:// Derived state or computations
const { formattedAddress, numBeds, numBedrooms, numBathrooms, formattedRoomInfo, images } = useMemo(() => {
if (!listing) {
return {
formattedAddress: "",
numBeds: 0,
numBedrooms: 0,
numBathrooms: 0,
formattedRoomInfo: "",
images: [],
};
}
const formattedAddress = `${listing.location.address1}, ${listing.location.city}, ${listing.location.stateprovince}`;
const numBeds = listing.basics.bedrooms.map((bedroom) => bedroom.bedType).length;
const numBedrooms = listing.basics.bedrooms.length;
const numBathrooms = listing.basics.bathrooms;
const formattedRoomInfo = `${numBeds} bed${numBeds === 1 ? "" : "s"} • ${numBedrooms} bedroom${numBedrooms === 1 ? "" : "s"} • ${numBathrooms} bathroom${numBathrooms === 1 ? "" : "s"}`;
const images = listing.images.map(({ url }) => url);
return { formattedAddress, numBeds, numBedrooms, numBathrooms, formattedRoomInfo, images };
}, [listing]);
if (!listing) return;
line at the top of the useEffect
on line 79 of the same /pages/listing/[listingId]
page. Just to safeguard against app crashes in the event of something going wrong with the DB or the SSR function. For e.g. before I had defined my NEXT_PUBLIC_API_URL
in the env variables, no listing
prop was coming through and we were getting crashes. Not sure how likely it is that the listing
prop won't come through but idk I still think it's best to plan for like worst case just in case yk/pages/listing/[listingId]
page too) I think we should still keep the original main <Loading/>
component as well as the new ones, just in case there's some delay with the DB or the SSR function. Hopefully unlikely cuz it's SSR, but I think it's better to have a loading screen there just in case the listing
prop takes a few seconds to come through. Here's the original main Loading component so u don't have to go lookin for it if u agree w this idea ahah:// loading component
const Loading = () => {
return (
<div className="flex flex-col items-start justify-start h-screen gap-3">
<Skeleton className="h-60 w-full rounded-none mb-6" />
<Skeleton className="h-8 w-24 mx-4 mb-2" />
<Skeleton className="h-6 w-52 mx-4 mb-8" />
<Skeleton className="h-6 w-80 mx-4" />
<Skeleton className="h-6 w-96 mx-4" />
<Skeleton className="h-6 w-72 mx-4" />
<Skeleton className="h-6 w-80 mx-4" />
<Skeleton className="h-6 w-72 mx-4" />
</div>
);
};
// show loading page until listing is successfully retrieved
if (!listing) {
return <Loading />;
}
Aaand I think that's it in terms of changes
In terms of the merge conflicts, I was looking at them and they're all relatively easy to resolve I think. So I'll hold off on resolving them for now, and then once you've looked at these thoughts and either vetoed them or made the changes I'll handle it then!
Sweeet thanks for catching all that Nathan. Here's what I did let me know what you think:
getServerSideProps
runs at request time on the server and completes before the page is rendered, there's no client-side fetching or waiting period that would even show a loading page. The page rendered on the client will already have all the data that getServerSideProps fetched or an indication of an error. So I took what you said and learned that getServerSideProps
has some error handling that I implemented and tested.
I also just quickly added 404 and 500 pages
Let me know your thoughts and if this makes sense!!
ezzz yes it makes sense! everything looks great, gonna resolve the merge conflicts now
okay sorry that took ages lmfao I ran into some huge issues with the merge conflicts, specifically the tailwind.config.js
file (had some clashes with the shadcn-ui component library) and the package-lock.json
file (merge conflicts in that file are so annoying lol). got everything sorted in the end tho, and ran and tested all the new functionality too to make sure the merge didn't introduce any new errors. just committed and pushed the conflict resolution changes and gonna merge into main now!
You're the goat 🐐
this commit fixes #4
Did the following things in this PR:
SSR
In
pages/listing/[listingId].js
getServerSideProps
function where thelisting
object is fetched using context parameters before the page is renderedlisting
information already displayeduseEffect
is still used to retrieveactiveRequests
andusers
except given thelisting._id
from the pre-loadedlisting
object fromgetServerSideProps
instead of from URL parameteruseEffect
Loading
function into 2;LoadingBids
andLoadingUser
activeRequests
andusers
to display the loading skeletons just where they are neededPusher Context
PusherContext
which creates apusher
connection and stores it in an object in contextApp
withPusherProvider
API Routes
Added
api/requests/create.js
routelistingId
to test pusherchannel
andevent
that client can subscribe toAdded
api/requests/update.js
routelistingId
with higher offer amount to test pusherchannel
andevent
that client can subscribe toPusher Subscribe and Bind
In
pages/listing/[listingId].js
highestRequest
andnumberOfRequests
statesComponents
index.js
Loading
to show the header while listings still loadutils/pusher.js
Pusher
instance connected to our cluster that will be used to "trigger" events from our API routesutils/connectMongo.js
Misc
LocationMarker
for Google Maps APIglobals.css
:root
globals.css
tailwind.config.js