Skip to content

Commit

Permalink
Add unread notification widget (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
YodaLightsabr authored Jan 30, 2025
1 parent bfc6908 commit 065534e
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 4 deletions.
2 changes: 0 additions & 2 deletions components/Post.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ const PostContext = createContext()
export function Author({ id, overrideText, sx, small }) {
const author = authors[id]

console.log({ author })

const width = small ? '24px' : '32px';
const height = width;

Expand Down
4 changes: 2 additions & 2 deletions pages/_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import theme from '@hackclub/theme'
import { ThemeProvider } from 'theme-ui'
import '../styles/global.css'
import Head from 'next/head'
import { QueryParamProvider } from 'use-query-params'
import { QueryParamProvider } from 'use-query-params';
import NextAdapterApp from 'next-query-params/app';

export default class App extends NextApp {
Expand All @@ -20,7 +20,7 @@ export default class App extends NextApp {
<link rel="shortcut icon" href="/favicon.png" />
<link rel="favicon" href="/favicon.png" />
<script defer data-domain="bank.engineering" src="https://plausible.io/js/script.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
</Head>
<Component {...pageProps} />
</ThemeProvider>
Expand Down
8 changes: 8 additions & 0 deletions pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ function PostPreview({ post }) {
export default function Home() {
const [tag, setTag] = useQueryParam('tag', StringParam);

useEffect(() => {
if (!localStorage.getItem("initialVisit")) {
localStorage.setItem("initialVisit", Date.now());
}

localStorage.setItem("lastPostVisit", posts.toReversed()[0].meta.slug);
}, []);

return (
<>
<Header />
Expand Down
7 changes: 7 additions & 0 deletions pages/posts/[slug].js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Author, PostTags } from '@/components/Post'
import { posts } from '@/content/index'
import { DisplayProvider } from '@/lib/display'
import Head from 'next/head'
import { useEffect } from 'react'
import { Box, Card, Container, Flex, Grid, Heading, Link, Text } from 'theme-ui'

const relatedPosts = post => {
Expand Down Expand Up @@ -41,6 +42,12 @@ export default function Post({ slug }) {
timeZone: "Etc/UTC"
});

useEffect(() => {
if (!localStorage.getItem("initialVisit")) {
localStorage.setItem("initialVisit", Date.now());
}
}, []);

return (
<DisplayProvider display="detail">
<Head>
Expand Down
27 changes: 27 additions & 0 deletions pages/widget.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Badge } from 'theme-ui';
import { posts } from '../content'
import { useEffect, useState } from "react";

export default function Widget() {
const [number, setNumber] = useState(0);

useEffect(() => {
if (!localStorage.getItem("initialVisit")) {
localStorage.setItem("initialVisit", Date.now());
}

const index = posts.map(post => post.meta.slug).toReversed().indexOf(localStorage.getItem("lastPostVisit"));
setNumber(index);
}, []);

return (
<a href="https://bank.engineering" target="_blank">
{number >= 1 ? (
<Badge variant="pill">{number}</Badge>
) : (
<Badge variant="pill" bg="muted"></Badge>
// zero width space ^
)}
</a>
)
}

0 comments on commit 065534e

Please sign in to comment.