Skip to content

Commit

Permalink
Merge pull request #41 from khaykingleb/move-to-react-router-v7
Browse files Browse the repository at this point in the history
Updates
  • Loading branch information
khaykingleb authored Jan 4, 2025
2 parents 5e89eef + babd1bd commit 707b50a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
1 change: 0 additions & 1 deletion app/components/organisms/Carousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export const Carousel = ({ posts }: { posts: Tables<"posts">[] }) => {
{post.title}
</h2>
<p className="font-gill-sans mb-1 text-sm">
Published on{" "}
{new Date(post.created_at).toLocaleDateString("en-US", {
year: "numeric",
month: "long",
Expand Down
8 changes: 4 additions & 4 deletions app/routes/blog.$slug.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ export const clientLoader: ClientLoaderFunction = async ({
params,
serverLoader,
}: ClientLoaderFunctionArgs) => {
const cachedData = sessionStorage.getItem(`blogPosts-${params.slug}`);
const cachedTimestamp = sessionStorage.getItem(
const cachedData = localStorage.getItem(`blogPosts-${params.slug}`);
const cachedTimestamp = localStorage.getItem(
`blogPostsTimestamp-${params.slug}`,
);

Expand All @@ -159,14 +159,14 @@ export const clientLoader: ClientLoaderFunction = async ({

// Cache the data
Promise.resolve(serverData.recordMap).then((recordMap) => {
sessionStorage.setItem(
localStorage.setItem(
`blogPosts-${params.slug}`,
JSON.stringify({
post: serverData.post,
recordMap,
}),
);
sessionStorage.setItem(
localStorage.setItem(
`blogPostsTimestamp-${params.slug}`,
Date.now().toString(),
);
Expand Down
8 changes: 4 additions & 4 deletions app/routes/blog._index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ const CACHE_DURATION = 60 * 60 * 1000; // 1 hour in milliseconds
export const clientLoader = async ({
serverLoader,
}: ClientLoaderFunctionArgs) => {
const cachedData = sessionStorage.getItem("blogPosts");
const cachedTimestamp = sessionStorage.getItem("blogPostsTimestamp");
const cachedData = localStorage.getItem("blogPosts");
const cachedTimestamp = localStorage.getItem("blogPostsTimestamp");

// Use cached data if it's valid
if (cachedData && cachedTimestamp) {
Expand All @@ -100,8 +100,8 @@ export const clientLoader = async ({
posts: Promise<Tables<"posts">[]>;
};
serverData.posts.then((posts) => {
sessionStorage.setItem("blogPosts", JSON.stringify({ posts }));
sessionStorage.setItem("blogPostsTimestamp", Date.now().toString());
localStorage.setItem("blogPosts", JSON.stringify({ posts }));
localStorage.setItem("blogPostsTimestamp", Date.now().toString());
});

return serverData;
Expand Down

0 comments on commit 707b50a

Please sign in to comment.