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

Added XP progress bar #10570

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const featureFlags = {
stickyEditor: buildFlag(process.env.FLAG_STICKY_EDITOR),
newMobileNav: buildFlag(process.env.FLAG_NEW_MOBILE_NAV),
rewardsPage: buildFlag(process.env.FLAG_REWARDS_PAGE),
xp: buildFlag(process.env.FLAG_XP),
};

export type AvailableFeatureFlag = keyof typeof featureFlags;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import AuthButtons from 'views/components/SublayoutHeader/AuthButtons';
import { AuthModalType } from 'views/modals/AuthModal';
import { capDecimals } from 'views/modals/ManageCommunityStakeModal/utils';
import { CWText } from '../../component_kit/cw_text';
import XPProgressIndicator from '../XPProgressIndicator';
import './DesktopHeader.scss';

interface DesktopHeaderProps {
Expand All @@ -32,6 +33,7 @@ interface DesktopHeaderProps {
const DesktopHeader = ({ onMobile, onAuthModalOpen }: DesktopHeaderProps) => {
const navigate = useCommonNavigate();
const rewardsEnabled = useFlag('rewardsPage');
const xpEnabled = useFlag('xp');
const { menuVisible, setMenu, menuName, setUserToggledVisibility } =
useSidebarStore();
const user = useUserStore();
Expand Down Expand Up @@ -87,6 +89,7 @@ const DesktopHeader = ({ onMobile, onAuthModalOpen }: DesktopHeaderProps) => {
isLoggedIn: user.isLoggedIn,
})}
>
{xpEnabled && <XPProgressIndicator />}
<CreateContentPopover />
{!isWindowSmallInclusive(window.innerWidth) && (
<CWTooltip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import MobileSearchModal from 'views/modals/MobileSearchModal';
import useUserMenuItems from '../useUserMenuItems';

import { DOCS_SUBDOMAIN } from '@hicommonwealth/shared';
import { useFlag } from 'hooks/useFlag';
import XPProgressIndicator, {
XPProgressIndicatorMode,
} from '../XPProgressIndicator';
import './MobileHeader.scss';

interface MobileHeaderProps {
Expand All @@ -35,6 +39,7 @@ const MobileHeader = ({
const [isModalOpen, isSetModalOpen] = useState(false);
const { menuVisible } = useSidebarStore();
const userData = useUserStore();
const xpEnabled = useFlag('xp');
const user = userData.addresses?.[0];
const { isInviteLinkModalOpen, setIsInviteLinkModalOpen } =
useInviteLinkModal();
Expand Down Expand Up @@ -78,6 +83,10 @@ const MobileHeader = ({
)}

<div className="right-side">
{xpEnabled && (
<XPProgressIndicator mode={XPProgressIndicatorMode.Compact} />
)}

{magnifyingGlassVisible && (
<CWIconButton
iconName="magnifyingGlass"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
@import '../../../../styles/shared';

.XPProgressIndicator {
all: unset;
padding: 4px;

.b2 {
color: $primary-500 !important;
}

&:focus,
&:focus-within {
outline: none !important;
}

&:hover {
background-color: $neutral-100;
cursor: pointer;
border-radius: 6px;
}

.weekly-progress {
min-width: 150px;
width: 200px;
max-width: 200px;
display: flex;
flex-direction: column;
justify-content: center;
gap: 2px;

.header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 0 4px;

.caption {
font-size: 10px !important;
color: $primary-500 !important;
}
}

.progress-bar {
height: 10px;
width: 100%;
border: 1px solid $neutral-100;

&::-webkit-progress-bar {
background-color: $neutral-200;
border-radius: $border-radius-corners;
}

&::-webkit-progress-value {
background-color: $primary-400;
border-radius: $border-radius-corners;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import clsx from 'clsx';
import React from 'react';

import useUserStore from 'state/ui/user';
import { CWText } from '../../component_kit/cw_text';
import './XPProgressIndicator.scss';
import { XPProgressIndicatorMode, XPProgressIndicatorProps } from './types';

const XPProgressIndicator = ({
mode = XPProgressIndicatorMode.Detailed,
className,
}: XPProgressIndicatorProps) => {
const sampleData = {
weeklyGoal: {
current: 170,
target: 400,
},
};

const currentProgress = parseInt(
(
(sampleData.weeklyGoal.current / sampleData.weeklyGoal.target) *
100
).toFixed(0),
);

const user = useUserStore();

if (!user.isLoggedIn) return;

const weeklyProgress = (
<div className={clsx('weekly-progress', className)}>
<div className="header">
<CWText type="caption" fontWeight="semiBold">
Weekly XP Goal
</CWText>
<CWText type="caption" fontWeight="semiBold">
{sampleData.weeklyGoal.current} / {sampleData.weeklyGoal.target} XP
</CWText>
</div>
<progress className="progress-bar" value={currentProgress} max={100} />
</div>
);

return (
<button className={clsx('XPProgressIndicator', className, mode)}>
{mode === XPProgressIndicatorMode.Compact ? (
<CWText type="b2" fontWeight="semiBold">
XP
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just xp text, no points?

</CWText>
) : (
weeklyProgress
)}
</button>
);
};

export default XPProgressIndicator;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import XPProgressIndicator from './XPProgressIndicator';
export * from './types';

export default XPProgressIndicator;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export enum XPProgressIndicatorMode {
Compact = 'compact',
Detailed = 'detailed',
}

export type XPProgressIndicatorProps = {
mode?: XPProgressIndicatorMode;
className?: string;
};
1 change: 1 addition & 0 deletions packages/commonwealth/client/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export default defineConfig(({ mode }) => {
'process.env.FLAG_REWARDS_PAGE': JSON.stringify(env.FLAG_REWARDS_PAGE),
'process.env.FLAG_STICKY_EDITOR': JSON.stringify(env.FLAG_STICKY_EDITOR),
'process.env.FLAG_NEW_MOBILE_NAV': JSON.stringify(env.FLAG_NEW_MOBILE_NAV),
'process.env.FLAG_XP': JSON.stringify(env.FLAG_XP),
};

const config = {
Expand Down
Loading