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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(React router): Implemented react router dom api example #6

Merged
merged 5 commits into from Jun 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 27 additions & 0 deletions with-jotai/.github/workflows/submit.yml
@@ -0,0 +1,27 @@
name: "Submit to Web Store"
on:
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Cache pnpm modules
uses: actions/cache@v3
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-
- uses: pnpm/action-setup@v2.2.1
with:
version: 7.1.0
run_install: true
- name: Build and zip extension artifact
run: pnpm build -- --zip
- name: Browser Platform Publish
uses: PlasmoHQ/bpp@v2
with:
keys: ${{ secrets.SUBMIT_KEYS }}
artifact: build/chrome-mv3-prod.zip
42 changes: 42 additions & 0 deletions with-jotai/.gitignore
@@ -0,0 +1,42 @@

# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

#cache
.turbo
.next
.vercel

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*


# local env files
.env*

out/
build/
dist/

# plasmo - https://www.plasmo.com
.plasmo

# bpp - http://bpp.browser.market/
keys.json

# typescript
.tsbuildinfo
17 changes: 17 additions & 0 deletions with-jotai/.prettierrc.cjs
@@ -0,0 +1,17 @@
/**
* @type {import('prettier').Options}
*/
module.exports = {
printWidth: 80,
tabWidth: 2,
useTabs: false,
semi: false,
singleQuote: false,
trailingComma: "none",
bracketSpacing: true,
bracketSameLine: true,
plugins: [require.resolve("@trivago/prettier-plugin-sort-imports")],
importOrder: ["^@plasmohq/(.*)$", "^~(.*)$", "^[./]"],
importOrderSeparation: true,
importOrderSortSpecifiers: true
}
Binary file added with-jotai/assets/icon512.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions with-jotai/counter.tsx
@@ -0,0 +1,24 @@
import { atom, useAtom } from "jotai"

const counterAtom = atom<number>(0);

const CounterView = () => {
const [counter, setCounter] = useAtom(counterAtom);

const onIncrement = (): void => {
setCounter((value: number): number => value + 1);
}

const onDecrement = (): void => {
setCounter((value: number): number => value - 1);
}
return (
<div>
<div>Current count: {counter}</div>
<button onClick={onIncrement}>Increment counter</button>
<button onClick={onDecrement}>Decrement counter</button>
</div>
)
}

export default CounterView;
31 changes: 31 additions & 0 deletions with-jotai/package.json
@@ -0,0 +1,31 @@
{
"name": "with-jotai",
"displayName": "With jotai",
"version": "0.0.0",
"description": "Plasmo extension which uses jotai library for state management",
"author": "yashwadhia",
"scripts": {
"dev": "plasmo dev",
"build": "plasmo build"
},
"dependencies": {
"jotai": "1.7.2",
"plasmo": "latest",
"react": "18.2.0",
"react-dom": "18.2.0"
},
"devDependencies": {
"@trivago/prettier-plugin-sort-imports": "3.2.0",
"@types/chrome": "0.0.190",
"@types/node": "17.0.43",
"@types/react": "18.0.12",
"@types/react-dom": "18.0.5",
"prettier": "2.7.0",
"typescript": "4.7.3"
},
"manifest": {
"host_permissions": [
"https://*/*"
]
}
}
13 changes: 13 additions & 0 deletions with-jotai/popup.tsx
@@ -0,0 +1,13 @@
import {Provider} from "jotai";

import CounterView from "~counter";

function IndexPopup() {
return (
<Provider>
<CounterView />
</Provider>
)
}

