diff --git a/.eslintrc b/.eslintrc.json similarity index 100% rename from .eslintrc rename to .eslintrc.json diff --git a/src/assets/img/welcome/extension-pinned.png b/src/assets/img/welcome/extension-pinned.png new file mode 100644 index 0000000..c9841a9 Binary files /dev/null and b/src/assets/img/welcome/extension-pinned.png differ diff --git a/src/assets/img/welcome/opened-extension.png b/src/assets/img/welcome/opened-extension.png new file mode 100644 index 0000000..a4991e7 Binary files /dev/null and b/src/assets/img/welcome/opened-extension.png differ diff --git a/src/components/ui/Button/index.tsx b/src/components/ui/Button/index.tsx new file mode 100644 index 0000000..3642ff4 --- /dev/null +++ b/src/components/ui/Button/index.tsx @@ -0,0 +1,94 @@ +import React from "react"; +import styled from "styled-components"; + +import { HTMLComponent } from "../../../types/html-component"; + +type Props = { + href?: string; + loading?: boolean; + disabled?: boolean; + prefixIcon?: React.ReactNode; + color?: "primary" | "secondary"; + variant?: "default" | "ghost"; + size?: "default" | "small" | "large"; + onClick?: (e: React.MouseEvent) => void; +}; + +type ButtonProps = HTMLComponent< + Props, + React.ButtonHTMLAttributes +>; + +const Button: React.FC = styled( + ({ + as: Component = "button", + href, + loading, + disabled = loading, + prefixIcon, + color = "primary", + variant = "default", + size = "default", + onClick, + className = "", + children, + ...rest + }: ButtonProps) => { + href; + color; + variant; + size; + /* if (href && !disabled) { + return ( + <_LinkAsButton className={className} href={href}> + {children} + + ); +} */ + + const handleClick = (e: React.MouseEvent) => { + e.preventDefault(); + onClick && onClick(e); + }; + + return ( + + +
+ {prefixIcon && prefixIcon} + {children} +
+
+
+ ); + }, +)` + cursor: pointer; + + font-family: "neulis-cursive"; + font-weight: 600; + color: #ffffff; + background-color: var(--green); + + padding: 15px 20px; + border: none; + border-radius: 5px; +`; + +const ButtonContent = styled.div` + display: flex; + flex-direction: row; + align-items: center; + justify-content: center; + + line-height: 20px; +`; + +export default Button; diff --git a/src/components/ui/GlobalStyle/custom.ts b/src/components/ui/GlobalStyle/custom.ts index 4d609cd..960ba83 100644 --- a/src/components/ui/GlobalStyle/custom.ts +++ b/src/components/ui/GlobalStyle/custom.ts @@ -18,7 +18,6 @@ const customCss = css` } html { - width: 380px; height: auto; } @@ -59,6 +58,16 @@ const customCss = css` filter: brightness(0.8); } } + + h1, + h2, + h3, + h4, + h5, + h6 { + font-family: "neulis-cursive", sans-serif; + font-weight: 700; + } `; export default customCss; diff --git a/src/pages/Background/index.ts b/src/pages/Background/index.ts index 1928be6..12fe5b3 100644 --- a/src/pages/Background/index.ts +++ b/src/pages/Background/index.ts @@ -1,7 +1,10 @@ import analyzes from "./analyzes"; +import installNotice from "./installed"; import tabtimes from "./tabtimes"; const main = async () => { + chrome.runtime.onInstalled.addListener(installNotice); + console.log("kartrak - background script started"); tabtimes(); analyzes(); diff --git a/src/pages/Background/installed.ts b/src/pages/Background/installed.ts new file mode 100644 index 0000000..c0939d8 --- /dev/null +++ b/src/pages/Background/installed.ts @@ -0,0 +1,9 @@ +const installNotice = () => { + console.log("kartrak - extension installed"); + + chrome.tabs.create({ + url: chrome.runtime.getURL("welcome.html"), + }); +}; + +export default installNotice; diff --git a/src/pages/Popup/index.css b/src/pages/Popup/index.css new file mode 100644 index 0000000..f4e8760 --- /dev/null +++ b/src/pages/Popup/index.css @@ -0,0 +1,3 @@ +html { + width: 380px; +} \ No newline at end of file diff --git a/src/pages/Popup/index.tsx b/src/pages/Popup/index.tsx index a8af875..0b89c05 100644 --- a/src/pages/Popup/index.tsx +++ b/src/pages/Popup/index.tsx @@ -2,6 +2,7 @@ import React from "react"; import { createRoot } from "react-dom/client"; import Popup from "./Popup"; +import "./index.css"; import "./../../styles/fonts.css"; const container = document.getElementById("app-container"); diff --git a/src/pages/Welcome/Welcome.tsx b/src/pages/Welcome/Welcome.tsx new file mode 100644 index 0000000..7e2c1db --- /dev/null +++ b/src/pages/Welcome/Welcome.tsx @@ -0,0 +1,155 @@ +import React from "react"; +import styled from "styled-components"; + +import Button from "../../components/ui/Button"; +import GlobalStyle from "../../components/ui/GlobalStyle"; + +const WelcomePage: React.FC = () => { + const [isPinned, setIsPinned] = React.useState(false); + const [error, setError] = React.useState(null); + + const handleCheckIfPinned = React.useCallback((shouldError = true) => { + console.log("kartrak - check if pinned"); + + const checkIfPinned = async (): Promise => { + const userSettings = await chrome.action.getUserSettings(); + + console.log("kartrak - userSettings", userSettings); + + return userSettings.isOnToolbar; + }; + + checkIfPinned().then((isPinned) => { + if (isPinned) { + chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => { + const activeTab = tabs[0]; + + if (activeTab) { + setIsPinned(true); + } + }); + } else if (shouldError) { + setError("L'extension n'est pas épinglée à la barre d'outils."); + } + }); + }, []); + + const handleCloseTab = React.useCallback(() => { + console.log("kartrak - close tab"); + + chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => { + const activeTab = tabs[0]; + + if (activeTab) { + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + chrome.tabs.remove(activeTab.id!); + } + }); + }, []); + + React.useEffect(() => { + handleCheckIfPinned(false); + }, []); + + console.log("kartrak - isPinned", isPinned); + + return ( + + + + + {isPinned ? ( + <> + {"Vous êtes prêt à y aller !"} + + + { + "Vous pouvez désormais cliquer sur l’extension quand vous le souhaitez pour analyser des sites internets ou voir vos statistiques d’activités." + } + + + {"Extension + + + {"J’ai compris, merci"} + + + ) : ( + <> + + {"Kartrak est désormais installé sur votre navigateur"} + + + + { + "Épinglez dès maintenant l’extension à la barre d’outils de votre navigateur. Vous serez amenés à ouvrir souvent l’extension, alors ça sera plus pratique !" + } + + + {"Extension + + handleCheckIfPinned()}> + {"J'ai épinglé l'extension"} + + + {error && {error}} + + )} + + + ); +}; + +const Container = styled.main` + display: flex; + align-items: center; + justify-content: center; + height: 100vh; +`; + +const Row = styled.div` + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + max-width: 750px; +`; + +const Title = styled.h1` + font-family: "neulis-cursive"; + font-size: 48px; + font-weight: 600; + text-align: center; + color: var(--primary); +`; + +const TextContent = styled.p` + margin-top: 15px; + text-align: center; + + color: var(--grey); + font-size: 18px; +`; + +const Image = styled.img` + margin-top: 40px; + max-width: 560px; + width: 100%; +`; + +const StyledButton = styled(Button)` + margin-top: 40px; +`; + +const Error = styled.p` + margin-top: 10px; + color: var(--red); +`; + +export default WelcomePage; diff --git a/src/pages/Welcome/index.html b/src/pages/Welcome/index.html new file mode 100644 index 0000000..0dc03c6 --- /dev/null +++ b/src/pages/Welcome/index.html @@ -0,0 +1,12 @@ + + + + + + Merci d'avoir installé Kartrak + + + +
+ + diff --git a/src/pages/Welcome/index.tsx b/src/pages/Welcome/index.tsx new file mode 100644 index 0000000..8caba32 --- /dev/null +++ b/src/pages/Welcome/index.tsx @@ -0,0 +1,11 @@ +import "./../../styles/fonts.css"; + +import React from "react"; +import { createRoot } from "react-dom/client"; + +import WelcomePage from "./Welcome"; + +const container = document.getElementById("app-container"); +// eslint-disable-next-line @typescript-eslint/no-non-null-assertion +const root = createRoot(container!); +root.render(); diff --git a/src/types/html-component.ts b/src/types/html-component.ts new file mode 100644 index 0000000..8ca5102 --- /dev/null +++ b/src/types/html-component.ts @@ -0,0 +1,12 @@ +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export type HTMLComponent> = { + /** + * The root element. + */ + as?: React.ElementType; + /** + * The content, duh. + */ + children?: React.ReactNode; +} & P & + Partial>; diff --git a/webpack.config.js b/webpack.config.js index ffe6515..5025e1f 100755 --- a/webpack.config.js +++ b/webpack.config.js @@ -42,6 +42,7 @@ const options = { mode: process.env.NODE_ENV || "development", entry: { options: path.join(__dirname, "src", "pages", "Options", "index.tsx"), + welcome: path.join(__dirname, "src", "pages", "Welcome", "index.tsx"), popup: path.join(__dirname, "src", "pages", "Popup", "index.tsx"), background: path.join(__dirname, "src", "pages", "Background", "index.ts"), contentScript: path.join(__dirname, "src", "pages", "Content", "index.ts"), @@ -192,6 +193,12 @@ const options = { chunks: ["options"], cache: false, }), + new HtmlWebpackPlugin({ + template: path.join(__dirname, "src", "pages", "Welcome", "index.html"), + filename: "welcome.html", + chunks: ["welcome"], + cache: false, + }), new HtmlWebpackPlugin({ template: path.join(__dirname, "src", "pages", "Popup", "index.html"), filename: "popup.html",