Skip to content

Commit

Permalink
Hook up progress percentage
Browse files Browse the repository at this point in the history
  • Loading branch information
jribbink committed Jan 6, 2025
1 parent 0ffbc1c commit 5d33a8f
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 29 deletions.
7 changes: 6 additions & 1 deletion src/components/ConnectButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useIsMobile } from '@site/src/hooks/use-is-mobile';
import Dropdown from '@site/src/ui/design-system/src/lib/Components/Dropdown';
import ProgressModal from '@site/src/components/ProgressModal';
import ProfileModal from '@site/src/components/ProfileModal';
import { useProgress } from '../hooks/use-progress';

const shortenAddress = (address: string, isMobile: boolean) => {
if (!address) return '';
Expand All @@ -16,6 +17,7 @@ const ConnectButton: React.FC = () => {
const isMobile = useIsMobile();
const [isProgressModalOpen, setIsProgressModalOpen] = useState(false);
const [isProfileModalOpen, setIsProfileModalOpen] = useState(false);
const { getProgress } = useProgress();

const handleOpenProgress = () => {
setIsProgressModalOpen(true);
Expand All @@ -42,7 +44,10 @@ const ConnectButton: React.FC = () => {
}

const dropdownItems = [
{ label: 'Progress', onClick: handleOpenProgress },
{
label: `Progress (${Math.floor(getProgress() * 100)}%)`,
onClick: handleOpenProgress,
},
{ label: 'Profile', onClick: handleOpenProfileModal },
{ label: 'Disconnect', onClick: logOut },
];
Expand Down
30 changes: 2 additions & 28 deletions src/components/ProgressModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import React from 'react';
import Modal from '@site/src/ui/design-system/src/lib/Components/Modal';
import Checklist from '@site/src/components/ProgressChecklist';
import { Button } from '@site/src/ui/design-system/src/lib/Components/Button';
import { useProfile } from '../hooks/use-profile';
import { useCurrentUser } from '../hooks/use-current-user';
import { SocialType } from '../types/gold-star';
import { useProgress } from '../hooks/use-progress';

interface ProgressModalProps {
isOpen: boolean;
Expand All @@ -17,31 +15,7 @@ const ProgressModal: React.FC<ProgressModalProps> = ({
onClose,
onOpenProfileModal,
}) => {
const user = useCurrentUser();
const { profile } = useProfile(user.user.addr);

const profileItems = [
{
label: 'Create handle',
completed: profile && !!profile.handle,
},
{
label: 'Add Github Profile',
completed: profile && !!profile.socials[SocialType.GITHUB],
},
{
label: 'Add how you found Flow',
completed: profile && !!profile.referralSource,
},
{
label: 'Add contract addresses',
completed: profile && Object.keys(profile.deployedContracts).length > 0,
},
] as { label: string; completed: boolean }[];

const challengeItems = [
{ label: 'Complete first challenge', completed: true },
];
const { profileItems, challengeItems } = useProgress();

const onChallengeAction = () => {
console.log('TODO: Challenge action');
Expand Down
52 changes: 52 additions & 0 deletions src/hooks/use-progress.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { SocialType } from '../types/gold-star';
import { useCurrentUser } from './use-current-user';
import { useProfile } from './use-profile';

export interface ProgressItem {
label: string;
completed: boolean;
}

export function useProgress() {
const { user } = useCurrentUser();
const { profile } = useProfile(user.addr);

const profileItems = [
{
label: 'Create handle',
completed: profile && !!profile.handle,
},
{
label: 'Add Github Profile',
completed: profile && !!profile.socials[SocialType.GITHUB],
},
{
label: 'Add how you found Flow',
completed: profile && !!profile.referralSource,
},
{
label: 'Add contract addresses',
completed: profile && Object.keys(profile.deployedContracts).length > 0,
},
] as ProgressItem[];

const challengeItems = [
{
label: 'Complete first challenge',
completed: false,
},
] as ProgressItem[];

function getProgress() {
const items = [...profileItems, ...challengeItems];
const total = items.length;
const completed = items.filter((item) => item.completed).length;
return completed / total;
}

return {
profileItems,
challengeItems,
getProgress,
};
}

0 comments on commit 5d33a8f

Please sign in to comment.