Skip to content

Commit

Permalink
feat: Add main layout and routing system (#72)
Browse files Browse the repository at this point in the history
* Add main layout and routing system

* Fix comments

---------

Co-authored-by: Diana Fulga <[email protected]>
  • Loading branch information
dianafulga and Diana Fulga authored Jan 23, 2024
1 parent fe4c099 commit 707d855
Show file tree
Hide file tree
Showing 17 changed files with 522 additions and 415 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
"postcss": "^8.4.32",
"postcss-loader": "^7.3.3",
"prettier": "^3.0.3",
"react-router-dom": "^6.21.1",
"tailwindcss": "^3.4.0",
"ts-jest": "^29.1.1",
"ts-loader": "^9.4.4",
Expand Down
31 changes: 31 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 0 additions & 11 deletions src/components/Popup/PopupFooter/PopupFooter.scss

This file was deleted.

19 changes: 0 additions & 19 deletions src/components/Popup/PopupFooter/PopupFooter.tsx

This file was deleted.

1 change: 0 additions & 1 deletion src/components/Popup/PopupFooter/index.ts

This file was deleted.

26 changes: 0 additions & 26 deletions src/components/Popup/PopupHeader/PopupHeader.scss

This file was deleted.

20 changes: 0 additions & 20 deletions src/components/Popup/PopupHeader/PopupHeader.tsx

This file was deleted.

1 change: 0 additions & 1 deletion src/components/Popup/PopupHeader/index.ts

This file was deleted.

44 changes: 44 additions & 0 deletions src/components/icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,50 @@ export const Spinner = (props: React.SVGProps<SVGSVGElement>) => {
)
}

export const ArrowBack = (props: React.SVGProps<SVGSVGElement>) => {
return (
<svg
width="25"
height="25"
viewBox="0 0 25 25"
fill="none"
xmlns="http://www.w3.org/2000/svg"
{...props}>
<mask id="mask0_169_196" maskUnits="userSpaceOnUse" x="0" y="0" width="25" height="25">
<rect x="0.75" y="0.5" width="24" height="24" fill="#C4C4C4" />
</mask>
<g mask="url(#mask0_169_196)">
<path
d="M12.75 20.5L4.75 12.5L12.75 4.5L14.175 5.9L8.575 11.5H20.75V13.5H8.575L14.175 19.1L12.75 20.5Z"
fill="#475569"
/>
</g>
</svg>
)
}

export const Settings = (props: React.SVGProps<SVGSVGElement>) => {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
width="25"
height="25"
viewBox="0 0 25 25"
fill="none"
{...props}>
<mask id="mask0_140_3136" maskUnits="userSpaceOnUse" x="0" y="0" width="25" height="25">
<rect x="0.75" y="0.5" width="24" height="24" fill="#C4C4C4" />
</mask>
<g mask="url(#mask0_140_3136)">
<path
d="M10.0002 22.5L9.6002 19.3C9.38353 19.2167 9.17953 19.1167 8.9882 19C8.7962 18.8833 8.60853 18.7583 8.4252 18.625L5.4502 19.875L2.7002 15.125L5.2752 13.175C5.25853 13.0583 5.2502 12.9457 5.2502 12.837C5.2502 12.729 5.2502 12.6167 5.2502 12.5C5.2502 12.3833 5.2502 12.2707 5.2502 12.162C5.2502 12.054 5.25853 11.9417 5.2752 11.825L2.7002 9.875L5.4502 5.125L8.4252 6.375C8.60853 6.24167 8.8002 6.11667 9.0002 6C9.2002 5.88333 9.4002 5.78333 9.6002 5.7L10.0002 2.5H15.5002L15.9002 5.7C16.1169 5.78333 16.3212 5.88333 16.5132 6C16.7045 6.11667 16.8919 6.24167 17.0752 6.375L20.0502 5.125L22.8002 9.875L20.2252 11.825C20.2419 11.9417 20.2502 12.054 20.2502 12.162C20.2502 12.2707 20.2502 12.3833 20.2502 12.5C20.2502 12.6167 20.2502 12.729 20.2502 12.837C20.2502 12.9457 20.2335 13.0583 20.2002 13.175L22.7752 15.125L20.0252 19.875L17.0752 18.625C16.8919 18.7583 16.7002 18.8833 16.5002 19C16.3002 19.1167 16.1002 19.2167 15.9002 19.3L15.5002 22.5H10.0002ZM12.8002 16C13.7669 16 14.5919 15.6583 15.2752 14.975C15.9585 14.2917 16.3002 13.4667 16.3002 12.5C16.3002 11.5333 15.9585 10.7083 15.2752 10.025C14.5919 9.34167 13.7669 9 12.8002 9C11.8169 9 10.9875 9.34167 10.3122 10.025C9.63753 10.7083 9.3002 11.5333 9.3002 12.5C9.3002 13.4667 9.63753 14.2917 10.3122 14.975C10.9875 15.6583 11.8169 16 12.8002 16ZM12.8002 14C12.3835 14 12.0295 13.854 11.7382 13.562C11.4462 13.2707 11.3002 12.9167 11.3002 12.5C11.3002 12.0833 11.4462 11.7293 11.7382 11.438C12.0295 11.146 12.3835 11 12.8002 11C13.2169 11 13.5712 11.146 13.8632 11.438C14.1545 11.7293 14.3002 12.0833 14.3002 12.5C14.3002 12.9167 14.1545 13.2707 13.8632 13.562C13.5712 13.854 13.2169 14 12.8002 14ZM11.7502 20.5H13.7252L14.0752 17.85C14.5919 17.7167 15.0712 17.5207 15.5132 17.262C15.9545 17.004 16.3585 16.6917 16.7252 16.325L19.2002 17.35L20.1752 15.65L18.0252 14.025C18.1085 13.7917 18.1669 13.5457 18.2002 13.287C18.2335 13.029 18.2502 12.7667 18.2502 12.5C18.2502 12.2333 18.2335 11.9707 18.2002 11.712C18.1669 11.454 18.1085 11.2083 18.0252 10.975L20.1752 9.35L19.2002 7.65L16.7252 8.7C16.3585 8.31667 15.9545 7.99567 15.5132 7.737C15.0712 7.479 14.5919 7.28333 14.0752 7.15L13.7502 4.5H11.7752L11.4252 7.15C10.9085 7.28333 10.4295 7.479 9.9882 7.737C9.5462 7.99567 9.14186 8.30833 8.7752 8.675L6.3002 7.65L5.3252 9.35L7.47519 10.95C7.39186 11.2 7.33353 11.45 7.3002 11.7C7.26686 11.95 7.2502 12.2167 7.2502 12.5C7.2502 12.7667 7.26686 13.025 7.3002 13.275C7.33353 13.525 7.39186 13.775 7.47519 14.025L5.3252 15.65L6.3002 17.35L8.7752 16.3C9.14186 16.6833 9.5462 17.004 9.9882 17.262C10.4295 17.5207 10.9085 17.7167 11.4252 17.85L11.7502 20.5Z"
fill="#475569"
/>
</g>
</svg>
)
}

