Skip to content

Commit

Permalink
Merge pull request #46 from samcyn/feat/site
Browse files Browse the repository at this point in the history
chore(site): add copy to clip functionality
  • Loading branch information
samcyn authored Apr 19, 2024
2 parents f251c41 + e03d7bd commit 3b19ff2
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/site/gatsby-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require('dotenv').config({
const config: GatsbyConfig = {
siteMetadata: {
title: `site`,
siteUrl: `https://www.samsoniyanda.com`,
siteUrl: `https://gatsby-source-hubspot-node-plugin.netlify.app/`,
},
graphqlTypegen: true,
plugins: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type Props = {
const AppCardWithContact = ({ properties: { firstname, lastname, email, hs_object_id } }: Props) => {
return (
<AppCard className="bg-primary dark:bg-gray-80">
<Link to="/" className="block w-full no-underline">
<Link to="#" className="block w-full no-underline">
<div className="relative overflow-hidden">
<div className="relative p-4 md:p-6 z-1">
<small className="text-white opacity-40">#{hs_object_id}</small>
Expand Down
2 changes: 1 addition & 1 deletion packages/site/src/components/AppCard/AppCardWithPhoto.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type Props = {

const AppCardWithPhoto = ({ author_name, title, featured_image, blog_author }: Props) => (
<AppCard className="bg-white dark:bg-gray-80 shadow-md hover:shadow-lg transition overflow-hidden rounded-lg group">
<Link to="/" className="block w-full no-underline">
<Link to="#" className="block w-full no-underline">
<figure className="w-full h-[165px] overflow-hidden">
<AppImage
className="w-full h-full transition-transform group-hover:scale-105"
Expand Down
37 changes: 35 additions & 2 deletions packages/site/src/components/AppShortCodes/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { ReactElement } from 'react';
import React, { ReactElement, useEffect, useRef, useState } from 'react';
import { Link } from 'gatsby';

function splitLanguageAndTitle(children: React.ReactNode) {
Expand Down Expand Up @@ -146,7 +146,37 @@ const MyPre = ({
children,
...rest
}: React.DetailedHTMLProps<React.HTMLAttributes<HTMLPreElement>, HTMLPreElement>) => {
const timeoutRef = useRef<NodeJS.Timeout>();
const [isCopied, setIsCopied] = useState(false);
const preRef = useRef<HTMLPreElement | null>(null);
const { language, title } = splitLanguageAndTitle(children);

useEffect(() => {
// prevent memory leakage
return () => {
if (timeoutRef.current) {
clearTimeout(timeoutRef.current);
}
};
}, []);

const handleCopy = async () => {
const preElem = preRef.current;
if (window && preElem) {
const code = preElem.getElementsByTagName('code')[0];
try {
await navigator.clipboard.writeText(code.innerText);
setIsCopied(true);
} catch (err) {
console.error('Failed to copy:', err);
setIsCopied(false);
}

timeoutRef.current = setTimeout(() => {
setIsCopied(false);
}, 2000);
}
};
return (
<>
{title && (
Expand All @@ -166,6 +196,7 @@ const MyPre = ({
text-[13.5px] leading-5 rounded overflow-auto
break-normal ${className || ''}
`}
ref={preRef}
>
<button
name="copy code to clipboard"
Expand All @@ -175,8 +206,10 @@ const MyPre = ({
text-xs leading-3 transition-colors
absolute top-1 right-1 rounded
hover:bg-primary hover:text-white"
disabled={isCopied}
onClick={handleCopy}
>
Copy
{isCopied ? 'Copied' : 'Copy'}
<span aria-roledescription="status" className="sr-only">
copy code to clipboard
</span>
Expand Down
2 changes: 1 addition & 1 deletion packages/site/src/docs/development.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ See the available commands:
gatsby --help
```

![Check Gatsby commands in terminal](../images/docs/config.png)
![Check Gatsby commands in terminal](../images/config.png)

<Announcement>

Expand Down
File renamed without changes
4 changes: 3 additions & 1 deletion packages/site/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ export const query = graphql`

export const Head: HeadFC<Queries.IndexPageQuery> = ({ data }) => (
<>
<title>{data.mdx.frontmatter.title}</title>
<title>
{data.mdx.frontmatter.title} {data.mdx.frontmatter.tail}
</title>
<meta name="author" content="Samson Iyanda"></meta>
<meta name="description" content="site for gatsby source hubspot plugin documentation"></meta>
<meta name="keywords" content="gatsby, gatsby plugin, reactjs, hubspot"></meta>
Expand Down

0 comments on commit 3b19ff2

Please sign in to comment.