mirror of
https://github.com/sergeyyarkov/educt-client.git
synced 2026-10-12 02:39:10 +03:00
feat: likes state
This commit is contained in:
parent
9d67c14fee
commit
b82c2203bf
@ -1,4 +1,4 @@
|
|||||||
import React from 'react';
|
import React, { useRef, useState } from 'react';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import * as helpers from '@educt/helpers';
|
import * as helpers from '@educt/helpers';
|
||||||
import { Link as ReactRouterLink } from 'react-router-dom';
|
import { Link as ReactRouterLink } from 'react-router-dom';
|
||||||
@ -76,9 +76,11 @@ interface ICourseInfoProps extends BoxProps {
|
|||||||
}
|
}
|
||||||
export const CourseInfo: React.FC<ICourseInfoProps> = props => {
|
export const CourseInfo: React.FC<ICourseInfoProps> = props => {
|
||||||
const { id, lessonsCount, studentsCount, likesCount, ...boxProps } = props;
|
const { id, lessonsCount, studentsCount, likesCount, ...boxProps } = props;
|
||||||
|
const [likes, setLikes] = useState<number>(Number.parseInt(likesCount, 10));
|
||||||
|
|
||||||
const handleLikeCourse = (id: string) => () => {
|
const handleLikeCourse = (id: string) => () => {
|
||||||
// TODO set like request
|
// TODO set like request
|
||||||
|
setLikes(likes => likes + 1);
|
||||||
console.log(`like course: ${id}`);
|
console.log(`like course: ${id}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -96,7 +98,7 @@ export const CourseInfo: React.FC<ICourseInfoProps> = props => {
|
|||||||
</Text>
|
</Text>
|
||||||
|
|
||||||
<Button onClick={handleLikeCourse(id)} leftIcon={<MdThumbUpOffAlt />} variant='ghost'>
|
<Button onClick={handleLikeCourse(id)} leftIcon={<MdThumbUpOffAlt />} variant='ghost'>
|
||||||
{likesCount}
|
{likes}
|
||||||
</Button>
|
</Button>
|
||||||
</Flex>
|
</Flex>
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user