Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 35431f57d9 | |||
| 8a15a26ff6 |
Generated
+30
-59
@@ -8,9 +8,9 @@
|
|||||||
"name": "store-client",
|
"name": "store-client",
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@tanstack/react-query": "^5.100.14",
|
||||||
"react": "^19.1.0",
|
"react": "^19.1.0",
|
||||||
"react-dom": "^19.1.0",
|
"react-dom": "^19.1.0"
|
||||||
"react-intl": "^10.1.13"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/js": "^9.25.0",
|
"@eslint/js": "^9.25.0",
|
||||||
@@ -899,38 +899,6 @@
|
|||||||
"node": "^18.18.0 || ^20.9.0 || >=21.1.0"
|
"node": "^18.18.0 || ^20.9.0 || >=21.1.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@formatjs/fast-memoize": {
|
|
||||||
"version": "3.1.6",
|
|
||||||
"resolved": "https://registry.npmjs.org/@formatjs/fast-memoize/-/fast-memoize-3.1.6.tgz",
|
|
||||||
"integrity": "sha512-H5aexk1Le7T9TPmscacZ+1pR6CTa2n1wq+HDVGXhH8TzUlQQpeXzZs91dRtmFHrbeNbjPFPfQujUqm7MHgVoXQ==",
|
|
||||||
"license": "MIT"
|
|
||||||
},
|
|
||||||
"node_modules/@formatjs/icu-messageformat-parser": {
|
|
||||||
"version": "3.5.11",
|
|
||||||
"resolved": "https://registry.npmjs.org/@formatjs/icu-messageformat-parser/-/icu-messageformat-parser-3.5.11.tgz",
|
|
||||||
"integrity": "sha512-NVsuNsc2dUVG9+4HBJ/srScxtA/18LqGgwtop/tuN/OIBjVl6QA+0KhfZQddDD9sEh2LeVjLFPGVU3ixa3blcA==",
|
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
|
||||||
"@formatjs/icu-skeleton-parser": "2.1.10"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@formatjs/icu-skeleton-parser": {
|
|
||||||
"version": "2.1.10",
|
|
||||||
"resolved": "https://registry.npmjs.org/@formatjs/icu-skeleton-parser/-/icu-skeleton-parser-2.1.10.tgz",
|
|
||||||
"integrity": "sha512-XuSva+8ZGawk8VnD5VD6UeH8KarQ/Z022zgjHDoHmlNiAewstXuuzXc0Hk5pGFSdG+nNw5bfJKXqj1ZXHn9yUA==",
|
|
||||||
"license": "MIT"
|
|
||||||
},
|
|
||||||
"node_modules/@formatjs/intl": {
|
|
||||||
"version": "4.1.13",
|
|
||||||
"resolved": "https://registry.npmjs.org/@formatjs/intl/-/intl-4.1.13.tgz",
|
|
||||||
"integrity": "sha512-dufOl09iREq8V+laVdlGuyoqNmuzqDvyeA3O3k+0XQfvKJgK8bBWFKqYYWejFMKeOij/4LuPKJA+LsshpXQ4sw==",
|
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
|
||||||
"@formatjs/fast-memoize": "3.1.6",
|
|
||||||
"@formatjs/icu-messageformat-parser": "3.5.11",
|
|
||||||
"intl-messageformat": "11.2.8"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@humanfs/core": {
|
"node_modules/@humanfs/core": {
|
||||||
"version": "0.19.1",
|
"version": "0.19.1",
|
||||||
"resolved": "https://registry.npmjs.org/@humanfs/core/-/core-0.19.1.tgz",
|
"resolved": "https://registry.npmjs.org/@humanfs/core/-/core-0.19.1.tgz",
|
||||||
@@ -1337,6 +1305,32 @@
|
|||||||
"win32"
|
"win32"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"node_modules/@tanstack/query-core": {
|
||||||
|
"version": "5.100.14",
|
||||||
|
"resolved": "https://registry.npmjs.org/@tanstack/query-core/-/query-core-5.100.14.tgz",
|
||||||
|
"integrity": "sha512-5X41dGpxgeaHISCRW2oYwcSycZeULZzAunaudXT9ov1KOTj9xwt0CH6hbwqP1/z74ZWF7rYFnDpyYH07XFcZew==",
|
||||||
|
"license": "MIT",
|
||||||
|
"funding": {
|
||||||
|
"type": "github",
|
||||||
|
"url": "https://github.com/sponsors/tannerlinsley"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@tanstack/react-query": {
|
||||||
|
"version": "5.100.14",
|
||||||
|
"resolved": "https://registry.npmjs.org/@tanstack/react-query/-/react-query-5.100.14.tgz",
|
||||||
|
"integrity": "sha512-oOr6aRdSFEwWhzxEkD/9ZcItM3+LjBSkeVmadWKwUssAHTsqd/7bOjWrX4AbvEkoEhgAxzN0Xk6H/aYzXiYBAw==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@tanstack/query-core": "5.100.14"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"type": "github",
|
||||||
|
"url": "https://github.com/sponsors/tannerlinsley"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"react": "^18 || ^19"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@types/babel__core": {
|
"node_modules/@types/babel__core": {
|
||||||
"version": "7.20.5",
|
"version": "7.20.5",
|
||||||
"resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.20.5.tgz",
|
"resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.20.5.tgz",
|
||||||
@@ -1400,6 +1394,7 @@
|
|||||||
"version": "19.1.6",
|
"version": "19.1.6",
|
||||||
"resolved": "https://registry.npmjs.org/@types/react/-/react-19.1.6.tgz",
|
"resolved": "https://registry.npmjs.org/@types/react/-/react-19.1.6.tgz",
|
||||||
"integrity": "sha512-JeG0rEWak0N6Itr6QUx+X60uQmN+5t3j9r/OVDtWzFXKaj6kD1BwJzOksD0FF6iWxZlbE1kB0q9vtnU2ekqa1Q==",
|
"integrity": "sha512-JeG0rEWak0N6Itr6QUx+X60uQmN+5t3j9r/OVDtWzFXKaj6kD1BwJzOksD0FF6iWxZlbE1kB0q9vtnU2ekqa1Q==",
|
||||||
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"csstype": "^3.0.2"
|
"csstype": "^3.0.2"
|
||||||
@@ -1651,6 +1646,7 @@
|
|||||||
"version": "3.1.3",
|
"version": "3.1.3",
|
||||||
"resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.3.tgz",
|
"resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.3.tgz",
|
||||||
"integrity": "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==",
|
"integrity": "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==",
|
||||||
|
"dev": true,
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/debug": {
|
"node_modules/debug": {
|
||||||
@@ -2112,16 +2108,6 @@
|
|||||||
"node": ">=0.8.19"
|
"node": ">=0.8.19"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/intl-messageformat": {
|
|
||||||
"version": "11.2.8",
|
|
||||||
"resolved": "https://registry.npmjs.org/intl-messageformat/-/intl-messageformat-11.2.8.tgz",
|
|
||||||
"integrity": "sha512-l323RCl3qJDVQ8U9j74ut/hVMdg3VPsOHpVMDvFfz9qiq4dPO5ooVYFNVUzzrpgG39a+RLzcXyJb8VFgIU+tUA==",
|
|
||||||
"license": "BSD-3-Clause",
|
|
||||||
"dependencies": {
|
|
||||||
"@formatjs/fast-memoize": "3.1.6",
|
|
||||||
"@formatjs/icu-messageformat-parser": "3.5.11"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/is-extglob": {
|
"node_modules/is-extglob": {
|
||||||
"version": "2.1.1",
|
"version": "2.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz",
|
||||||
@@ -2502,21 +2488,6 @@
|
|||||||
"react": "^19.1.0"
|
"react": "^19.1.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/react-intl": {
|
|
||||||
"version": "10.1.13",
|
|
||||||
"resolved": "https://registry.npmjs.org/react-intl/-/react-intl-10.1.13.tgz",
|
|
||||||
"integrity": "sha512-3aKnIOIPN6CWsu3jqPpYMlJZ2U0Qnxhd42xGWQNdGIknK/gBudWOHSIx9vN4XKkITokJLr7YTgs4yLUGtbvP9g==",
|
|
||||||
"license": "BSD-3-Clause",
|
|
||||||
"dependencies": {
|
|
||||||
"@formatjs/icu-messageformat-parser": "3.5.11",
|
|
||||||
"@formatjs/intl": "4.1.13",
|
|
||||||
"intl-messageformat": "11.2.8"
|
|
||||||
},
|
|
||||||
"peerDependencies": {
|
|
||||||
"@types/react": "19",
|
|
||||||
"react": "19"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/react-refresh": {
|
"node_modules/react-refresh": {
|
||||||
"version": "0.17.0",
|
"version": "0.17.0",
|
||||||
"resolved": "https://registry.npmjs.org/react-refresh/-/react-refresh-0.17.0.tgz",
|
"resolved": "https://registry.npmjs.org/react-refresh/-/react-refresh-0.17.0.tgz",
|
||||||
|
|||||||
+2
-2
@@ -10,9 +10,9 @@
|
|||||||
"preview": "vite preview"
|
"preview": "vite preview"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@tanstack/react-query": "^5.100.14",
|
||||||
"react": "^19.1.0",
|
"react": "^19.1.0",
|
||||||
"react-dom": "^19.1.0",
|
"react-dom": "^19.1.0"
|
||||||
"react-intl": "^10.1.13"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/js": "^9.25.0",
|
"@eslint/js": "^9.25.0",
|
||||||
|
|||||||
+85
-22
@@ -1,30 +1,93 @@
|
|||||||
import { IntlProvider,
|
import React, {useState, useEffect, useRef } from 'react'
|
||||||
FormattedMessage,
|
//import { useQuery } from '@tanstack/react-query'
|
||||||
FormattedNumber,
|
|
||||||
FormattedDate,
|
function useWindowWidth() {
|
||||||
FormattedTime,
|
const [width,setWidth] = useState(window.innerWidth)
|
||||||
FormattedDateTimeRange } from 'react-intl'
|
|
||||||
import messageRu from './translations/ru.json'
|
useEffect(() => {
|
||||||
import messageEn from './translations/en.json'
|
const handleResize = () => setWidth(window.innerWidth);
|
||||||
|
window.addEventListener('resize',handleResize);
|
||||||
|
return () => window.removeEventListener('resize',handleResize);
|
||||||
|
},[])
|
||||||
|
|
||||||
|
return width
|
||||||
|
}
|
||||||
|
|
||||||
|
function useLocalStorage(key, initValue) {
|
||||||
|
const [value, setValue] = useState(()=>{
|
||||||
|
const stored = localStorage.getItem(key);
|
||||||
|
return stored !== null ? JSON.parse(stored) : initValue
|
||||||
|
})
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
localStorage.setItem(key, JSON.stringify(value))
|
||||||
|
},[key, value])
|
||||||
|
|
||||||
|
return [value,setValue]
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
function useUserData(userId) {
|
||||||
|
return useQuery(
|
||||||
|
['user',userId],
|
||||||
|
() => fetch(`/api/user/${userId}`).then(res => res.json()),
|
||||||
|
{refetchOnWindowFocus: false}
|
||||||
|
)
|
||||||
|
}*/
|
||||||
|
|
||||||
|
function useInput(initValue, validate) {
|
||||||
|
const [value, setValue] = useState(initValue);
|
||||||
|
const [error, setError] = useState(null);
|
||||||
|
|
||||||
|
const onChange = e => {
|
||||||
|
const newValue = e.target.value
|
||||||
|
setValue(newValue)
|
||||||
|
if (validate) {
|
||||||
|
const validationResult = validate(newValue)
|
||||||
|
setError(validationResult)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return { value, error, onChange }
|
||||||
|
}
|
||||||
|
|
||||||
|
function useInterval(callback, delay) {
|
||||||
|
const savedCallback = useRef()
|
||||||
|
|
||||||
|
useEffect(()=>{
|
||||||
|
savedCallback.current = callback
|
||||||
|
},[callback]);
|
||||||
|
|
||||||
|
useEffect(()=>{
|
||||||
|
if (delay == null) return
|
||||||
|
const id = setInterval(()=>{
|
||||||
|
savedCallback.current()
|
||||||
|
},delay);
|
||||||
|
return () => clearInterval(id);
|
||||||
|
},[delay])
|
||||||
|
}
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const locale = 'ru';
|
const width = useWindowWidth();
|
||||||
const messages = messageEn;
|
const [theme, setTheme] = useLocalStorage('theme','light');
|
||||||
|
|
||||||
|
const username = useInput(
|
||||||
|
'',
|
||||||
|
value => value.length < 3 ? 'минимум 3 символа' : null
|
||||||
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<IntlProvider locale={locale} messages={messages}>
|
<h1>Hello, React!{width}</h1>
|
||||||
<h1><FormattedMessage id='app.welcome' /></h1>
|
<button onClick={()=>{
|
||||||
<h2><FormattedMessage id='app.userGreeting' values={{ name: <u>Alex</u> }} /></h2>
|
setTheme(theme === 'light' ? 'dark' : 'light')
|
||||||
<p><FormattedMessage id='app.notifications' values= {{count: 25}} /></p>
|
}}>
|
||||||
<p><FormattedMessage id='app.lastLogin' values={{ date: new Date(), time: new Date()}} /></p>
|
Сменить тему
|
||||||
<p><FormattedNumber value={ 999.99 } style='currency' currency='RUB' /></p>
|
</button>
|
||||||
<p><FormattedNumber value={0.56} style='percent' /></p>
|
<p><input type="text"
|
||||||
<p><FormattedNumber value={1234.567} minimumFractionDigits={2} maximumFractionDigits={2} /></p>
|
value={username.value}
|
||||||
<p><FormattedDate value={new Date()} weekday='long' /></p>
|
onChange={username.onChange} />
|
||||||
<p><FormattedTime value={new Date()} hour='2-digit' minute='2-digit' second='2-digit' /></p>
|
{ username.error ? username.error : '' }
|
||||||
<p><FormattedDateTimeRange from={new Date(2026,6,1,10,0)} to={new Date(2026,6,10,9,0)} /></p>
|
</p>
|
||||||
</IntlProvider>
|
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
{
|
|
||||||
"app.welcome": "welcome to React application",
|
|
||||||
"app.userGreeting": "Hello, {name}",
|
|
||||||
"app.notifications": "You have {count, plural, one {# a notification} few {# are notifications} many {# уведомлений} other {# уведомления}}",
|
|
||||||
"app.lastLogin": "Last login was {date,date,long} in {time,time,short}"
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
{
|
|
||||||
"app.welcome": "добро пожаловать в приложение React",
|
|
||||||
"app.userGreeting": "Здравствуйте, {name}",
|
|
||||||
"app.notifications": "У вас {count, plural, one {# уведомление} few {# уведомления} many {# уведомлений} other {# уведомления}}",
|
|
||||||
"app.lastLogin": "Последний вход был {date,date,long} в {time,time,short}"
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user