Skip to content

Commit

Permalink
BREAKING CHANGE: rewrite to preact (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
scffs authored Oct 24, 2023
1 parent 1bef8a4 commit d9a49dd
Show file tree
Hide file tree
Showing 84 changed files with 4,197 additions and 2,834 deletions.
78 changes: 21 additions & 57 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,68 +1,32 @@
module.exports = {
env: {
browser: true,
es2021: true,
},
extends: ['eslint:recommended', 'plugin:preact/recommended', 'prettier'],
parser: '@typescript-eslint/parser',
plugins: ['react', '@typescript-eslint', '@typescript-eslint/eslint-plugin'],
extends: ['airbnb', 'airbnb-typescript'],
parserOptions: {
ecmaVersion: 'latest',
ecmaVersion: 2021,
sourceType: 'module',
project: ['./tsconfig.json'],
},
settings: {
react: {
version: '^18.2.0',
},
env: {
browser: true,
es6: true,
},
plugins: ['@typescript-eslint', 'preact', 'prettier'],
rules: {
quotes: ['error', 'single'],
semi: [1, 'always'],
'max-len': ['warn', { code: 150 }],
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{ "argsIgnorePattern": "^_" }
],
"prettier/prettier": "error",
"prefer-arrow-callback": "error",
"react/jsx-no-bind": "off",
"no-console": "off",
},
overrides: [
{
files: ['bin/*.js', 'lib/*.js', '*.ts', '*.tsx'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
],
settings: {
react: {
version: "^17.0",
},
{
files: ['*.tsx', '*.ts'],
rules: {
'linebreak-style': 'off',
'import/prefer-default-export': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'react/react-in-jsx-scope': 'off',
'@typescript-eslint/no-misused-promises': 'off',
'@typescript-eslint/no-floating-promises': 'off',
'react/require-default-props': 'off',
'react/jsx-fragments': 'off',
'no-console': 'off',
'import/no-extraneous-dependencies': 'off',
// @see https://stackoverflow.com/questions/46735483/error-do-not-use-array-index-in-keys
// Обычно так делать нельзя, но в рамках нашего проекта - можно
// Т.к. наши массивы статичны и юзер не может как-либо менять порядок / удалять элементы,
// мы можем использовать индекс как key
'react/no-array-index-key': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'no-nested-ternary': 'off',
'react/jsx-props-no-spreading': 'off',
'no-param-reassign': 'off',
'max-classes-per-file': 'off',
'jsx-quotes': [2, 'prefer-single'],
'react/function-component-definition': [2, {
namedComponents: 'arrow-function',
unnamedComponents: 'arrow-function',
},
],
},
parserOptions: {
project: ['./tsconfig.json'],
},
jest: {
version: 26,
},
],
},
};
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"trailingComma": "es5",
"semi": false,
"singleQuote": true,
"useTabs": false
}
45 changes: 0 additions & 45 deletions .yarnclean

This file was deleted.

15 changes: 0 additions & 15 deletions index-a12.html

This file was deleted.

14 changes: 14 additions & 0 deletions index1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<link rel="icon" type="image/svg+xml" href="/vite.svg"/>
<meta name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no, user-scalable=no, viewport-fit=cover"/>
<title>Vite + Preact + TS</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
42 changes: 25 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"name": "dnevnik-ts",
"private": true,
"homepage": ".",
"version": "6.0.0",
"version": "7.0.0",
"type": "module",
"scripts": {
"dev": "vite",
Expand All @@ -13,39 +12,48 @@
"preview": "vite preview"
},
"dependencies": {
"@vkontakte/icons": "^2.66.0",
"@reduxjs/toolkit": "^1.9.7",
"@vkontakte/icons": "^2.72.0",
"@vkontakte/vk-bridge": "^2.11.2",
"@vkontakte/vk-bridge-react": "^1.0.0",
"@vkontakte/vk-mini-apps-router": "^1.1.1",
"@vkontakte/vkui": "^5.8.1",
"@vkontakte/vkui": "^5.9.4",
"jshashes": "^1.0.8",
"react": "^18.2.0",
"react-dom": "^18.2.0"
"preact": "^10.16.0",
"react-redux": "^8.1.3"
},
"devDependencies": {
"@rollup/plugin-terser": "^0.4.3",
"@types/node": "^20.6.1",
"@types/react": "^18.2.15",
"@types/react-dom": "^18.2.7",
"@babel/eslint-parser": "^7.22.15",
"@preact/preset-vite": "^2.5.0",
"@rollup/plugin-terser": "^0.4.4",
"@types/node": "^20.8.7",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"@vitejs/plugin-basic-ssl": "^1.0.1",
"@vitejs/plugin-react-swc": "^3.3.2",
"@typescript-eslint/parser": "^6.8.0",
"@vkontakte/vk-miniapps-deploy": "^0.1.6",
"diary-shared": "1.8.0",
"eslint": "^8.45.0",
"diary-shared": "^1.8.0",
"eslint": "^8.52.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-airbnb-typescript": "^17.1.0",
"eslint-config-preact": "^1.3.0",
"eslint-config-prettier": "^9.0.0",
"eslint-config-standard-with-typescript": "^38.0.0",
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-jest": "^27.4.3",
"eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-n": "^16.0.2",
"eslint-plugin-preact": "^0.1.0",
"eslint-plugin-prettier": "^5.0.1",
"eslint-plugin-promise": "^6.0.0",
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.3",
"prop-types": "^15.8.1",
"typescript": "^5.0.2",
"prettier": "^3.0.3",
"typescript": "^5.2.2",
"vite": "^4.4.5"
},
"peerDependencies": {
"@babel/core": "^7.0.0-0-dom",
"react": "^18.1.0",
"react-dom": "^18.1.0"
}
}
1 change: 1 addition & 0 deletions public/vite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
92 changes: 53 additions & 39 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,64 +1,78 @@
import {
AppRoot, PanelHeader, ScreenSpinner, SplitCol, SplitLayout,
} from '@vkontakte/vkui';
import { lazy, useEffect, useState } from 'react';
import { useActiveVkuiLocation, usePopout, useRouteNavigator } from '@vkontakte/vk-mini-apps-router';
import { useInsets } from '@vkontakte/vk-bridge-react';
import { MAIN_SETTINGS, VIEW_SCHEDULE } from './routes';
import { getCookie } from './methods';
import { Pages } from './types';
import Suspense from './components/UI/Suspense';
AppRoot,
PanelHeader,
ScreenSpinner,
SplitCol,
SplitLayout,
} from '@vkontakte/vkui'
import {
useActiveVkuiLocation,
usePopout,
useRouteNavigator,
} from '@vkontakte/vk-mini-apps-router'
import { useInsets } from '@vkontakte/vk-bridge-react'
import { lazy } from 'preact/compat'
import { useEffect, useState } from 'preact/hooks'
import { MAIN_SETTINGS, VIEW_SCHEDULE } from './routes'
import { Pages } from './types'
import Suspense from './components/UI/Suspense'

