diff --git a/package.json b/package.json index 2edc88965..45363e073 100755 --- a/package.json +++ b/package.json @@ -18,9 +18,11 @@ "@emotion/styled": "^11.10.4", "@hot-loader/react-dom": "^17.0.2", "framer-motion": "6.2.4", + "js-cookie": "^3.0.1", "react": "^17.0.2", "react-dom": "^17.0.2", - "react-hot-loader": "^4.13.0" + "react-hot-loader": "^4.13.0", + "react-select": "^5.6.1" }, "devDependencies": { "@babel/core": "^7.17.0", @@ -28,6 +30,7 @@ "@babel/preset-env": "^7.16.11", "@babel/preset-react": "^7.16.7", "@types/chrome": "^0.0.177", + "@types/js-cookie": "^3.0.2", "@types/react": "^17.0.39", "@types/react-dom": "^17.0.11", "babel-eslint": "^10.1.0", @@ -57,4 +60,4 @@ "webpack-cli": "^4.9.2", "webpack-dev-server": "^4.7.4" } -} \ No newline at end of file +} diff --git a/src/manifest.json b/src/manifest.json index 730ffeec2..cb96cb365 100755 --- a/src/manifest.json +++ b/src/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 3, - "name": "Takeoff", - "description": "A chrome extension that will help you to takeoff from your current tab to a new tab.", + "name": "Happy Tabs", + "description": "A chrome extension that will turn that frown upside down! :)", "options_page": "options.html", "background": { "service_worker": "background.bundle.js" @@ -16,6 +16,10 @@ "icons": { "128": "icon-128.png" }, + "permissions": [ + "identity", + "identity.email" + ], "content_scripts": [ { "matches": [ diff --git a/src/pages/Components/user-selection.tsx b/src/pages/Components/user-selection.tsx new file mode 100644 index 000000000..8a667640c --- /dev/null +++ b/src/pages/Components/user-selection.tsx @@ -0,0 +1,94 @@ +import { Flex, Text } from "@chakra-ui/react"; +import React, { useEffect, useState } from "react"; +import Select from 'react-select'; +import { getItem, setItem } from "../Utils/storage"; + +const options = [ + { value: 'chocolate', label: 'Chocolate' }, + { value: 'strawberry', label: 'Strawberry' }, + { value: 'mint', label: 'Mint' }, + { value: 'peach', label: 'Peach' }, + { value: 'vanilla', label: 'Vanilla' }, + { value: 'caramel', label: 'Caramel' }, + { value: 'coffee', label: 'Coffee' }, + { value: 'raspberry', label: 'Raspberry' }, + { value: 'lemon', label: 'Lemon' }, + { value: 'lime', label: 'Lime' }, + { value: 'orange', label: 'Orange' }, + { value: 'watermelon', label: 'Watermelon' }, + { value: 'grape', label: 'Grape' }, +]; + +type Option = { + value: string; + label: string; +} + +export const UserSelection = ({ width, email, userId, isLoading, selections }: { width: number; email?: string; userId: string; selections?: Option[]; isLoading?: boolean; }) => { + const [selected, setSelected] = useState((selections || []) as Option[]); + const [loading, setLoading] = useState(true); + + const text = `Hello${email ? `, ${email.split('@')[0]}` : ' Sexy'}!`; + + useEffect(() => { + const setItems = async () => { + if (selected.length > 0) { + await setItem('user-selection', JSON.stringify({ [userId]: selected.map((e) => e.value) })); + } + } + setItems(); + }, [selected, userId]); + + useEffect(() => { + if (!userId) return; + const getItems = async () => { + const results = await getItem('user-selection'); + if (results) { + const parsed = JSON.parse(results as unknown as string); + Object.keys(parsed)?.includes(userId) ? setSelected(parsed[userId].map((e: string) => ({ value: e, label: e }))) : setSelected([]); + + } + setLoading(false) + } + getItems(); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [userId]); + + if (loading || isLoading) { + return ( + + Loading... + + ) + } + + return ( + + + {text} + +