friends pages

This commit is contained in:
Primakov Alexandr Alexandrovich 2024-11-07 19:58:32 +03:00
parent db1fc8e634
commit e1c39aad33
5 changed files with 51 additions and 18 deletions

View File

@ -6,8 +6,8 @@ module.exports = {
apiPath: 'stubs/api', apiPath: 'stubs/api',
webpackConfig: { webpackConfig: {
output: { output: {
publicPath: `/static/${pkg.name}/${process.env.VERSION || pkg.version}/` publicPath: `/static/${pkg.name}/${process.env.VERSION || pkg.version}/`,
} },
}, },
/* use https://admin.bro-js.ru/ to create config, navigations and features */ /* use https://admin.bro-js.ru/ to create config, navigations and features */
navigations: { navigations: {
@ -15,11 +15,17 @@ module.exports = {
'link.nav2.by': '/by/:userId', 'link.nav2.by': '/by/:userId',
}, },
features: { features: {
'nav2': { nav2: {
// add your features here in the format [featureName]: { value: string } // add your features here in the format [featureName]: { value: string }
stars: {
value: '8',
},
buttons: {
value: 'true',
},
}, },
}, },
config: { config: {
'nav2.api': '/api' 'nav2.api': '/api',
} },
} }

File diff suppressed because one or more lines are too long

View File

@ -9,12 +9,11 @@ import {
Center, Center,
HStack, HStack,
Heading, Heading,
Icon,
Input, Input,
Text, Text,
VStack, VStack,
} from '@chakra-ui/react' } from '@chakra-ui/react'
import { FaRegStar, FaStar } from 'react-icons/fa6' import { getFeatures, getAllFeatures } from '@brojs/cli'
import React, { memo, useState } from 'react' import React, { memo, useState } from 'react'
import { FormTest } from './from' import { FormTest } from './from'
@ -28,6 +27,10 @@ type User = Record<string, unknown> & {
friends?: User[] friends?: User[]
} }
const features = getFeatures('nav2')
export const Profile = ({ export const Profile = ({
user, user,
isLink, isLink,
@ -54,11 +57,17 @@ export const Profile = ({
<Text fontWeight="bold">Имя: {user.name.toUpperCase()}</Text> <Text fontWeight="bold">Имя: {user.name.toUpperCase()}</Text>
</CardBody> </CardBody>
<CardFooter> <CardFooter>
<Stars rated={rated} setRated={setRated} /> {features['stars'] && (
<Stars
count={Number(features['stars']?.value) * 2}
rated={rated}
setRated={setRated}
/>
)}
</CardFooter> </CardFooter>
</Card> </Card>
</Box> </Box>
{!isLink && <Counter value={rated} setValue={setRated} />} {!isLink && features['buttons'] && <Counter value={rated} setValue={setRated} />}
</Box> </Box>
) )
} }

View File

@ -1,20 +1,38 @@
import { import { HStack, Icon } from '@chakra-ui/react'
HStack,
Icon,
} from '@chakra-ui/react'
import { FaRegStar, FaStar } from 'react-icons/fa6' import { FaRegStar, FaStar } from 'react-icons/fa6'
import React from 'react' import React, { useMemo, useState } from 'react'
const useStars = (currentRated, starsCount) => {
const [rated, setRated] = useState(currentRated)
const stars = useMemo(
() =>
Array.from({ length: starsCount }).map((_, index) => index + 1 > rated),
[starsCount, rated],
)
return {
setRated,
stars,
}
}
export const Stars = ({ export const Stars = ({
count,
rated, rated,
setRated, setRated,
}: { }: {
count: number
rated: number rated: number
setRated: (rate: number) => void setRated: (rate: number) => void
}) => { }) => {
// const {
// stars,
// setRated: starsSetRated
// } = useStars(rated, count)
return ( return (
<HStack> <HStack>
{Array.from({ length: 5 }).map((_, index) => {Array.from({ length: count }).map((_, index) =>
index + 1 > rated ? ( index + 1 > rated ? (
<Icon <Icon
key={index} key={index}
@ -29,7 +47,7 @@ export const Stars = ({
key={index} key={index}
color="orange.400" color="orange.400"
cursor="pointer" cursor="pointer"
onClick={() => setRated(index + 1)} onClick={() => starsSetRated(index + 1)}
> >
<FaStar /> <FaStar />
</Icon> </Icon>

View File

@ -1,5 +1,5 @@
import React from 'react' import React from 'react'
import { Navigate, Route, Routes } from 'react-router-dom' import { Route, Routes } from 'react-router-dom'
import { Container } from '@chakra-ui/react' import { Container } from '@chakra-ui/react'
import { URLs } from './__data__/urls' import { URLs } from './__data__/urls'