Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Welcome page #52

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 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
jerembdn marked this conversation as resolved.
Show resolved Hide resolved
File renamed without changes.
Binary file added src/assets/img/welcome/extension-pinned.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/img/welcome/opened-extension.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
94 changes: 94 additions & 0 deletions src/components/ui/Button/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import React from "react";
Copy link
Member

Choose a reason for hiding this comment

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

in this file you just dont respect the sizes indicated on the figma

Copy link
Member Author

Choose a reason for hiding this comment

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

ahbon

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<HTMLButtonElement>) => void;
};

type ButtonProps = HTMLComponent<
Props,
React.ButtonHTMLAttributes<HTMLButtonElement>
>;

const Button: React.FC<ButtonProps> = styled(
({
as: Component = "button",
href,
loading,
disabled = loading,
prefixIcon,
color = "primary",
variant = "default",
size = "default",
onClick,
className = "",
children,
...rest
}: ButtonProps) => {
href;

Check warning on line 37 in src/components/ui/Button/index.tsx

View workflow job for this annotation

GitHub Actions / Build, lint, and test

Expected an assignment or function call and instead saw an expression
color;

Check warning on line 38 in src/components/ui/Button/index.tsx

View workflow job for this annotation

GitHub Actions / Build, lint, and test

Expected an assignment or function call and instead saw an expression
variant;

Check warning on line 39 in src/components/ui/Button/index.tsx

View workflow job for this annotation

GitHub Actions / Build, lint, and test

Expected an assignment or function call and instead saw an expression
size;

Check warning on line 40 in src/components/ui/Button/index.tsx

View workflow job for this annotation

GitHub Actions / Build, lint, and test

Expected an assignment or function call and instead saw an expression
/* if (href && !disabled) {
jerembdn marked this conversation as resolved.
Show resolved Hide resolved
return (
<_LinkAsButton className={className} href={href}>
{children}
</_LinkAsButton>
);
} */

const handleClick = (e: React.MouseEvent<HTMLButtonElement>) => {
e.preventDefault();
onClick && onClick(e);
};

return (
<Component
onClick={handleClick}
className={className}
disabled={disabled}
whileTap={{ opacity: 0.8 }}
transition={{ duration: 0.2 }}
{...rest}
>
<ButtonContent>
<div className={"flex flex-row gap-x-[15px] items-center"}>
{prefixIcon && prefixIcon}
{children}
</div>
</ButtonContent>
</Component>
);
},
)<ButtonProps>`
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;
12 changes: 11 additions & 1 deletion src/components/ui/GlobalStyle/custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const customCss = css`
}

html {
width: 380px;
height: auto;
}

Expand Down Expand Up @@ -59,6 +58,17 @@ const customCss = css`
filter: brightness(0.8);
}
}

h1,
h2,
h3,
h4,
h5,
h6 {
font-family: "neulis-cursive", sans-serif;
font-weight: 700;
margin: 0;
jerembdn marked this conversation as resolved.
Show resolved Hide resolved
}
`;

export default customCss;
3 changes: 3 additions & 0 deletions src/pages/Background/index.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
9 changes: 9 additions & 0 deletions src/pages/Background/installed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const installNotice = () => {
console.log("kartrak - extension installed");

chrome.tabs.create({
url: chrome.runtime.getURL("welcome.html"),
});
};

export default installNotice;
3 changes: 3 additions & 0 deletions src/pages/Popup/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
html {
jerembdn marked this conversation as resolved.
Show resolved Hide resolved
width: 380px;
}
1 change: 1 addition & 0 deletions src/pages/Popup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
import { createRoot } from "react-dom/client";

import Popup from "./Popup";
import "./index.css";
Copy link
Member

Choose a reason for hiding this comment

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

remove it

import "./../../styles/fonts.css";

const container = document.getElementById("app-container");
const root = createRoot(container!); // createRoot(container!) if you use TypeScript

Check warning on line 9 in src/pages/Popup/index.tsx

View workflow job for this annotation

GitHub Actions / Build, lint, and test

Forbidden non-null assertion
root.render(<Popup />);
154 changes: 154 additions & 0 deletions src/pages/Welcome/Welcome.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
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<boolean>(false);
const [error, setError] = React.useState<string | null>(null);

const handleCheckIfPinned = React.useCallback((shouldError = true) => {
console.log("kartrak - check if pinned");

const checkIfPinned = async (): Promise<boolean> => {
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 (
<Container>
<Row>
<GlobalStyle />

{isPinned ? (
<>
<Title>{"Vous êtes prêt à y aller !"}</Title>

<TextContent>
{
"Vous pouvez désormais cliquer sur l’extension quand vous le souhaitez pour analyser des sites internets ou voir vos statistiques d’activités."
}
</TextContent>

<Image
src={require("../../assets/img/welcome/opened-extension.png")}
alt={"Extension ouverte"}
/>

<StyledButton onClick={handleCloseTab}>
{"J’ai compris, merci"}
</StyledButton>
</>
) : (
<>
<Title>
{"Kartrak est désormais installé sur votre navigateur"}
</Title>

<TextContent>
{
"Epinglez 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 !"
jerembdn marked this conversation as resolved.
Show resolved Hide resolved
}
</TextContent>

<Image
jerembdn marked this conversation as resolved.
Show resolved Hide resolved
src={require("../../assets/img/welcome/extension-pinned.png")}
alt={"Extension épinglée"}
Copy link
Member

Choose a reason for hiding this comment

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

add width and height attributes to avoid blinking during first paint

Copy link
Member Author

Choose a reason for hiding this comment

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

i don't understand

Copy link
Member

Choose a reason for hiding this comment

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

an image should have a width and height attribute, what you. don't understand ?

/>

<StyledButton onClick={() => handleCheckIfPinned()}>
{"J'ai épinglé l'extension"}
</StyledButton>

{error && <Error>{error}</Error>}
</>
)}
</Row>
</Container>
);
};

const Container = styled.main`
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
Copy link
Member

Choose a reason for hiding this comment

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

don't use 100vh because we cant scroll if the window height is low

Copy link
Member Author

Choose a reason for hiding this comment

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

ok so i don't know how to do it

`;

const Row = styled.div`
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
max-width: 800px;
jerembdn marked this conversation as resolved.
Show resolved Hide resolved
`;

const Title = styled.h1`
font-family: "neulis-cursive";
font-size: 48px;
font-weight: 600;
text-align: center;
color: var(--primary);
Copy link
Member

Choose a reason for hiding this comment

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

it's true that I didn't do it everywhere, but get into the habit of using fallback colors when you use css variables

Copy link
Member Author

Choose a reason for hiding this comment

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

idk how to do it

Copy link
Member

Choose a reason for hiding this comment

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

`;

const TextContent = styled.p`
margin-top: 15px;
jerembdn marked this conversation as resolved.
Show resolved Hide resolved
text-align: center;

color: var(--grey);
font-size: 18px;
`;

const Image = styled.img`
margin-top: 40px;
jerembdn marked this conversation as resolved.
Show resolved Hide resolved
max-width: 560px;
jerembdn marked this conversation as resolved.
Show resolved Hide resolved
`;

const StyledButton = styled(Button)`
margin-top: 40px;
jerembdn marked this conversation as resolved.
Show resolved Hide resolved
`;

const Error = styled.p`
margin-top: 10px;
color: var(--red);
`;

export default WelcomePage;
12 changes: 12 additions & 0 deletions src/pages/Welcome/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Merci d'avoir installé Kartrak</title>
</head>

<body>
<div id="app-container"></div>
</body>
</html>
11 changes: 11 additions & 0 deletions src/pages/Welcome/index.tsx
Original file line number Diff line number Diff line change
@@ -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(<WelcomePage />);
12 changes: 12 additions & 0 deletions src/types/html-component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type HTMLComponent<P, N = React.HTMLAttributes<any>> = {
/**
* The root element.
*/
as?: React.ElementType;
/**
* The content, duh.
*/
children?: React.ReactNode;
} & P &
Partial<Omit<N, keyof P>>;
7 changes: 7 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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",
Expand Down
Loading