Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates #41

Merged
merged 2 commits into from
Jan 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading