fit: add background image for breath page, fix emails list timing
This commit is contained in:
parent
041112bdaa
commit
e662122d41
@ -1,8 +1,8 @@
|
|||||||
import routes from "@/routes"
|
import routes from "@/routes"
|
||||||
import { AuthPayload } from "../types"
|
// import { AuthPayload } from "../types"
|
||||||
import { getAuthHeaders } from "../utils"
|
// import { getAuthHeaders } from "../utils"
|
||||||
|
|
||||||
export interface Payload extends AuthPayload {
|
export interface Payload {
|
||||||
locale: string
|
locale: string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -17,11 +17,11 @@ export interface AssetCategory {
|
|||||||
path: string
|
path: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export const createRequest = ({ locale, token }: Payload): Request => {
|
export const createRequest = ({ locale }: Payload): Request => {
|
||||||
const url = new URL(routes.server.assetCategories())
|
const url = new URL(routes.server.assetCategories())
|
||||||
const query = new URLSearchParams({ locale })
|
const query = new URLSearchParams({ locale })
|
||||||
|
|
||||||
url.search = query.toString()
|
url.search = query.toString()
|
||||||
|
|
||||||
return new Request(url, { method: 'GET', headers: getAuthHeaders(token) })
|
return new Request(url, { method: 'GET' })
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,9 +1,10 @@
|
|||||||
import routes from "@/routes"
|
import routes from "@/routes"
|
||||||
import { AuthPayload } from "../types"
|
|
||||||
import { AssetCategory } from "./AssetCategories"
|
import { AssetCategory } from "./AssetCategories"
|
||||||
import { getAuthHeaders } from "../utils"
|
// import { AuthPayload } from "../types"
|
||||||
|
// import { getAuthHeaders } from "../utils"
|
||||||
|
|
||||||
export interface Payload extends AuthPayload {
|
// export interface Payload extends AuthPayload {
|
||||||
|
export interface Payload {
|
||||||
category: string
|
category: string
|
||||||
page?: number
|
page?: number
|
||||||
perPage?: number
|
perPage?: number
|
||||||
@ -34,7 +35,7 @@ export interface AssetMetadata {
|
|||||||
mime_type: string
|
mime_type: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export const createRequest = ({ token, category, page, perPage }: Payload): Request => {
|
export const createRequest = ({ category, page, perPage }: Payload): Request => {
|
||||||
const url = new URL(routes.server.assets(category))
|
const url = new URL(routes.server.assets(category))
|
||||||
const query = new URLSearchParams()
|
const query = new URLSearchParams()
|
||||||
|
|
||||||
@ -45,5 +46,5 @@ export const createRequest = ({ token, category, page, perPage }: Payload): Requ
|
|||||||
|
|
||||||
url.search = query.toString()
|
url.search = query.toString()
|
||||||
|
|
||||||
return new Request(url, { method: 'GET', headers: getAuthHeaders(token) })
|
return new Request(url, { method: 'GET' })
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { useNavigate } from 'react-router-dom'
|
import { useNavigate } from 'react-router-dom'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import routes from '@/routes'
|
// import routes from '@/routes'
|
||||||
import styles from './styles.module.css'
|
import styles from './styles.module.css'
|
||||||
import { useEffect, useState } from 'react'
|
import { useEffect, useState } from 'react'
|
||||||
|
|
||||||
@ -15,7 +15,7 @@ function BreathCircle(): JSX.Element {
|
|||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleNext = () => navigate(routes.client.compatibility())
|
// const handleNext = () => navigate(routes.client.compatibility())
|
||||||
Promise.resolve()
|
Promise.resolve()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
setText(t('breathIn'))
|
setText(t('breathIn'))
|
||||||
@ -32,7 +32,7 @@ function BreathCircle(): JSX.Element {
|
|||||||
.then(() => {
|
.then(() => {
|
||||||
setCounter((prevState) => prevState + 1)
|
setCounter((prevState) => prevState + 1)
|
||||||
if (counter === 3) {
|
if (counter === 3) {
|
||||||
handleNext()
|
// handleNext()
|
||||||
}
|
}
|
||||||
setRender((prevState) => !prevState)
|
setRender((prevState) => !prevState)
|
||||||
})
|
})
|
||||||
|
|||||||
@ -1,10 +1,49 @@
|
|||||||
import styles from './styles.module.css'
|
import styles from './styles.module.css'
|
||||||
import BreathCircle from '../BreathCircle'
|
import BreathCircle from '../BreathCircle'
|
||||||
|
import { useCallback, useEffect, useState } from 'react'
|
||||||
|
import { useApi, useApiCall } from '@/api'
|
||||||
|
import { Asset } from '@/api/resources/Assets'
|
||||||
|
import { useSelector } from 'react-redux'
|
||||||
|
import { selectors } from '@/store'
|
||||||
|
import { getZodiacSignByDate } from '@/services/zodiac-sign'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { AssetCategory } from '@/api/resources/AssetCategories'
|
||||||
|
import { getRandomArbitrary } from '@/services/random-value'
|
||||||
|
|
||||||
|
const getCategoryIdByZodiacSign = (zodiacSign: string, categories: AssetCategory[]) => {
|
||||||
|
const categoryId = categories.find((category) => category.slug === zodiacSign.toLowerCase())?.id
|
||||||
|
return categoryId
|
||||||
|
}
|
||||||
|
|
||||||
function BreathPage(): JSX.Element {
|
function BreathPage(): JSX.Element {
|
||||||
|
const { i18n } = useTranslation()
|
||||||
|
const locale = i18n.language
|
||||||
|
const birthdate = useSelector(selectors.selectBirthdate)
|
||||||
|
const zodiacSign = getZodiacSignByDate(birthdate)
|
||||||
|
const [asset, setAsset] = useState<Asset>()
|
||||||
|
const api = useApi()
|
||||||
|
|
||||||
|
const assetsData = useCallback(async () => {
|
||||||
|
const { asset_categories } = await api.getAssetCategories({ locale })
|
||||||
|
const categoryId = getCategoryIdByZodiacSign(zodiacSign, asset_categories)
|
||||||
|
const { assets } = await api.getAssets({ category: String(categoryId || '1') })
|
||||||
|
return assets
|
||||||
|
}, [api, locale, zodiacSign])
|
||||||
|
|
||||||
|
const {
|
||||||
|
data,
|
||||||
|
// isPending
|
||||||
|
} = useApiCall<Asset[]>(assetsData)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (data) {
|
||||||
|
setAsset(data[getRandomArbitrary(0, data?.length || 0)])
|
||||||
|
}
|
||||||
|
}, [data])
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section className={`${styles.page} page`}>
|
<section className={`${styles.page} page`} style={{ backgroundImage: `url(${asset?.url})` }}>
|
||||||
<BreathCircle />
|
<BreathCircle />
|
||||||
</section>
|
</section>
|
||||||
)
|
)
|
||||||
|
|||||||
@ -7,4 +7,6 @@
|
|||||||
grid-template-rows: 1fr 96px;
|
grid-template-rows: 1fr 96px;
|
||||||
justify-items: center;
|
justify-items: center;
|
||||||
background-color: #01010b;
|
background-color: #01010b;
|
||||||
|
background-size: cover;
|
||||||
|
background-repeat: no-repeat;
|
||||||
}
|
}
|
||||||
@ -2,6 +2,5 @@
|
|||||||
color: #fff;
|
color: #fff;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
/* display: block;
|
color: #1a6821;
|
||||||
width: 100%; */
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,24 +4,6 @@ import styles from './styles.module.css'
|
|||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { useEffect, useRef, useState } from 'react'
|
import { useEffect, useRef, useState } from 'react'
|
||||||
|
|
||||||
// const getEmails = (): IEmailItem[] => {
|
|
||||||
// const emails: IEmailItem[] = []
|
|
||||||
|
|
||||||
// for (let i = 0; i < 2; i++) {
|
|
||||||
// const subList = []
|
|
||||||
// for (let j = 0; j < 4; j++) {
|
|
||||||
// subList.push({
|
|
||||||
// email: getRandomName(),
|
|
||||||
// price: 9
|
|
||||||
// })
|
|
||||||
// }
|
|
||||||
// subList[getRandomArbitrary(0, 4)].price = [5, 13.67][getRandomArbitrary(0, 2)]
|
|
||||||
// emails.push(...subList)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return emails
|
|
||||||
// }
|
|
||||||
|
|
||||||
const getEmails = (): IEmailItem[] => {
|
const getEmails = (): IEmailItem[] => {
|
||||||
const emails: IEmailItem[] = []
|
const emails: IEmailItem[] = []
|
||||||
|
|
||||||
@ -53,7 +35,10 @@ function EmailsList(): JSX.Element {
|
|||||||
}, [countUsers])
|
}, [countUsers])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const randomDelay = getRandomArbitrary(500, 5000)
|
let randomDelay = getRandomArbitrary(500, 5000)
|
||||||
|
if (!elementIdx) {
|
||||||
|
randomDelay = 0
|
||||||
|
}
|
||||||
|
|
||||||
const itemsRefInterval = setInterval(() => {
|
const itemsRefInterval = setInterval(() => {
|
||||||
if (itemsRef.current[elementIdx - 1]) {
|
if (itemsRef.current[elementIdx - 1]) {
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
.container {
|
.container {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
background-color: #adadad;
|
background-color: #b7e9c3;
|
||||||
border-radius: 7px;
|
border-radius: 7px;
|
||||||
padding: 6px 16px;
|
padding: 6px 16px;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|||||||
@ -20,7 +20,7 @@ function WallpaperPage(): JSX.Element {
|
|||||||
const category = user?.profile.sign?.sign || ''
|
const category = user?.profile.sign?.sign || ''
|
||||||
const loadData = useCallback(() => {
|
const loadData = useCallback(() => {
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
api.getAssets({ token, category }),
|
api.getAssets({ category }),
|
||||||
api.getDailyForecasts({ token }),
|
api.getDailyForecasts({ token }),
|
||||||
])
|
])
|
||||||
.then(([{ assets }, { user_daily_forecast }]) => ({
|
.then(([{ assets }, { user_daily_forecast }]) => ({
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user