Skip to content

Commit

Permalink
chore: setup like button
Browse files Browse the repository at this point in the history
  • Loading branch information
itsjoeoui committed Mar 22, 2024
1 parent 9c57647 commit d0647cd
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
12 changes: 10 additions & 2 deletions db/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { defineDb } from 'astro:db';
import { defineDb, defineTable, column } from "astro:db";

const Like = defineTable({
columns: {
date: column.date(),
fingerprint: column.text(),
page: column.text(),
},
});

// https://astro.build/db/config
export default defineDb({
tables: {}
tables: { Like },
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@astrojs/react": "^3.1.0",
"@astrojs/sitemap": "^3.1.1",
"@astrojs/tailwind": "^5.1.0",
"@fingerprintjs/fingerprintjs": "^4.2.2",
"@radix-ui/react-slot": "^1.0.2",
"@types/react": "^18.2.67",
"@types/react-dom": "^18.2.22",
Expand Down
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions src/components/like-button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { useEffect, useState } from "react";
import FingerprintJS from "@fingerprintjs/fingerprintjs";

type Props = {
page: string;
};

const LikeButton = ({ page }: Props) => {
const [fpHash, setFpHash] = useState("");

// create and set the fingerprint as soon as
// the component mounts
useEffect(() => {
const setFp = async () => {
const fp = await FingerprintJS.load();

const { visitorId } = await fp.get();

setFpHash(visitorId);
};

setFp();
}, []);

return <div>LikeButton</div>;
};

export default LikeButton;

0 comments on commit d0647cd

Please sign in to comment.