Skip to content

Commit 60899c8

Browse files
committed
StudentSolutionsPage: использовать avatarka
1 parent 7ff5c29 commit 60899c8

File tree

5 files changed

+49
-3
lines changed

5 files changed

+49
-3
lines changed

hwproj.front/package-lock.json

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hwproj.front/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
"@types/remarkable": "^1.7.4",
2727
"@uiw/react-markdown-preview": "4.2.2",
2828
"@uiw/react-md-editor": "3.25.6",
29+
"avatarka": "^1.0.1",
30+
"avatarka-react": "^1.0.1",
2931
"axios": "^0.30.2",
3032
"bootstrap": "^4.3.1",
3133
"classnames": "^2.3.1",
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import {AccountDataDto} from "@/api";
2+
import {FC} from "react";
3+
import AvatarUtils from "@/components/Utils/AvatarUtils";
4+
import {Avatar} from "@mui/material";
5+
import {Avatar as Avatarka, generateParams, getThemeNames} from 'avatarka-react';
6+
7+
const themes = getThemeNames().filter(x => x !== "geometric")
8+
9+
export const UserAvatar: FC<{ user: AccountDataDto }> = ({user}) => {
10+
if (user.githubId) return <Avatar {...AvatarUtils.stringAvatar(user)}/>
11+
12+
const hash = [...user.userId!].reduce((h, c) => Math.imul(h, 31) + c.charCodeAt(0) | 0, 0) >>> 0
13+
const index = hash % themes.length
14+
const theme = themes[index]
15+
const params = generateParams(theme, user.userId);
16+
return <Avatarka params={{...params, backgroundShape: "circle"}} theme={theme} size={40}/>;
17+
}

hwproj.front/src/components/Solutions/TaskSolutionComponent.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
SolutionActualityPart, StudentDataDto
1212
} from '@/api'
1313
import ApiSingleton from "../../api/ApiSingleton";
14-
import {Alert, Avatar, Rating, Stack, Tooltip, Card, CardContent, CardActions, IconButton, Chip} from "@mui/material";
14+
import {Alert, Rating, Stack, Card, CardContent, CardActions, IconButton, Chip, Tooltip, Avatar} from "@mui/material";
1515
import AvatarUtils from "../Utils/AvatarUtils";
1616
import Utils from "../../services/Utils";
1717
import {RatingStorage} from "../Storages/RatingStorage";
@@ -28,6 +28,7 @@ import KeyboardCommandKeyIcon from '@mui/icons-material/KeyboardCommandKey';
2828
import MouseOutlinedIcon from '@mui/icons-material/MouseOutlined';
2929
import BlurOnIcon from '@mui/icons-material/BlurOn';
3030
import BlurOffIcon from '@mui/icons-material/BlurOff';
31+
import {UserAvatar} from "../Common/UserAvatar";
3132

3233
interface ISolutionProps {
3334
courseId: number,
@@ -463,7 +464,7 @@ const TaskSolutionComponent: FC<ISolutionProps> = (props) => {
463464
alignItems={students.length === 1 ? "center" : "normal"} spacing={1}>
464465
<Stack direction={"row"} spacing={1}>
465466
{students && students.map(t => <Tooltip title={t.surname + " " + t.name}>
466-
<Avatar {...AvatarUtils.stringAvatar(t)} />
467+
<span><UserAvatar user={t} key={t.userId}/></span>
467468
</Tooltip>)}
468469
</Stack>
469470
<Grid item spacing={1} container direction="column">

hwproj.front/src/components/Utils/AvatarUtils.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {AccountDataDto} from "../../api";
1+
import {AccountDataDto} from "@/api";
22

33
export default class AvatarUtils {
44

0 commit comments

Comments
 (0)