const ModalRoot = lazy(() => import('./modals/ModalRoot'));
const Epic = lazy(() => import('./components/UI/Epic'));
const ModalRoot = lazy(() => import('./modals/ModalRoot'))
const Epic = lazy(() => import('./components/UI/Epic'))

const App = () => {
const [isLoading, setIsLoading] = useState<boolean>(false);
const { view: activeView = MAIN_SETTINGS } = useActiveVkuiLocation();
const routeNavigator = useRouteNavigator();
const modals = <ModalRoot />;
const [isLoading, setIsLoading] = useState<boolean>(false)
const routeNavigator = useRouteNavigator()
const modals = <ModalRoot />
const { view: activeView = MAIN_SETTINGS } = useActiveVkuiLocation()
const cookieValue = localStorage.getItem('cookie')

const routerPopout = usePopout();
const vkBridgeInsets = useInsets() || undefined;
const routerPopout = usePopout()
const vkBridgeInsets = useInsets() || undefined

useEffect(() => {
getCookie().then(async (cookieValue) => {
const onRoute = async () => {
if (!cookieValue) {
await routeNavigator.replace('/');
setIsLoading(false);
} else if ((cookieValue) && activeView === MAIN_SETTINGS) {
await routeNavigator.replace(`/${VIEW_SCHEDULE}`);
setIsLoading(false);
await routeNavigator.replace('/')
setIsLoading(false)
} else if (cookieValue && activeView === MAIN_SETTINGS) {
await routeNavigator.replace(`/${VIEW_SCHEDULE}`)
setIsLoading(false)
}
});
}, [activeView, localStorage, window.location]);
}

const onStoryChange = async (currentView: Pages) => {
const cookieValue = await getCookie();
onRoute()
}, [activeView, localStorage, window.location])

const onStoryChange = async (currentView: Pages) => {
if (cookieValue) {
try {
await routeNavigator.push(`/${currentView}`);
return;
await routeNavigator.push(`/${currentView}`)
return
} catch (e) {
console.error(e);
console.error(e)
}
}
await routeNavigator.replace('/');
};
await routeNavigator.replace('/')
}

return (
<AppRoot safeAreaInsets={vkBridgeInsets}>
<SplitLayout popout={routerPopout} modal={modals} header={<PanelHeader separator={false} />} style={{ justifyContent: 'center' }}>
<Suspense id='Epic'>
{isLoading && <ScreenSpinner size='large' />}
<SplitCol width='100%' maxWidth='700px' stretchedOnMobile autoSpaced>
<SplitLayout
popout={routerPopout}
modal={modals}
header={<PanelHeader separator={false} />}
style={{ justifyContent: 'center' }}
>
<Suspense id="Epic">
{isLoading && <ScreenSpinner size="large" />}
<SplitCol width="100%" maxWidth="700px" stretchedOnMobile autoSpaced>
<Epic onStoryChange={onStoryChange} />
</SplitCol>
</Suspense>
</SplitLayout>
</AppRoot>
);
};
)
}

export default App;
export default App
Loading

0 comments on commit d9a49dd

Please sign in to comment.