export default IndexPopup
33 changes: 33 additions & 0 deletions with-jotai/readme.md
@@ -0,0 +1,33 @@
This is a [Plasmo extension](https://docs.plasmo.com/) project bootstrapped with [`plasmo init`](https://www.npmjs.com/package/plasmo).

## Getting Started

First, run the development server:

```bash
pnpm dev
# or
npm run dev
```

Open your browser and load the appropriate development build. For example, if you are developing for the chrome browser, using manifest v3, use: `build/chrome-mv3-dev`.

You can start editing the popup by modifying `popup.tsx`. It should auto-update as you make changes. To add an options page, simply add a `options.tsx` file to the root of the project, with a react component default exported. Likewise to add a content page, add a `content.ts` file to the root of the project, importing some module and do some logic, then reload the extension on your browser.

For further guidance, [visit our Documentation](https://docs.plasmo.com/)

## Making production build

Run the following:

```bash
pnpm build
# or
npm run build
```

This should create a production bundle for your extension, ready to be zipped and published to the stores.

## Submit to the webstores

The easiest way to deploy your Plasmo extension is to use the built-in [bpp](https://bpp.browser.market) GitHub action. Prior to using this action however, make sure to build your extension and upload the first version to the store to establish the basic credentials. Then, simply follow [this setup instruction](https://docs.plasmo.com/workflows#submit-your-extension) and you should be on your way for automated submission!
11 changes: 11 additions & 0 deletions with-jotai/tsconfig.json
@@ -0,0 +1,11 @@
{
"extends": "plasmo/templates/tsconfig.base",
"exclude": ["node_modules"],
"include": [".plasmo/**/*", "./**/*.ts", "./**/*.tsx"],
"compilerOptions": {
"paths": {
"~*": ["./*"]
},
"baseUrl": "."
}
}
27 changes: 27 additions & 0 deletions with-react-router/.github/workflows/submit.yml
@@ -0,0 +1,27 @@
name: "Submit to Web Store"
on:
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Cache pnpm modules
uses: actions/cache@v3
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-
- uses: pnpm/action-setup@v2.2.1
with:
version: 7.1.0
run_install: true
- name: Build and zip extension artifact
run: pnpm build -- --zip
- name: Browser Platform Publish
uses: PlasmoHQ/bpp@v2
with:
keys: ${{ secrets.SUBMIT_KEYS }}
artifact: build/chrome-mv3-prod.zip
42 changes: 42 additions & 0 deletions with-react-router/.gitignore
@@ -0,0 +1,42 @@

# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

#cache
.turbo
.next
.vercel

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*


# local env files
.env*

out/
build/
dist/

# plasmo - https://www.plasmo.com
.plasmo

# bpp - http://bpp.browser.market/
keys.json

# typescript
.tsbuildinfo
17 changes: 17 additions & 0 deletions with-react-router/.prettierrc.cjs
@@ -0,0 +1,17 @@
/**
* @type {import('prettier').Options}
*/
module.exports = {
printWidth: 80,
tabWidth: 2,
useTabs: false,
semi: false,
singleQuote: false,
trailingComma: "none",
bracketSpacing: true,
bracketSameLine: true,
plugins: [require.resolve("@trivago/prettier-plugin-sort-imports")],
importOrder: ["^@plasmohq/(.*)$", "^~(.*)$", "^[./]"],
importOrderSeparation: true,
importOrderSortSpecifiers: true
}
Binary file added with-react-router/assets/icon512.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions with-react-router/package.json
@@ -0,0 +1,31 @@
{
"name": "with-react-router",
"displayName": "With react router",
"version": "0.0.0",
"description": "A basic Plasmo extension.",
"author": "yashwadhia",
"scripts": {
"dev": "plasmo dev",
"build": "plasmo build"
},
"dependencies": {
"plasmo": "latest",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-router-dom": "6.3.0"
},
"devDependencies": {
"@trivago/prettier-plugin-sort-imports": "3.2.0",
"@types/chrome": "0.0.190",
"@types/node": "17.0.43",
"@types/react": "18.0.12",
"@types/react-dom": "18.0.5",
"prettier": "2.7.0",
"typescript": "4.7.3"
},
"manifest": {
"host_permissions": [
"https://*/*"
]
}
}
16 changes: 16 additions & 0 deletions with-react-router/pages/about.tsx
@@ -0,0 +1,16 @@
import { NavigateFunction, useNavigate } from "react-router-dom"

export const About = () => {
const navigation: NavigateFunction = useNavigate()

const onNextPage = (): void => {
navigation("/")
}

return (
<div style={{ padding: 16 }}>
<span>About page</span>
<button onClick={onNextPage}>Home</button>
</div>
)
}
16 changes: 16 additions & 0 deletions with-react-router/pages/home.tsx
@@ -0,0 +1,16 @@
import { NavigateFunction, useNavigate } from "react-router-dom"

export const Home = () => {
const navigation: NavigateFunction = useNavigate()

const onNextPage = (): void => {
navigation("/about")
}

return (
<div style={{ padding: 16 }}>
<span>Home page</span>
<button onClick={onNextPage}>About</button>
</div>
)
}
13 changes: 13 additions & 0 deletions with-react-router/popup.tsx
@@ -0,0 +1,13 @@
import { MemoryRouter } from "react-router-dom"

import { Routing } from "~routes"

function IndexPopup() {
return (
<MemoryRouter>
<Routing />
</MemoryRouter>
)
}

export default IndexPopup