Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hook up progress percentage #1073

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
};
}
Loading