some cra template work

This commit is contained in:
Chen Asraf
2022-09-02 03:48:39 +03:00
parent a2c13162a5
commit 6758767012
83 changed files with 9584 additions and 4829 deletions

View File

@@ -1,5 +1,7 @@
# .dotfiles
## How to install
1. Install [Oh-My-Zsh](https://github.com/ohmyzsh/ohmyzsh)
2. Clone this repository into `~/.dotfiles`:
@@ -19,3 +21,7 @@
home install
home reload
```
## TO DO
- [ ] Make next template incremental (`yarn create next-app` + copy rest of tpl)

View File

@@ -1,7 +1,7 @@
import React from 'react'
import Box, { BoxProps } from '@mui/material/Box'
import { sxc } from '../nextjs/core/utils/object_utils'
import { CustomComponent } from '../nextjs/core/types'
import { sxc } from 'core/utils/object_utils'
import { CustomComponent } from 'core/types'
export interface {{pascalCase name}}Props extends CustomComponent<BoxProps> {
//

View File

@@ -0,0 +1,42 @@
{
"version": "0.1.0",
"scripts": {
"gen:page": "npx -y simple-scaffold@latest -t scaffolds/page -s false -o pages ",
"gen:component": "npx -y simple-scaffold@latest -t scaffolds/component -s false -o components/atoms"
},
"dependencies": {
"@emotion/cache": "^11.9.3",
"@emotion/react": "^11.9.3",
"@emotion/server": "^11.4.0",
"@emotion/styled": "^11.9.3",
"@mui/icons-material": "^5.8.4",
"@mui/material": "^5.9.2",
"axios": "^0.27.2",
"lodash": "^4.17.21",
"mapbox-gl": "^2.9.2",
"mobx": "^6.6.1",
"mobx-react-lite": "^3.4.0",
"react-i18next": "^11.3.0",
"node-fetch": "^3.2.10",
"react-hook-form": "^7.34.0",
"react-query": "^3.39.2",
"react-use": "^17.4.0",
"stylis": "^4.1.1",
"stylis-plugin-rtl": "^2.1.1"
},
"devDependencies": {
"@types/lodash": "^4.14.182",
"@types/mapbox-gl": "^2.7.5",
"@types/node": "18.6.2",
"@types/stylis": "^4.0.2",
"@typescript-eslint/eslint-plugin": "^5.34.0",
"@typescript-eslint/parser": "^5.34.0",
"css-loader": "^6.7.1",
"csv-parse": "^5.3.0",
"eslint": "8.20.0",
"eslint-config-next": "12.2.3",
"style-loader": "^3.3.1",
"ts-node": "^10.9.1",
"typescript": "4.7.4"
}
}

View File

@@ -0,0 +1,25 @@
import React from 'react'
import { useHistory } from 'react-router-dom'
import { useTranslation } from 'react-i18next'
import Box from '@mui/material/Box'
import { PageWrapper } from 'components/atoms/PageWrapper'
// NOTE
// This page mights need to be SSRed using `getStaticProps`. If that's the case,
// we will need to use `getStaticPaths` to generate the routes.
export const {{pascalCase name}}: React.FC = () => {
const router = useHistory()
const params = router.query
const { t } = useTranslation('{{snakeCase name}}')
return (
<PageWrapper pageTitle="{{ startCase name }}">
<Box>
{{ pascalCase name }} Page
</Box>
</PageWrapper>
)
}
export default {{pascalCase name}}

View File

@@ -0,0 +1,12 @@
import React from 'react'
import Box, { BoxProps } from '@mui/material/Box'
import { sxc } from 'core/utils/object_utils'
import { CustomComponent } from 'core/types'
export interface {{pascalCase name}}Props extends CustomComponent<BoxProps> {
//
}
export const {{pascalCase name}}: React.FC<{{pascalCase name}}Props> = ({ sx, children }) => {
return <Box sx={sxc({}, sx)}>{children}</Box>
}

View File

@@ -1,13 +1,6 @@
{
"name": "{{ hyphenCase name }}",
"version": "0.1.0",
"private": true,
"license": "UNLICENSED",
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint",
"gen:page": "npx -y simple-scaffold@latest -t scaffolds/page -s false -o pages ",
"gen:component": "npx -y simple-scaffold@latest -t scaffolds/component -s false -o components/atoms",
"build:docker": "docker build -t nextjs-docker .",
@@ -25,17 +18,12 @@
"mapbox-gl": "^2.9.2",
"mobx": "^6.6.1",
"mobx-react-lite": "^3.4.0",
"next": "12.2.3",
"next-i18next": "^11.3.0",
"next-images": "^1.8.4",
"next-transpile-modules": "^9.0.0",
"node-fetch": "^3.2.10",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-facebook-login": "^4.1.1",
"react-hook-form": "^7.34.0",
"react-query": "^3.39.2",
"react-responsive-carousel": "^3.2.23",
"react-use": "^17.4.0",
"stylis": "^4.1.1",
"stylis-plugin-rtl": "^2.1.1"
@@ -44,9 +32,6 @@
"@types/lodash": "^4.14.182",
"@types/mapbox-gl": "^2.7.5",
"@types/node": "18.6.2",
"@types/react": "18.0.15",
"@types/react-dom": "18.0.6",
"@types/react-facebook-login": "^4.1.5",
"@types/stylis": "^4.0.2",
"@typescript-eslint/eslint-plugin": "^5.34.0",
"@typescript-eslint/parser": "^5.34.0",

View File

@@ -1,10 +1,10 @@
import React from 'react'
import { NextPage, NextPageContext } from 'next'
import { useRouter } from 'next/router'
import { getI18nProps } from '../../core/i18n'
import { getI18nProps } from 'core/i18n'
import { useTranslation } from 'next-i18next'
import Box from '@mui/material/Box'
import { PageWrapper } from '../../components/atoms/PageWrapper'
import { PageWrapper } from 'components/atoms/PageWrapper'
// NOTE
// This page mights need to be SSRed using `getStaticProps`. If that's the case,

View File

@@ -8,31 +8,16 @@
# testing
/coverage
# next.js
/.next/
/out/
# production
/build
# misc
.DS_Store
*.pem
.env.local
.env.development.local
.env.test.local
.env.production.local
# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*
# local env files
.env*.local
# vercel
.vercel
# typescript
*.tsbuildinfo
# swagger definitions
/swagger.*

46
scaffolds/cra/README.md Normal file
View File

@@ -0,0 +1,46 @@
# Getting Started with Create React App
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
## Available Scripts
In the project directory, you can run:
### `yarn start`
Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
The page will reload if you make edits.\
You will also see any lint errors in the console.
### `yarn test`
Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
### `yarn build`
Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.
The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
### `yarn eject`
**Note: this is a one-way operation. Once you `eject`, you cant go back!**
If you arent satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point youre on your own.
You dont have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldnt feel obligated to use this feature. However we understand that this tool wouldnt be useful if you couldnt customize it when you are ready for it.
## Learn More
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
To learn React, check out the [React documentation](https://reactjs.org/).

View File

@@ -0,0 +1,43 @@
{
"name": "{{ hyphenCase name }}",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^13.0.0",
"@testing-library/user-event": "^13.2.1",
"@types/jest": "^27.0.1",
"@types/node": "^16.7.13",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"typescript": "^4.4.2",
"web-vitals": "^2.1.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

View File

@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

View File

@@ -0,0 +1,25 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}

View File

@@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:

View File

@@ -0,0 +1,9 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import App from './App';
test('renders learn react link', () => {
render(<App />);
const linkElement = screen.getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
});

View File

@@ -0,0 +1,55 @@
import React from 'react'
import Box from '@material-ui/core/Box'
import Image from '@material-ui/core/Image'
import Typography from '@material-ui/core/Typography'
import Link from '@material-ui/core/Link'
import logo from './logo.svg'
function App() {
return (
<Box sx={{ textAlign: 'center' }}>
<Box
component="header"
sx={{
backgroundColor: "#282c34",
minHeight: "100vh",
display: "flex",
flexDirection: "column",
alignItems: "center",
justifyContent: "center",
fontSize: "calc(10px + 2vmin)",
color: "white",
}}>
<Image
src={logo}
alt="logo"
sx={{
height: "40vmin",
pointerEvents: "none",
animation: "App-logo-spin infinite 20s linear",
"@keyframes App-logo-spin": {
from: {
transform: "rotate(0deg)",
},
to: {
transform: "rotate(360deg)",
}
}
}} />
<Typography>
Edit <code>src/App.tsx</code> and save to reload.
</Typography>
<Link
sx={{ color: "#61dafb" }}
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</Link>
</Box>
</Box>
)
}
export default App

View File

@@ -0,0 +1,64 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import CssBaseline from '@mui/material/CssBaseline'
import ThemeProvider from '@mui/material/styles/ThemeProvider'
import { lightTheme, themeDir } from 'theme'
import { useTranslation } from 'react-i18next'
import { QueryClientProvider, QueryClient } from 'react-query'
import { useSilentLoginFlow } from 'stores/user_store'
import reportWebVitals from './reportWebVitals'
import App from './App'
let windowInit = false
const _{{ pascalCase name }}App: React.FC = () => {
const queryClient = new QueryClient({
defaultOptions: {
queries: {
staleTime: Infinity,
refetchOnMount: false,
refetchOnReconnect: false,
refetchOnWindowFocus: false,
},
},
})
const { i18n } = useTranslation()
const themeWithDirection = React.useMemo(
() => themeDir(lightTheme, i18n.dir(i18n.language)),
[i18n],
)
const silentLogin = useSilentLoginFlow()
React.useEffect(() => {
if (!windowInit && typeof window !== 'undefined') {
windowInit = true
silentLogin()
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [typeof window])
return (
<QueryClientProvider client={queryClient}>
<ThemeProvider theme={themeWithDirection}>
<CssBaseline />
<App />
</ThemeProvider>
</QueryClientProvider>
)
}
const root = ReactDOM.createRoot(
document.getElementById('root') as HTMLElement
)
root.render(
<React.StrictMode>
<_{{ pascalCase name }}App />
</React.StrictMode>
)
// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 841.9 595.3"><g fill="#61DAFB"><path d="M666.3 296.5c0-32.5-40.7-63.3-103.1-82.4 14.4-63.6 8-114.2-20.2-130.4-6.5-3.8-14.1-5.6-22.4-5.6v22.3c4.6 0 8.3.9 11.4 2.6 13.6 7.8 19.5 37.5 14.9 75.7-1.1 9.4-2.9 19.3-5.1 29.4-19.6-4.8-41-8.5-63.5-10.9-13.5-18.5-27.5-35.3-41.6-50 32.6-30.3 63.2-46.9 84-46.9V78c-27.5 0-63.5 19.6-99.9 53.6-36.4-33.8-72.4-53.2-99.9-53.2v22.3c20.7 0 51.4 16.5 84 46.6-14 14.7-28 31.4-41.3 49.9-22.6 2.4-44 6.1-63.6 11-2.3-10-4-19.7-5.2-29-4.7-38.2 1.1-67.9 14.6-75.8 3-1.8 6.9-2.6 11.5-2.6V78.5c-8.4 0-16 1.8-22.6 5.6-28.1 16.2-34.4 66.7-19.9 130.1-62.2 19.2-102.7 49.9-102.7 82.3 0 32.5 40.7 63.3 103.1 82.4-14.4 63.6-8 114.2 20.2 130.4 6.5 3.8 14.1 5.6 22.5 5.6 27.5 0 63.5-19.6 99.9-53.6 36.4 33.8 72.4 53.2 99.9 53.2 8.4 0 16-1.8 22.6-5.6 28.1-16.2 34.4-66.7 19.9-130.1 62-19.1 102.5-49.9 102.5-82.3zm-130.2-66.7c-3.7 12.9-8.3 26.2-13.5 39.5-4.1-8-8.4-16-13.1-24-4.6-8-9.5-15.8-14.4-23.4 14.2 2.1 27.9 4.7 41 7.9zm-45.8 106.5c-7.8 13.5-15.8 26.3-24.1 38.2-14.9 1.3-30 2-45.2 2-15.1 0-30.2-.7-45-1.9-8.3-11.9-16.4-24.6-24.2-38-7.6-13.1-14.5-26.4-20.8-39.8 6.2-13.4 13.2-26.8 20.7-39.9 7.8-13.5 15.8-26.3 24.1-38.2 14.9-1.3 30-2 45.2-2 15.1 0 30.2.7 45 1.9 8.3 11.9 16.4 24.6 24.2 38 7.6 13.1 14.5 26.4 20.8 39.8-6.3 13.4-13.2 26.8-20.7 39.9zm32.3-13c5.4 13.4 10 26.8 13.8 39.8-13.1 3.2-26.9 5.9-41.2 8 4.9-7.7 9.8-15.6 14.4-23.7 4.6-8 8.9-16.1 13-24.1zM421.2 430c-9.3-9.6-18.6-20.3-27.8-32 9 .4 18.2.7 27.5.7 9.4 0 18.7-.2 27.8-.7-9 11.7-18.3 22.4-27.5 32zm-74.4-58.9c-14.2-2.1-27.9-4.7-41-7.9 3.7-12.9 8.3-26.2 13.5-39.5 4.1 8 8.4 16 13.1 24 4.7 8 9.5 15.8 14.4 23.4zM420.7 163c9.3 9.6 18.6 20.3 27.8 32-9-.4-18.2-.7-27.5-.7-9.4 0-18.7.2-27.8.7 9-11.7 18.3-22.4 27.5-32zm-74 58.9c-4.9 7.7-9.8 15.6-14.4 23.7-4.6 8-8.9 16-13 24-5.4-13.4-10-26.8-13.8-39.8 13.1-3.1 26.9-5.8 41.2-7.9zm-90.5 125.2c-35.4-15.1-58.3-34.9-58.3-50.6 0-15.7 22.9-35.6 58.3-50.6 8.6-3.7 18-7 27.7-10.1 5.7 19.6 13.2 40 22.5 60.9-9.2 20.8-16.6 41.1-22.2 60.6-9.9-3.1-19.3-6.5-28-10.2zM310 490c-13.6-7.8-19.5-37.5-14.9-75.7 1.1-9.4 2.9-19.3 5.1-29.4 19.6 4.8 41 8.5 63.5 10.9 13.5 18.5 27.5 35.3 41.6 50-32.6 30.3-63.2 46.9-84 46.9-4.5-.1-8.3-1-11.3-2.7zm237.2-76.2c4.7 38.2-1.1 67.9-14.6 75.8-3 1.8-6.9 2.6-11.5 2.6-20.7 0-51.4-16.5-84-46.6 14-14.7 28-31.4 41.3-49.9 22.6-2.4 44-6.1 63.6-11 2.3 10.1 4.1 19.8 5.2 29.1zm38.5-66.7c-8.6 3.7-18 7-27.7 10.1-5.7-19.6-13.2-40-22.5-60.9 9.2-20.8 16.6-41.1 22.2-60.6 9.9 3.1 19.3 6.5 28.1 10.2 35.4 15.1 58.3 34.9 58.3 50.6-.1 15.7-23 35.6-58.4 50.6zM320.8 78.4z"/><circle cx="420.9" cy="296.5" r="45.7"/><path d="M520.5 78.1z"/></g></svg>

After

Width:  |  Height:  |  Size: 2.6 KiB

1
scaffolds/cra/src/react-app-env.d.ts vendored Normal file
View File

@@ -0,0 +1 @@
/// <reference types="react-scripts" />

View File

@@ -0,0 +1,15 @@
import { ReportHandler } from 'web-vitals';
const reportWebVitals = (onPerfEntry?: ReportHandler) => {
if (onPerfEntry && onPerfEntry instanceof Function) {
import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
getCLS(onPerfEntry);
getFID(onPerfEntry);
getFCP(onPerfEntry);
getLCP(onPerfEntry);
getTTFB(onPerfEntry);
});
}
};
export default reportWebVitals;

View File

@@ -0,0 +1,5 @@
// jest-dom adds custom jest matchers for asserting on DOM nodes.
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom';

View File

@@ -0,0 +1,39 @@
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",
"baseUrl": "./src/",
},
"ts-node": {
"compilerOptions": {
"module": "commonjs"
}
},
"include": [
"src",
"mui.d.ts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules",
"templates/**/*"
]
}

9050
scaffolds/cra/yarn.lock Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,8 +0,0 @@
[*]
tab_width = 2
indent_size = 2
indent_style = space
insert_final_newline = true
[*.md]
trim_trailing_whitespace = false

View File

@@ -1 +0,0 @@
templates/**/*

View File

@@ -1,9 +0,0 @@
module.exports = {
extends: ['next/core-web-vitals', 'plugin:@typescript-eslint/recommended'],
rules: {
'no-console': ['warn', { allow: ['warn', 'error'] }],
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': ['warn', { varsIgnorePattern: '^_' }],
'@typescript-eslint/no-non-null-assertion': 'off',
},
}

View File

@@ -17,12 +17,7 @@ static serving.
2. Add `.env.local` file to the repository root folder, and fill it with the correct env variables:
```shell
NEXT_PUBLIC_API_BASE=
NEXT_PUBLIC_MAPBOX_API_KEY=
NEXT_PUBLIC_FACEBOOK_APP_ID=
# to use test social app login instead of prod one in backend
# (optional, automatically true in dev mode)
# NEXT_PUBLIC_API_TEST=true
ENV_VAR=
```
3. Run in development mode with hot reload: `yarn dev`

View File

@@ -1,54 +0,0 @@
import React from 'react'
import flatsApi from '../../core/api/flats.api'
import { Flat } from '../../core/models/flats'
import { createUseApi } from '../../core/utils/react_utils'
export const useMyFlat = createUseApi(() => flatsApi.getMyFlat(), {
cacheKey: 'myFlat',
responseKey: 'flat',
})
export const usePotentialFlats = createUseApi(() => flatsApi.getPotentialFlatsList(), {
cacheKey: 'potentialFlats',
responseKey: 'potentialFlats',
innerKey: 'flat',
})
export const useMatchedFlats = createUseApi(() => flatsApi.getMatchedFlatsList(), {
cacheKey: 'matchedFlats',
responseKey: 'fullMatches',
innerKey: 'matchesByUser',
})
export const useLikedFlats = createUseApi(() => flatsApi.getLikedFlatsList(), {
cacheKey: 'likedFlats',
responseKey: 'likedFlats',
innerKey: 'flat',
})
export const useDislikedFlats = createUseApi(() => flatsApi.getDislikedFlatsList(), {
cacheKey: 'dislikedFlats',
responseKey: 'dislikedFlats',
innerKey: 'flat',
})
export function useFlatCache(list: Flat[] | undefined) {
const [cache, setCache] = React.useState<Flat[]>(list ?? [])
React.useEffect(() => {
setCache(list ?? [])
}, [list])
return {
data: cache,
add: (item: Flat) => {
setCache([...cache, item])
},
update: (item: Flat) => {
setCache(cache.map((flat) => (flat.userId === item.userId ? item : flat)))
},
remove: (item: Flat) => {
setCache(cache.filter((flat) => flat.userId !== item.userId))
},
}
}

View File

@@ -1,10 +0,0 @@
import notificationsApi from '../../core/api/notifications.api'
import { Notification } from '../../core/models/notification'
import { createUseApi } from '../../core/utils/react_utils'
const getId = (notification: Notification) => notification.userId
export const useNotifications = createUseApi(() => notificationsApi.getNotifications(), {
cacheKey: 'notifications',
responseKey: 'notifications',
})

View File

@@ -1,21 +0,0 @@
import placesApi, { GetPlacesListResult } from '../../core/api/places.api'
import uniqBy from 'lodash/uniqBy'
import React from 'react'
import { createUseApi, RequiredQueryOptions } from '../../core/utils/react_utils'
export const usePlaces = createUseApi(() => placesApi.getPlacesList(), {
cacheKey: 'places',
responseKey: 'places',
})
export function useCities(options?: RequiredQueryOptions<GetPlacesListResult>) {
const { places = [], ...rest } = usePlaces(options)
const data = React.useMemo(() => uniqBy(places, 'city'), [places])
return { ...rest, cities: data }
}
export function useNeighborhoods(options?: RequiredQueryOptions<GetPlacesListResult>) {
const { places = [], ...rest } = usePlaces(options)
const data = React.useMemo(() => uniqBy(places, 'neighborhood'), [places])
return { ...rest, neighborhoods: data }
}

View File

@@ -1,7 +0,0 @@
import userPreferencesApi from '../../core/api/user_preferences.api'
import { createUseApi } from '../../core/utils/react_utils'
export const useUserPreferences = createUseApi(() => userPreferencesApi.getUserPreferences(), {
cacheKey: 'userPreferences',
responseKey: 'userPreference',
})

View File

@@ -1,13 +0,0 @@
export type SingleResult<T, K extends string> = {
[result in K]: T
} & {
error: boolean
msg: string
}
export type ListResult<T, K extends string> = {
[result in K]?: T[]
} & {
count: number
error: boolean
msg: string
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +0,0 @@
export const ENV = {
BROWSER_LOADED: typeof window !== 'undefined',
API_BASE: process.env.NEXT_PUBLIC_API_BASE!,
API_TEST: process.env.NODE_ENV === 'development' || process.env.NEXT_PUBLIC_API_TEST === 'true',
MAPBOX_API_KEY: process.env.NEXT_PUBLIC_MAPBOX_API_KEY!,
FACEBOOK_APP_ID: process.env.NEXT_PUBLIC_FACEBOOK_APP_ID!,
}

View File

@@ -1,111 +0,0 @@
import { alpha } from '@mui/material/styles'
import createTheme, { Theme } from '@mui/material/styles/createTheme'
const colors = {
primary: '#638DB3',
link: '#0066FF',
primaryGradientTop: '#7EACD6',
primaryGradientBottom: '#6089AF',
disabledBackground: '#bdbdbd',
disabled: '#DCDCDC',
}
const shadows = {
input: `0 2px 10px ${alpha('#000000', 0.25)}`,
card: `0 1px 9px ${alpha('#000000', 0.25)}`,
likedCard: `0 1px 9px 1px ${alpha('#0FA639', 0.5)}`,
dislikedCard: `0 1px 9px 1px ${alpha('#E22F29', 0.5)}`,
mutualCard: `0 1px 9px 1px ${alpha('#0C77DF', 0.5)}`,
matchButton: `0 2px 9px 0 ${alpha('#000000', 0.25)}`,
avatar: `0 4px 11px ${alpha('#000000', 0.38)}`,
}
export const lightTheme = createTheme({
boxShadows: shadows,
typography: {
fontFamily: 'Assistant, Roboto, Helvetica, sans-serif',
},
palette: {
mode: 'light',
primary: {
main: colors.primary,
},
link: {
main: colors.link,
},
disabled: {
main: colors.disabled,
},
disabledBackground: {
main: colors.disabledBackground,
},
},
components: {
MuiLink: {
styleOverrides: {
root: {
color: colors.link,
textDecoration: 'none',
},
},
},
MuiButton: {
styleOverrides: {
root: {
fontSize: '24px',
fontWeight: 600,
borderRadius: '2em',
minWidth: '200',
'&.Mui-disabled': {
background: colors.disabledBackground,
},
},
containedPrimary: {
background: `linear-gradient(180deg, ${colors.primaryGradientTop}, ${colors.primaryGradientBottom})`,
},
},
},
MuiTextField: {
styleOverrides: {
root: {
fontSize: '20',
},
},
},
MuiInputBase: {
styleOverrides: {
multiline: {
borderRadius: '0 !important',
},
},
},
MuiSelect: {
defaultProps: {
variant: 'outlined',
},
},
MuiOutlinedInput: {
styleOverrides: {
root: {
borderRadius: '2em',
boxShadow: shadows.input,
outline: 'none',
},
notchedOutline: {
border: '0',
},
},
},
MuiTypography: {
styleOverrides: {
h5: {
fontSize: 22,
},
},
},
},
})
export function themeDir(theme: Theme, direction: 'ltr' | 'rtl'): Theme {
return { ...theme, direction }
}

View File

@@ -1,5 +0,0 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />
// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.

View File

@@ -1,8 +1,8 @@
module.exports = {
debug: process.env.NODE_ENV === 'development',
i18n: {
defaultLocale: 'he',
locales: ['he'],
defaultLocale: 'en',
locales: ['en'],
},
defaultNS: '{{ hyphenCase name }}',
reloadOnPrerender: process.env.NODE_ENV === 'development',

View File

@@ -1,20 +1,16 @@
import React from 'react'
import type { AppProps } from 'next/app'
import CssBaseline from '@mui/material/CssBaseline'
import ThemeProvider from '@mui/material/styles/ThemeProvider'
import { lightTheme, themeDir } from '../core/theme'
import { lightTheme, themeDir } from '../../common/core/theme'
import { CacheProvider, EmotionCache } from '@emotion/react'
import { createEmotionCache } from '../core/emotion'
import { createEmotionCache } from '../../common/core/emotion'
import { enableStaticRendering } from 'mobx-react-lite'
import { appWithTranslation, useTranslation } from 'next-i18next'
import nextI18nConfig from '../next-i18next.config'
import { QueryClientProvider, QueryClient } from 'react-query'
import React from 'react'
import 'mapbox-gl/dist/mapbox-gl.css'
import mapboxgl from 'mapbox-gl'
import { ENV } from '../core/env'
import { useSilentLoginFlow } from '../core/stores/user_store'
mapboxgl.accessToken = ENV.MAPBOX_API_KEY
import { ENV } from 'core/env'
import { useSilentLoginFlow } from 'core/stores/user_store'
export interface {{ pascalCase name }}AppProps extends AppProps {
emotionCache?: EmotionCache

View File

@@ -1,6 +1,6 @@
import * as React from 'react'
import Document, { Html, Head, Main, NextScript } from 'next/document'
import { createEmotionCache } from '../core/emotion'
import { createEmotionCache } from '../../common/core/emotion'
import createEmotionServer from '@emotion/server/create-instance'
export default class MyDocument extends Document {

View File

@@ -1,13 +0,0 @@
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import type { NextApiRequest, NextApiResponse } from 'next'
type Data = {
name: string
}
export default function handler(
req: NextApiRequest,
res: NextApiResponse<Data>
) {
res.status(200).json({ name: 'John Doe' })
}

View File

@@ -1,7 +1,7 @@
import React from 'react'
import type { NextPage } from 'next'
import Head from 'next/head'
import { Routes, usePushRoute } from '../core/routes'
import { Routes, usePushRoute } from '../../common/core/routes'
const Home: NextPage = () => {
const goTo = usePushRoute()

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

View File

@@ -1,77 +0,0 @@
{
"floor": "קומה",
"rooms": "חדרים",
"rooms_one": "חדר",
"rooms_other": "חדרים",
"sqm": "מ\"ר",
"city": "עיר",
"neighborhood": "שכונה",
"street": "רחוב",
"apt_number": "מספר דירה",
"apt_type": "סוג הדירה",
"freetext_placeholder": "הכנס תיאור של הנכס",
"apt_type_values": {
"apartment": "דירה",
"condo": "קונדורה",
"house": "בית",
"studio": "סטודיו",
"townhouse": "דירת עיר",
"villa": "בית וילה",
"penthouse": "פנטהאוס"
},
"price": "מחיר",
"extras": {
"parking": "חניה",
"elevator": "מעלית",
"balcony": "מרפסת",
"renovated": "משופץ",
"pets": "חיות",
"roommates": "שותפים",
"handicappedAccessibility": "גישה לנכים",
"furnished": "מרוהטת",
"secureRoom": "ממ\"ד"
},
"my": {
"title": "פרטי הדירה שלי",
"extras_title": "מה עוד יש לדירה להציע",
"photos_title": "העלו עד 6 תמונות",
"description_title": "ספר לנו על הדירה שלך",
"next": "הבא",
"save": "שמור",
"required_error": "שדה חובה"
},
"view": {
"freetext_title": "תיאור הנכס"
},
"view_switcher": {
"card": "הצג ככרטיסיות",
"list": "הצג כרשימה"
},
"matched": {
"title": "התאמות"
},
"potential": {
"title": "תוצאות"
},
"liked": {
"title": "דירות שאהבתי"
},
"disliked": {
"title": "דירות שלא אהבתי"
},
"search_preferences": {
"title": "מה אני מחפש/ת",
"neighborhoods": "שכונות",
"selected_neighborhoods": "שכונות שנבחרו",
"property_types": "סוגי הדירה",
"selected_property_types": "סוגי הדירה שנבחרו",
"minPrice": "מחיר מינימלי",
"maxPrice": "מחיר מקסימלי",
"minRooms": "מס' חדרים מינימלי",
"maxRooms": "מס' חדרים מקסימלי",
"minSqm": "מגודל (מ\"ר)",
"maxSqm": "עד גודל (מ\"ר)",
"minFloor": "מקומה",
"maxFloor": "עד קומה"
}
}

View File

@@ -1,11 +0,0 @@
{
"app_bar": {
"menu": {
"results": "תוצאות",
"matches": "התאמות",
"liked": "דירות שאהבתי",
"disliked": "דירות שלא אהבתי",
"profile": "פרופיל"
}
}
}

View File

@@ -1,8 +0,0 @@
{
"title": "הפרופיל שלי",
"buttons": {
"details": "פרטים אישיים",
"search_preferences": "העדפות חיפוש",
"my_apt_details": "פרטי הדירה שלי"
}
}

View File

@@ -1,27 +0,0 @@
{
"select_login": {
"title": "קליק אחד ואת/ה בפנים",
"subtitle": "אנחנו כבר נדאג לכל השאר...",
"accept_terms": "בהצטרפותי אני מסכים ל<a>תנאי השימוש</a>",
"buttons": {
"facebook": "המשך עם פייסבוק",
"google": "המשך עם גוגל"
}
},
"user_details": {
"title": "פרטים אישיים",
"signup_title": "היי, איזה כיף שאת/ה פה",
"subtitle": "כמה פרטים קטנים ונתחיל לחפש לך את הדירה הבאה שלך...",
"accept_updates": "אני מעוניין לקבל עדכונים על דירות רלוונטיות והתאמות חדשות באמצעות הדואר האלקטרוני",
"submit": "הרשמה",
"save": "שמור שינויים",
"inputs": {
"first_name": "שם פרטי",
"last_name": "שם משפחה",
"phone": "טלפון",
"email": "כתובת מייל",
"required_error": "שדה חובה",
"phone_error": "לפחות 9 ספרות"
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,9 +1,9 @@
import React from 'react'
import Box, { BoxProps } from '@mui/material/Box'
import { sxc } from '../../core/utils/object_utils'
import { CustomComponent } from '../../core/types'
import Image from 'next/image'
import { apiFallbackImageUrl } from '../../core/utils/image_utils'
import { sxc } from 'core/utils/object_utils'
import { CustomComponent } from 'core/types'
import Image from '{{ imageImport }}'
import { apiFallbackImageUrl } from 'core/utils/image_utils'
export interface AvatarProps extends CustomComponent<BoxProps> {
src: string
@@ -27,12 +27,12 @@ export const Avatar: React.FC<AvatarProps> = ({ sx, size = 160, src, padding = 8
)}
>
<Box
sx={{
sx={ {
width: size - padding * 2,
height: size - padding * 2,
borderRadius: '50%',
overflow: 'hidden',
}}
} }
>
<Image
src={apiFallbackImageUrl(src)}

View File

@@ -2,8 +2,8 @@ import Autocomplete, { AutocompleteProps } from '@mui/material/Autocomplete'
import TextField from '@mui/material/TextField'
import React from 'react'
import { Controller, Control, Path } from 'react-hook-form'
import { CustomComponent, Option } from '../../core/types'
import { optionFrom } from '../../core/utils/object_utils'
import { CustomComponent, Option } from 'core/types'
import { optionFrom } from 'core/utils/object_utils'
export interface ControlledAutocompleteProps<T, K extends Path<T>, Multiple extends boolean = false>
extends CustomComponent<Partial<AutocompleteProps<Option, Multiple, false, false>>> {
@@ -45,7 +45,7 @@ export const ControlledAutocomplete = <T, K extends Path<T>, Multiple extends bo
<Controller<T, K>
control={control}
name={name}
rules={{ required: props.required }}
rules={ { required: props.required } }
render={({ field, formState: { errors } }) => (
<Autocomplete
onChange={(e, d, r) => {

View File

@@ -2,8 +2,8 @@ import Select, { SelectProps } from '@mui/material/Select'
import MenuItem from '@mui/material/MenuItem'
import React from 'react'
import { Controller, Control, Path } from 'react-hook-form'
import { CustomComponent, Option } from '../../core/types'
import { useRerender } from '../../core/utils/react_utils'
import { CustomComponent, Option } from 'core/types'
import { useRerender } from 'core/utils/react_utils'
export interface ControlledSelectProps<
R extends string,
@@ -62,7 +62,7 @@ export const ControlledSelect = <
<Controller<T, K>
control={control}
name={name}
rules={{ required: props.required }}
rules={ { required: props.required } }
render={({ field, formState: { errors } }) => (
<Select
onChange={(e, d) => {

View File

@@ -6,7 +6,7 @@ import AppBar from '@mui/material/AppBar'
import React from 'react'
import IconButton from '@mui/material/IconButton'
import Box from '@mui/material/Box'
import { Routes, usePushRoute } from '../../core/routes'
import { Routes, usePushRoute } from 'routes'
import { useTranslation } from 'next-i18next'
import Menu from '@mui/material/Menu'
import MenuItem from '@mui/material/MenuItem'
@@ -29,7 +29,7 @@ export const MainAppBar: React.FC = React.memo(function MainAppBar() {
return (
<>
<AppBar color="inherit">
<Toolbar sx={{ height: `${TOOLBAR_HEIGHT}px` }}>
<Toolbar sx={ { height: `${TOOLBAR_HEIGHT}px` } }>
<IconButton onClick={handleMenuClick} color="inherit">
<MenuIcon />
</IconButton>

View File

@@ -1,8 +1,8 @@
import React from 'react'
import Box, { BoxProps } from '@mui/material/Box'
import { CustomComponent } from '../../core/types'
import { CustomComponent } from 'core/types'
import CircularProgress from '@mui/material/CircularProgress'
import { TOOLBAR_HEIGHT } from '../layout/MainAppBar'
import { TOOLBAR_HEIGHT } from './MainAppBar'
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface PageLoaderProps extends CustomComponent<BoxProps> {

View File

@@ -1,8 +1,8 @@
import React from 'react'
import Box, { BoxProps } from '@mui/material/Box'
import { sxc } from '../../core/utils/object_utils'
import { CustomComponent } from '../../core/types'
import { MainAppBar, TOOLBAR_HEIGHT } from '../layout/MainAppBar'
import { sxc } from 'core/utils/object_utils'
import { CustomComponent } from 'core/types'
import { MainAppBar, TOOLBAR_HEIGHT } from './MainAppBar'
import Toolbar from '@mui/material/Toolbar'
import { PageLoader } from './PageLoader'
import Head from 'next/head'
@@ -50,7 +50,7 @@ export const PageWrapper: React.FC<PageWrapperProps> = (props) => {
{/* App Bar */}
<MainAppBar />
{/* Empty toolbar - to save space for fixed app bar */}
<Toolbar sx={{ height: `${TOOLBAR_HEIGHT}px` }} />
<Toolbar sx={ { height: `${TOOLBAR_HEIGHT}px` } } />
{pageTitle ? (
<Typography fontWeight={600} variant="h5">
{pageTitle}

View File

@@ -11,7 +11,7 @@ export function useNumberFormatter(options?: Intl.NumberFormatOptions): Intl.Num
export function useCurrencyFormatter(options?: Intl.NumberFormatOptions): Intl.NumberFormat {
return useNumberFormatter({
style: 'currency',
currency: 'ILS',
currency: 'USD',
...options,
})
}

View File

@@ -0,0 +1 @@
export {}

View File

@@ -0,0 +1,3 @@
export const ENV = {
IS_DEBUG: process.env.NODE_ENV === 'development',
}

View File

@@ -0,0 +1,32 @@
import { alpha } from '@mui/material/styles'
import createTheme, { Theme } from '@mui/material/styles/createTheme'
const colors = {
primary: '#000000',
}
const shadows = {
input: `0 2px 10px ${alpha('#000000', 0.25)}`,
card: `0 1px 9px ${alpha('#000000', 0.25)}`,
}
export const lightTheme = createTheme({
boxShadows: shadows,
typography: {
fontFamily: 'Roboto, Helvetica, sans-serif',
},
palette: {
mode: 'light',
},
components: {
MuiSelect: {
defaultProps: {
variant: 'outlined',
},
},
},
})
export function themeDir(theme: Theme, direction: 'ltr' | 'rtl'): Theme {
return { ...theme, direction }
}

View File

@@ -4,6 +4,7 @@ declare module '@mui/material/styles/createTheme' {
type Shadows =
| 'input'
| 'card'
| 'avatar'
interface ThemeOptions {
boxShadows: Record<Shadows, string>

View File

@@ -1,15 +0,0 @@
{
"printWidth": 100,
"semi": false,
"singleQuote": true,
"trailingComma": "all",
"overrides": [
{
"files": "*.md",
"options": {
"printWidth": 100,
"proseWrap": "always"
}
}
]
}

View File

@@ -1,20 +1,37 @@
SCAFFOLDS_DIR="$DOTFILES/scaffolds"
tpl() {
case $1 in
nextjs)
nextjs | cra)
tpl_name="$1"
tpl_data=""
shift
npx -y simple-scaffold@latest -t "$SCAFFOLDS_DIR/nextjs" -o . $@
echo_gray "Copying other scaffolds..."
case $tpl_name in
nextjs)
tpl_data='{"imageImport":"next/image"}'
yarn create next-app --typescript .
;;
cra)
tpl_data='{"imageImport":"@mui/material/Image"}'
yarn create react-app --template typescript .
yes | rm -rf ./src/
;;
esac
npx -y simple-scaffold@latest -t "$SCAFFOLDS_DIR/$tpl_name" -w 1 -o . -d $tpl_data $@
npx -y simple-scaffold@latest -t "$SCAFFOLDS_DIR/react-app-common" -w 1 -o ./src -d $tpl_data $@
echo_gray "Merging package.json..."
jq 'reduce inputs as $s (.; .*$s)' ./package.json $SCAFFOLDS_DIR/_subs/$tpl_name/package.json >./package.json
echo_gray "Copying sub scaffolds..."
mkdir -p ./scaffolds
cp -R $SCAFFOLDS_DIR/nextjs-* ./scaffolds/
cp -R $SCAFFOLDS_DIR/_subs/$tpl_name/ ./scaffolds/
yarn install
echo_gray "Done"
;;
tsfiles)
editorfiles)
shift
npx -y simple-scaffold@latest -t "$SCAFFOLDS_DIR/tsfiles" -o . - $@
npx -y simple-scaffold@latest -t "$SCAFFOLDS_DIR/editorfiles" -o . - $@
;;
*)
echo_red "Usage: tpl [nextjs|tsfiles]"
echo_red "Usage: tpl [nextjs|cra|editorfiles]"
;;
esac
}