Skip to content
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"webpack-merge": "5.8.0"
},
"devDependencies": {
"@docusaurus/module-type-aliases": "^3.5.2",
"@docusaurus/module-type-aliases": "^3.6.3",
"@jest/globals": "^29.7.0",
"@tsconfig/docusaurus": "^2.0.3",
"@types/jest": "^29.5.14",
Expand Down
43 changes: 43 additions & 0 deletions src/components/feedbackFaces.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import React, { useState } from "react";
import { event } from "@site/src/utils/gtags.client";

export default function FeedbackFaces() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Best component name ever haha

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used to make games. I still do, but I used to too. I don't think I'll ever top getting to implement a function called

ExecuteWarpJump

const [clickedFace, setClickedFace] = useState<string | null>(null);

const faces = [
{ label: "sad", emoji: "😞" },
{ label: "neutral", emoji: "😐" },
{ label: "happy", emoji: "😊" },
];

const handleFeedbackClick = (feedbackType: string) => {
setClickedFace(feedbackType);

const label = `${feedbackType}`;

event({
action: "feedback_click",
category: "feedback",
label: label,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would also probably lowercase here, but just a nit. Do you also want to use the user hash so that you can tell how many unique people are clicking it and reduce the number of multiple clicks?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually want multiple clicks here. Sort of like clapping on Medium vs. upvotes or downvotes.

location: true,
});

setTimeout(() => setClickedFace(null), 300);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you want to let someone click more than one time? Do you just want to have in state its been clicked and disable clicking any further? I'd probably store something in local storage so the same person on the same browser can't click again imo.

};

return (
<div className="flex justify-left items-center gap-1">
{faces.map((face) => (
<button
key={face.label}
onClick={() => handleFeedbackClick(face.label)}
className={`text-4xl cursor-pointer p-2 bg-transparent border-none transition-transform duration-200 focus:outline-none ${clickedFace === face.label ? "scale-110 opacity-70" : "scale-100 opacity-100"
}`}
aria-label={face.label}
>
{face.emoji}
</button>
))}
</div>
);
}
28 changes: 28 additions & 0 deletions src/theme/TOC/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react';
import clsx from 'clsx';
import TOCItems from '@theme/TOCItems';
import type { Props } from '@theme/TOC';

import styles from './styles.module.css';
import FeedbackFaces from '@site/src/components/feedbackFaces';

// Using a custom className
// This prevents TOCInline/TOCCollapsible getting highlighted by mistake
const LINK_CLASS_NAME = 'table-of-contents__link toc-highlight';
const LINK_ACTIVE_CLASS_NAME = 'table-of-contents__link--active';

export default function TOC({ className, ...props }: Props): JSX.Element {
return (
<div className={clsx(styles.tableOfContents, 'thin-scrollbar', className)}>
<div className="p-1">
<h6 className="mb-0 p-1">Rate this page</h6>
<FeedbackFaces />
</div>
<TOCItems
{...props}
linkClassName={LINK_CLASS_NAME}
linkActiveClassName={LINK_ACTIVE_CLASS_NAME}
/>
</div>
);
}
16 changes: 16 additions & 0 deletions src/theme/TOC/styles.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.tableOfContents {
max-height: calc(100vh - (var(--ifm-navbar-height) + 2rem));
overflow-y: auto;
position: sticky;
top: calc(var(--ifm-navbar-height) + 1rem);
}

@media (max-width: 996px) {
.tableOfContents {
display: none;
}

.docItemContainer {
padding: 0 0.3rem;
}
}
17 changes: 13 additions & 4 deletions src/utils/gtags.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const pageview = (url: string, trackingId: string) => {

if (!window.gtag) {
console.warn(
"window.gtag is not defined. This could mean your google anylatics script has not loaded on the page yet."
"window.gtag is not defined. This could mean your google analytics script has not loaded on the page yet."
)
return
}
Expand All @@ -37,25 +37,34 @@ export const event = ({
category,
label,
value,
location
}: {
action?: string;
category?: string;
label?: string;
value?: number | string;
location?: boolean;
}) => {
if (process.env.NODE_ENV !== "production") return

if (!window.gtag) {
console.warn(
"window.gtag is not defined. This could mean your google anylatics script has not loaded on the page yet."
"window.gtag is not defined. This could mean your google analytics script has not loaded on the page yet."
)
return
}
window.gtag("event", action, {

const eventPayload: Record<string, any> = {
event_category: category,
event_label: label,
value: value,
})
};

if (location) {
eventPayload.page_location = window.location.href;
}

window.gtag("event", action, eventPayload);
}

export const reportWebVitalsToGA = (vitals: Metric) => {
Expand Down
12 changes: 9 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@
"jsx": "react",
"baseUrl": ".",
"strictNullChecks": true,
"typeRoots": ["./", "./node_modules/@types"]
"typeRoots": [
"./",
"./node_modules/@types"
]
},
"include": ["src", "docusaurus.config.d.ts"]
}
"include": [
"src",
"docusaurus.config.d.ts"
]
}
Loading
Loading