fix: heatmap focus

pull/5494/head
Arik Chakma 8 months ago
parent 4acdbaebea
commit 005c66c60a
  1. 12
      src/components/UserPublicProfile/UserPublicActivityHeatmap.tsx
  2. 9
      src/components/UserPublicProfile/UserPublicProfilePage.tsx
  3. 6
      src/components/UserPublicProfile/UserPublicProgressStats.tsx
  4. 10
      src/components/UserPublicProfile/UserPublicProgresses.tsx
  5. 10
      src/helper/number.ts

@ -27,20 +27,20 @@ export function UserActivityHeatmap(props: UserActivityHeatmapProps) {
values={data} values={data}
classForValue={(value) => { classForValue={(value) => {
if (!value) { if (!value) {
return 'fill-gray-100 rounded-md [rx:2px]'; return 'fill-gray-100 rounded-md [rx:2px] focus:outline-none';
} }
const { count } = value; const { count } = value;
if (count >= 20) { if (count >= 20) {
return 'fill-gray-800 rounded-md [rx:2px]'; return 'fill-gray-800 rounded-md [rx:2px] focus:outline-none';
} else if (count >= 10) { } else if (count >= 10) {
return 'fill-gray-600 rounded-md [rx:2px]'; return 'fill-gray-600 rounded-md [rx:2px] focus:outline-none';
} else if (count >= 5) { } else if (count >= 5) {
return 'fill-gray-500 rounded-md [rx:2px]'; return 'fill-gray-500 rounded-md [rx:2px] focus:outline-none';
} else if (count >= 3) { } else if (count >= 3) {
return 'fill-gray-300 rounded-md [rx:2px]'; return 'fill-gray-300 rounded-md [rx:2px] focus:outline-none';
} else { } else {
return 'fill-gray-200 rounded-md [rx:2px]'; return 'fill-gray-200 rounded-md [rx:2px] focus:outline-none';
} }
}} }}
tooltipDataAttrs={(value: any) => { tooltipDataAttrs={(value: any) => {

@ -7,7 +7,13 @@ import { UserPublicProgresses } from './UserPublicProgresses';
type UserPublicProfilePageProps = GetPublicProfileResponse; type UserPublicProfilePageProps = GetPublicProfileResponse;
export function UserPublicProfilePage(props: UserPublicProfilePageProps) { export function UserPublicProfilePage(props: UserPublicProfilePageProps) {
const { activity, username, isOwnProfile, profileVisibility } = props; const {
activity,
username,
isOwnProfile,
profileVisibility,
_id: userId,
} = props;
return ( return (
<> <>
@ -23,6 +29,7 @@ export function UserPublicProfilePage(props: UserPublicProfilePageProps) {
<div className="mt-10"> <div className="mt-10">
<UserPublicProgresses <UserPublicProgresses
username={username!} username={username!}
userId={userId!}
roadmaps={props.roadmaps} roadmaps={props.roadmaps}
publicConfig={props.publicConfig} publicConfig={props.publicConfig}
/> />

@ -14,6 +14,7 @@ type UserPublicProgressStats = {
isCustomResource?: boolean; isCustomResource?: boolean;
roadmapSlug?: string; roadmapSlug?: string;
username: string; username: string;
userId: string;
}; };
export function UserPublicProgressStats(props: UserPublicProgressStats) { export function UserPublicProgressStats(props: UserPublicProgressStats) {
@ -28,10 +29,13 @@ export function UserPublicProgressStats(props: UserPublicProgressStats) {
roadmapSlug, roadmapSlug,
isCustomResource = false, isCustomResource = false,
username, username,
userId,
} = props; } = props;
// Currently we only support roadmap not (best-practices) // Currently we only support roadmap not (best-practices)
const url = `/u/${username}/${isCustomResource ? roadmapSlug : resourceId}`; const url = isCustomResource
? `/r/${roadmapSlug}`
: `/${resourceId}?s=${userId}`;
const totalMarked = doneCount + skippedCount; const totalMarked = doneCount + skippedCount;
const progressPercentage = getPercentage(totalMarked, totalCount); const progressPercentage = getPercentage(totalMarked, totalCount);

@ -2,13 +2,19 @@ import type { GetPublicProfileResponse } from '../../api/user';
import { UserPublicProgressStats } from './UserPublicProgressStats'; import { UserPublicProgressStats } from './UserPublicProgressStats';
type UserPublicProgressesProps = { type UserPublicProgressesProps = {
userId: string;
username: string; username: string;
roadmaps: GetPublicProfileResponse['roadmaps']; roadmaps: GetPublicProfileResponse['roadmaps'];
publicConfig: GetPublicProfileResponse['publicConfig']; publicConfig: GetPublicProfileResponse['publicConfig'];
}; };
export function UserPublicProgresses(props: UserPublicProgressesProps) { export function UserPublicProgresses(props: UserPublicProgressesProps) {
const { roadmaps: roadmapProgresses = [], username, publicConfig } = props; const {
roadmaps: roadmapProgresses = [],
username,
publicConfig,
userId,
} = props;
const { roadmapVisibility, customRoadmapVisibility } = publicConfig! || {}; const { roadmapVisibility, customRoadmapVisibility } = publicConfig! || {};
const roadmaps = roadmapProgresses.filter( const roadmaps = roadmapProgresses.filter(
@ -43,6 +49,7 @@ export function UserPublicProgresses(props: UserPublicProgressesProps) {
roadmapSlug={roadmap.roadmapSlug} roadmapSlug={roadmap.roadmapSlug}
isCustomResource={false} isCustomResource={false}
username={username!} username={username!}
userId={userId}
/> />
</li> </li>
))} ))}
@ -74,6 +81,7 @@ export function UserPublicProgresses(props: UserPublicProgressesProps) {
roadmapSlug={roadmap.roadmapSlug} roadmapSlug={roadmap.roadmapSlug}
username={username!} username={username!}
isCustomResource={true} isCustomResource={true}
userId={userId}
/> />
</li> </li>
))} ))}

@ -1,3 +1,9 @@
export function getPercentage(portion: number, total: number) { export function getPercentage(portion: number, total: number): string {
return portion > 0 ? ((portion / total) * 100).toFixed(2) : 0; if (total <= 0 || portion <= 0) {
return '0';
} else if (portion > total) {
return '100';
}
return ((portion / total) * 100).toFixed(2);
} }

Loading…
Cancel
Save