Skip to content

Commit

Permalink
code with react hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
kmvan committed Oct 29, 2020
1 parent 6d0dbdb commit abadd5e
Show file tree
Hide file tree
Showing 50 changed files with 7,080 additions and 10,673 deletions.
15,311 changes: 5,810 additions & 9,501 deletions package-lock.json

Large diffs are not rendered by default.

42 changes: 22 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "A PHP probe",
"scripts": {
"lang": "node ./build-lang.js",
"dev": "cross-env webpack --progress --watch",
"dev": "cross-env webpack --config webpack.config.js --progress --watch",
"dev:php": "php ./Make.php dev; php -S localhost:8000 -t .tmp",
"build": "cross-env webpack --config webpack.config.prod.js --progress",
"build:php": "php-cs-fixer fix ./src --config=.php_cs53; php ./Make.php build; php -S localhost:8000/prober.php -t dist",
Expand All @@ -23,40 +23,42 @@
"@babel/preset-react": "^7.12.1",
"@babel/preset-typescript": "^7.12.1",
"@types/core-js": "^2.5.4",
"@types/node": "^14.11.10",
"@types/node": "^14.14.5",
"@types/query-string": "^6.3.0",
"@types/react": "^16.9.53",
"@types/react-dom": "^16.9.8",
"@types/react": "^16.9.54",
"@types/react-dom": "^16.9.9",
"babel-plugin-styled-components": "^1.11.1",
"cross-env": "^7.0.2",
"eslint": "^7.11.0",
"eslint-plugin-react": "^7.21.4",
"mobx": "5.15.7",
"mobx-react": "6.3.1",
"eslint": "^7.12.1",
"eslint-plugin-react": "^7.21.5",
"node-libs-browser": "^2.2.1",
"pofile": "^1.1.0",
"react": "^16.14.0",
"react-dom": "^16.14.0",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-hot-loader": "^4.13.0",
"terser-webpack-plugin": "^5.0.0",
"ts-loader": "^8.0.5",
"typescript": "^4.0.3",
"webpack": "^5.1.3",
"webpack-cli": "^4.0.0",
"terser-webpack-plugin": "^5.0.3",
"ts-loader": "^8.0.7",
"typescript": "^4.0.5",
"webpack": "^5.3.0",
"webpack-cli": "^4.1.0",
"webpack-common-shake": "^2.1.0",
"webpack-dev-server": "^3.11.0",
"webpack-log": "^3.0.1"
},
"dependencies": {
"@types/immutability-helper": "^2.6.3",
"@types/styled-components": "^5.1.4",
"@typescript-eslint/eslint-plugin": "^4.4.1",
"@typescript-eslint/eslint-plugin-tslint": "^4.4.1",
"@typescript-eslint/parser": "^4.4.1",
"@typescript-eslint/eslint-plugin": "^4.6.0",
"@typescript-eslint/eslint-plugin-tslint": "^4.6.0",
"@typescript-eslint/parser": "^4.6.0",
"babel-loader": "^8.1.0",
"caniuse-lite": "^1.0.30001148",
"caniuse-lite": "^1.0.30001151",
"es6-promise": "^4.2.8",
"eslint-config-prettier": "^6.13.0",
"eslint-config-prettier": "^6.15.0",
"glob": "^7.1.6",
"immutability-helper": "^3.1.1",
"mobx": "^6.0.1",
"mobx-react-lite": "^3.0.1",
"polished": "^4.0.3",
"query-string": "^6.13.6",
"styled-components": "^5.2.0",
Expand Down
43 changes: 20 additions & 23 deletions src/Components/Bootstrap/src/components/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { Component } from 'react'
import React from 'react'
import { render } from 'react-dom'
import ready from '@/Helper/src/components/ready'
import styled, { ThemeProvider } from 'styled-components'
Expand Down Expand Up @@ -26,7 +26,7 @@ import ColorScheme from '@/ColorScheme/src/components'
import { GUTTER } from '@/Config/src'
import { rgba } from 'polished'
import ColorSchemeStore from '@/ColorScheme/src/stores'
import { observer } from 'mobx-react'
import { observer } from 'mobx-react-lite'

const StyledApp = styled.div`
padding: calc(${GUTTER} * 3.5) 0 calc(${GUTTER} * 2);
Expand All @@ -51,27 +51,24 @@ const StyledApp = styled.div`
}
`

@observer
class Bootstrap extends Component {
public render() {
return (
<ThemeProvider theme={ColorSchemeStore.scheme}>
<Normalize />
<Title />
<StyledApp ref={c => store.setAppContainer(c)}>
<Container>
<ColorScheme />
<Cards />
<Footer />
</Container>
</StyledApp>
<Nav />
<Forkme />
<Toast />
</ThemeProvider>
)
}
}
const Bootstrap = observer(() => {
return (
<ThemeProvider theme={ColorSchemeStore.scheme}>
<Normalize />
<Title />
<StyledApp ref={c => store.setAppContainer(c)}>
<Container>
<ColorScheme />
<Cards />
<Footer />
</Container>
</StyledApp>
<Nav />
<Forkme />
<Toast />
</ThemeProvider>
)
})

ready(() => {
const c = document.createElement('div')
Expand Down
6 changes: 5 additions & 1 deletion src/Components/Bootstrap/src/stores/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { observable, action, configure } from 'mobx'
import { observable, action, configure, makeObservable } from 'mobx'
import conf from '@/Helper/src/components/conf'

configure({
Expand All @@ -19,6 +19,10 @@ class Store {

@observable public appContainer: HTMLElement | null = null

public constructor() {
makeObservable(this)
}

@action
public setAppContainer = (appContainer: HTMLElement | null) => {
this.appContainer = appContainer
Expand Down
105 changes: 52 additions & 53 deletions src/Components/Card/src/components/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React, { Component } from 'react'
import React from 'react'
import styled from 'styled-components'
import { observer } from 'mobx-react'
import store from '../stores'
import { GUTTER } from '@/Config/src'
import { gettext } from '@/Language/src'
import { rgba } from 'polished'
import { device } from '@/Style/src/components/devices'
import { observer } from 'mobx-react-lite'

interface StyleArrowProps {
isHidden: boolean
Expand Down Expand Up @@ -57,58 +57,57 @@ const StyleArrow = styled.a<StyleArrowProps>`
}
`

@observer
export default class Cards extends Component {
public render() {
const {
cardsLength,
enabledCards,
enabledCardsLength,
moveCardDown,
moveCardUp,
} = store
const Cards = observer(() => {
const {
cardsLength,
enabledCards,
enabledCardsLength,
moveCardDown,
moveCardUp,
} = store

if (!cardsLength) {
return null
}
if (!cardsLength) {
return null
}

return (
<>
{enabledCards.map(({ id, title, component: Tag }, i) => {
const upArrow = (
<StyleArrow
title={gettext('Move up')}
isHidden={i === 0}
onClick={() => moveCardUp(id)}
>
</StyleArrow>
)
return (
<>
{enabledCards.map(({ id, title, component: Tag }, i) => {
const upArrow = (
<StyleArrow
title={gettext('Move up')}
isHidden={i === 0}
onClick={() => moveCardUp(id)}
>
</StyleArrow>
)

const downArrow = (
<StyleArrow
title={gettext('Move down')}
isHidden={i === enabledCardsLength - 1}
onClick={() => moveCardDown(id)}
>
</StyleArrow>
)
const downArrow = (
<StyleArrow
title={gettext('Move down')}
isHidden={i === enabledCardsLength - 1}
onClick={() => moveCardDown(id)}
>
</StyleArrow>
)

return (
<StyledFieldset key={id} id={id}>
<StyledLegend>
{upArrow}
{title}
{downArrow}
</StyledLegend>
<StyledBody>
<Tag />
</StyledBody>
</StyledFieldset>
)
})}
</>
)
}
}
return (
<StyledFieldset key={id} id={id}>
<StyledLegend>
{upArrow}
{title}
{downArrow}
</StyledLegend>
<StyledBody>
<Tag />
</StyledBody>
</StyledFieldset>
)
})}
</>
)
})

export default Cards
16 changes: 11 additions & 5 deletions src/Components/Card/src/stores/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { observable, action, configure, computed } from 'mobx'
import { ComponentClass } from 'react'
import { observable, action, configure, computed, makeObservable } from 'mobx'
import { FunctionComponent } from 'react'

configure({
enforceActions: 'observed',
Expand All @@ -16,12 +16,16 @@ export interface CardProps {
tinyTitle: string
enabled?: boolean
priority: number
component: ComponentClass
component: FunctionComponent
}

class CardStore {
class Store {
@observable public cards: CardProps[] = []

public constructor() {
makeObservable(this)
}

@action
public addCard = (card: CardProps) => {
const priority = this.getStoragePriority(card.id)
Expand Down Expand Up @@ -141,4 +145,6 @@ class CardStore {
}
}

export default new CardStore()
const CardStore = new Store()

export default CardStore
39 changes: 19 additions & 20 deletions src/Components/ColorScheme/src/components/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, { Component } from 'react'
import { observer } from 'mobx-react'
import React from 'react'
import styled, { keyframes } from 'styled-components'
import { GUTTER, BORDER_RADIUS, ANIMATION_DURATION_SC } from '@/Config/src'
import schemes from '../stores/colors'
import { rgba } from 'polished'
import store from '../stores'
import { observer } from 'mobx-react-lite'

const fadeIn = keyframes`
from{
Expand Down Expand Up @@ -46,21 +46,20 @@ const StyledColorScheme = styled.div`
animation-fill-mode: forwards;
`

@observer
export default class ColorScheme extends Component {
public render() {
return (
<StyledColorScheme>
{Object.entries(schemes).map(([schemeId, { name, colorDark }]) => (
<StyledColorSchemeLink
isActive={schemeId === store.schemeId}
title={name}
key={schemeId}
style={{ backgroundColor: colorDark }}
onClick={() => store.setSchemeId(schemeId)}
/>
))}
</StyledColorScheme>
)
}
}
const ColorScheme = observer(() => {
return (
<StyledColorScheme>
{Object.entries(schemes).map(([schemeId, { name, colorDark }]) => (
<StyledColorSchemeLink
isActive={schemeId === store.schemeId}
title={name}
key={schemeId}
style={{ backgroundColor: colorDark }}
onClick={() => store.setSchemeId(schemeId)}
/>
))}
</StyledColorScheme>
)
})

export default ColorScheme
6 changes: 5 additions & 1 deletion src/Components/ColorScheme/src/stores/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { configure, observable, action, computed } from 'mobx'
import { configure, observable, action, computed, makeObservable } from 'mobx'
import schemes from './colors'

configure({
Expand All @@ -22,6 +22,10 @@ class Store {

@observable public schemeId: string = this.getStorageSchemeId()

public constructor() {
makeObservable(this)
}

@action
public setSchemeId = (schemeId: string) => {
this.schemeId = schemeId
Expand Down
Loading

0 comments on commit abadd5e

Please sign in to comment.