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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix frontend codestyle #67

Merged
merged 3 commits into from
Jan 6, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ on:
branches:
- main
- lab-[1234]
paths-ignore:
- frontend
pull_request:
branches:
- main
- lab-[1234]
paths-ignore:
- frontend

jobs:
build:
Expand Down
47 changes: 47 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: NodeJS

on:
push:
branches:
- main
- lab-[1234]
paths-ignore:
- backend
pull_request:
branches:
- main
- lab-[1234]
paths-ignore:
- backend

jobs:
build:
defaults:
run:
working-directory: ./frontend
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v3
with:
node-version: latest

- name: Create Fake Certificates
run: |
mkdir -p .cert
touch .cert/privkey.pem
touch .cert/cert.pem
touch .cert/chain.pem

- name: Install Dependencies
run: npm install

- name: Build
run: npm run build

- name: Lint
run: npm run lint

- name: Check Formatting
run: npm run format
27 changes: 11 additions & 16 deletions frontend/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,36 +1,31 @@
module.exports = {
env: {
browser: true,
es2021: true
es2021: true,
},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react/recommended'
'plugin:react/recommended',
],
overrides: [
{
env: {
node: true
node: true,
},
files: [
'.eslintrc.{js,cjs}'
],
files: ['.eslintrc.{js,cjs}'],
parserOptions: {
'sourceType': 'script'
}
}
sourceType: 'script',
},
},
],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module'
sourceType: 'module',
},
plugins: [
'@typescript-eslint',
'react'
],
plugins: ['@typescript-eslint', 'react'],
rules: {
'react/react-in-jsx-scope': 0,
}
};
},
}
5 changes: 5 additions & 0 deletions frontend/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"singleQuote": true,
"trailingComma": "all",
"semi": false
}
6 changes: 3 additions & 3 deletions frontend/index.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta name="theme-color" content="#000000"/>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<title>ITMO Dating</title>
</head>
<body>
Expand Down
2 changes: 2 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
"build": "tsc --noEmit && vite build",
"lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"lint:fix": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0 --fix",
"format": "npx prettier --check .",
"format:fix": "npx prettier --write --check . ",
"preview": "vite preview",
"predeploy": "npm run build"
},
Expand Down
51 changes: 24 additions & 27 deletions frontend/src/app/index.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
import {useEffect} from "react";
import {router} from "./routes/api";
import {RouterProvider} from "atomic-router-react";
import { useEffect } from 'react'
import { router } from './routes/api'
import { RouterProvider } from 'atomic-router-react'

import {$errorStore} from "@/shared/api";
import {message} from "antd";
import {Routes} from "@/app/routes/ui";

import {init, mockTgEnv} from './telegram-sdk';
import {retrieveLaunchParams} from '@telegram-apps/sdk';
import { $errorStore } from '@/shared/api'
import { message } from 'antd'
import { Routes } from '@/app/routes/ui'

import { init, mockTgEnv } from './telegram-sdk'
import { retrieveLaunchParams } from '@telegram-apps/sdk'

export const App = () => {
mockTgEnv()
.then(() => {
init(retrieveLaunchParams().startParam === 'debug' || import.meta.env.DEV);
})
mockTgEnv().then(() => {
init(retrieveLaunchParams().startParam === 'debug' || import.meta.env.DEV)
})

const [messageApi, contextHolder] = message.useMessage();
useEffect(() => {
$errorStore.watch(state => {
if (state)
messageApi.error(state?.message)
})
}, [])
const [messageApi, contextHolder] = message.useMessage()
useEffect(() => {
$errorStore.watch((state) => {
if (state) messageApi.error(state?.message)
})
}, [])

return (
<RouterProvider router={router}>
{contextHolder}
<Routes/>
</RouterProvider>
);
};
return (
<RouterProvider router={router}>
{contextHolder}
<Routes />
</RouterProvider>
)
}
2 changes: 1 addition & 1 deletion frontend/src/app/routes/api/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export {routes, routesMap, router} from "./routing.ts"
export { routes, routesMap, router } from './routing.ts'
28 changes: 14 additions & 14 deletions frontend/src/app/routes/api/routing.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { createHistoryRouter, createRoute } from "atomic-router";
import { createBrowserHistory } from "history";
import { createHistoryRouter, createRoute } from 'atomic-router'
import { createBrowserHistory } from 'history'

