forked from MarsX-dev/devhunt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
mac
authored and
mac
committed
Sep 13, 2023
1 parent
de79972
commit 27a0bd0
Showing
5 changed files
with
85 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
'use client'; | ||
|
||
import ModalBannerCode from '@/components/ui/ModalBannerCode'; | ||
import { useState } from 'react'; | ||
|
||
export default () => { | ||
const [isModalOpen, setModalOpen] = useState(false); | ||
const [toolSlug, setToolSlug] = useState(''); | ||
|
||
const copyDone = () => { | ||
localStorage.removeItem('last-tool'); | ||
setModalOpen(false); | ||
}; | ||
|
||
return ( | ||
<ModalBannerCode | ||
isModalOpen={isModalOpen} | ||
toolSlug={toolSlug} | ||
setModalOpen={setModalOpen} | ||
setToolSlug={setToolSlug} | ||
copyDone={copyDone} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
'use client'; | ||
|
||
import CodeBlock from '@/components/CodeBlock'; | ||
import Button from '@/components/ui/Button/Button'; | ||
import Modal from '@/components/ui/Modal'; | ||
import { useEffect, useState } from 'react'; | ||
|
||
export default ({ | ||
toolSlug = '', | ||
isModalOpen, | ||
setModalOpen, | ||
setToolSlug, | ||
copyDone, | ||
}: { | ||
toolSlug: string; | ||
isModalOpen: boolean; | ||
setModalOpen: (val: boolean) => void; | ||
setToolSlug: (val: string) => void; | ||
copyDone: () => void; | ||
}) => { | ||
useEffect(() => { | ||
let getToolFromLocalStorage = localStorage.getItem('last-tool'); | ||
|
||
if (getToolFromLocalStorage) { | ||
const parsedTool = JSON.parse(getToolFromLocalStorage) as { toolSlug: string; launchEnd: string; launchDate: string }; | ||
if (new Date(parsedTool.launchEnd).getTime() >= Date.now()) { | ||
setToolSlug(parsedTool.toolSlug); | ||
setModalOpen(true); | ||
} | ||
} | ||
}, []); | ||
|
||
return ( | ||
<Modal variant="custom" isActive={isModalOpen}> | ||
<h3 className="text-slate-50 font-medium">Add banner</h3> | ||
<p className="text-slate-300 text-sm mt-2"> | ||
Add this code between <b>{'<head>'}</b> tags in your website to show a banner about your launch. | ||
</p> | ||
<div className="mt-6"> | ||
<CodeBlock onCopy={copyDone}> | ||
{`<script defer data-url="https://devhunt.org/tool/${toolSlug}" src="https://cdn.jsdelivr.net/gh/sidiDev/devhunt-banner/index.js" />`} | ||
</CodeBlock> | ||
</div> | ||
<Button className="mt-3 ring-offset-2 ring-orange-500 focus:ring-2" onClick={copyDone}> | ||
I've done this | ||
</Button> | ||
</Modal> | ||
); | ||
}; | ||
|
||
// {"toolSlug":"fdsfdsg","launchDate":"2023-10-10","launchEnd":"2023-10-16T23:59:59+00:00"} |