export const DollarSign = (props: React.SVGProps<SVGSVGElement>) => {
return (
<svg
Expand Down
43 changes: 43 additions & 0 deletions src/components/layout/header.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import React, { useMemo } from 'react'
import { Link, useLocation } from 'react-router-dom'
import { runtime } from 'webextension-polyfill'

import { ArrowBack, Settings } from '../icons'
import { ROUTES } from '../router-provider'

const Logo = runtime.getURL('assets/images/logo.svg')

const NavigationButton = () => {
const location = useLocation()

const component = useMemo(
() =>
location.pathname === `/${ROUTES.SETTINGS}` ? (
<Link to={ROUTES.INDEX}>
<ArrowBack className="h-6" />
</Link>
) : (
<Link to={ROUTES.SETTINGS}>
<Settings className="h-6" />
</Link>
),

[location],
)

return component
}

export const Header = () => {
return (
<div className="flex flex-row items-center justify-between py-8">
<div className="flex flex-row items-center">
<img src={Logo} alt="Web Monetization Logo" className="h-6" />
<p className="ml-3 text-strong text-xl">Web Monetization</p>
</div>
<div className="flex flex-row items-center">
<NavigationButton />
</div>
</div>
)
}
20 changes: 20 additions & 0 deletions src/components/layout/main-layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react'
import { Outlet } from 'react-router-dom'

import { Header } from './header'

const Divider = () => {
return <div className="mb-8 bg-divider-gradient w-100 h-1" />
}

export const MainLayout = () => {
return (
<div className="flex flex-col w-popup h-popup border-base px-6">
<Header />
<Divider />
<main>
<Outlet />
</main>
</div>
)
}
22 changes: 22 additions & 0 deletions src/components/router-provider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* eslint-disable simple-import-sort/imports */
import React from 'react'
import { MemoryRouter, Routes, Route } from 'react-router-dom'
import { Home } from '@/popup/pages/Home'
import { Settings } from '@/popup/pages/Settings'
import { MainLayout } from './layout/main-layout'

export const ROUTES = {
INDEX: 'index',
SETTINGS: 'settings',
}

export const RouterProvider = () => (
<MemoryRouter basename="popup" initialEntries={['/popup/index']}>
<Routes>
<Route path="" element={<MainLayout />}>
<Route path={ROUTES.SETTINGS} element={<Settings />} />
<Route path={ROUTES.INDEX} element={<Home />} />
</Route>
</Routes>
</MemoryRouter>
)
Loading

0 comments on commit 707d855

Please sign in to comment.