const basePath = "/itmo-dating-mini-app"
const basePath = '/itmo-dating-mini-app'
export const routes = {
home: createRoute(),
registration: createRoute(),
main: createRoute()
};
home: createRoute(),
registration: createRoute(),
main: createRoute(),
}

export const routesMap = [
{ path: "", route: routes.home },
{ path: "/registration", route: routes.registration},
{ path: "/main", route: routes.main},
];
{ path: '', route: routes.home },
{ path: '/registration', route: routes.registration },
{ path: '/main', route: routes.main },
]

const history = createBrowserHistory();
const history = createBrowserHistory()

export const router = createHistoryRouter({ base: basePath, routes: routesMap });
export const router = createHistoryRouter({ base: basePath, routes: routesMap })

router.setHistory(history);
router.setHistory(history)
18 changes: 9 additions & 9 deletions frontend/src/app/routes/ui/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {Route} from "atomic-router-react";
import {routes} from "../api";
import {Registration, Home, Main} from "@/pages";
import { Route } from 'atomic-router-react'
import { routes } from '../api'
import { Registration, Home, Main } from '@/pages'

export const Routes = () => (
<>
<Route route={routes.home} view={Home}/>
<Route route={routes.registration} view={Registration}/>
<Route route={routes.main} view={Main}/>
</>
);
<>
<Route route={routes.home} view={Home} />
<Route route={routes.registration} view={Registration} />
<Route route={routes.main} view={Main} />
</>
)
4 changes: 2 additions & 2 deletions frontend/src/app/telegram-sdk/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export {init} from "./init.ts"
export { init } from './init.ts'

export {mockTgEnv} from "./mockEnv.ts"
export { mockTgEnv } from './mockEnv.ts'
81 changes: 40 additions & 41 deletions frontend/src/app/telegram-sdk/api/init.ts
Original file line number Diff line number Diff line change
@@ -1,53 +1,52 @@
import {
backButton,
viewport,
themeParams,
miniApp,
initData,
$debug,
init as initSDK,
} from '@telegram-apps/sdk';
import {mountMainButton} from "@/entities/main-button";
import {mountBackButton} from "@/entities/back-button";
backButton,
viewport,
themeParams,
miniApp,
initData,
$debug,
init as initSDK,
} from '@telegram-apps/sdk'
import { mountMainButton } from '@/entities/main-button'
import { mountBackButton } from '@/entities/back-button'

/**
* Initializes the application and configures its dependencies.
*/
export function init(debug: boolean): void {
// Set @telegram-apps/sdk-react debug mode.
$debug.set(debug);
// Set @telegram-apps/sdk-react debug mode.
$debug.set(debug)

// Initialize special event handlers for Telegram Desktop, Android, iOS, etc.
// Also, configure the package.
initSDK();
// Initialize special event handlers for Telegram Desktop, Android, iOS, etc.
// Also, configure the package.
initSDK()

// Add Eruda if needed.
debug && import('eruda')
.then((lib) => lib.default.init())
.catch(console.error);
// Add Eruda if needed.
debug &&
import('eruda').then((lib) => lib.default.init()).catch(console.error)

// Check if all required components are supported.
if (!backButton.isSupported() || !miniApp.isSupported()) {
throw new Error('ERR_NOT_SUPPORTED');
}
// Check if all required components are supported.
if (!backButton.isSupported() || !miniApp.isSupported()) {
throw new Error('ERR_NOT_SUPPORTED')
}

// Mount all components used in the project.
mountMainButton()
mountBackButton()
// Mount all components used in the project.
mountMainButton()
mountBackButton()

miniApp.mount();
themeParams.mount();
initData.restore();
void viewport
.mount()
.catch(e => {
console.error('Something went wrong mounting the viewport', e);
})
.then(() => {
viewport.bindCssVars();
});
miniApp.mount()
themeParams.mount()
initData.restore()
void viewport
.mount()
.catch((e) => {
console.error('Something went wrong mounting the viewport', e)
})
.then(() => {
viewport.bindCssVars()
})

// Define components-related CSS variables.
miniApp.bindCssVars();
themeParams.bindCssVars();
}
// Define components-related CSS variables.
miniApp.bindCssVars()
themeParams.bindCssVars()
}
Loading
Loading