Skip to content

Commit

Permalink
refactor: remove gamification
Browse files Browse the repository at this point in the history
  • Loading branch information
nzambello committed Aug 29, 2024
1 parent 240c03c commit 64c3f7e
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 314 deletions.
45 changes: 0 additions & 45 deletions src/components/MemoriWidget/MemoriWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
MemoriConfig,
TranslatedHint,
Invitation,
GamificationLevel,
Tenant,
MemoriSession,
User,
Expand Down Expand Up @@ -76,7 +75,6 @@ import {
} from '../../helpers/utils';
import { anonTag } from '../../helpers/constants';
import { getErrori18nKey } from '../../helpers/error';
import { getGamificationLevel } from '../../helpers/statistics';
import { getCredits } from '../../helpers/credits';

// Widget utilities and helpers
Expand Down Expand Up @@ -2330,48 +2328,6 @@ const MemoriWidget = ({
}
}, []);

const [gamificationLevel, setGamificationLevel] =
useState<GamificationLevel>();
const getGamificationPoints = async (
memoriID: string
): Promise<{
points: number;
unansweredQuestions: number;
}> => {
let gamificationPoints: number | undefined;
let unansQuestions: number | undefined;
try {
const {
contentQualityIndex,
answerQualityIndex,
unansweredQuestions,
...cqResp
} = await getContentQualityIndexes(memoriID);
if (cqResp.resultCode === 0) {
gamificationPoints = contentQualityIndex;
unansQuestions = unansweredQuestions;
}
} catch (_e) {
let err = _e as Error;
console.debug('[APPCONTEXT/QUERYGAMIFICATIONPOINTS]', err);
}

return {
points: gamificationPoints ?? 0,
unansweredQuestions: unansQuestions ?? 0,
};
};
useEffect(() => {
if (memori.engineMemoriID) {
getGamificationPoints(memori.engineMemoriID)
.then(value => {
setGamificationLevel(getGamificationLevel(value.points));
})
.catch(console.debug);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [memori.engineMemoriID]);

// Put SEO tags in head
useEffect(() => {
if (integrationConfig?.seoTitle) {
Expand Down Expand Up @@ -3026,7 +2982,6 @@ const MemoriWidget = ({
const startPanelProps: StartPanelProps = {
memori,
tenant: tenant,
gamificationLevel: gamificationLevel,
language: language,
userLang: userLang,
setUserLang: setUserLang,
Expand Down
13 changes: 5 additions & 8 deletions src/components/StartPanel/StartPanel.css
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
.memori--board-of-experts,
.memori--nsfw {
position: absolute;
right: 2.5rem;
right: 0.25rem;
bottom: -1.25rem;
display: flex;
width: 2rem;
Expand All @@ -160,12 +160,9 @@
height: 1rem;
}

.memori--completions-enabled+.memori--nsfw {
right: 4.75rem;
}

.memori--board-of-experts {
right: 0.25rem;
.memori--board-of-experts + .memori--nsfw,
.memori--completions-enabled + .memori--nsfw {
right: 2.5rem;
}

.memori--board-of-experts svg {
Expand Down Expand Up @@ -220,4 +217,4 @@
.memori--deep-thought-disclaimer a {
color: inherit;
text-decoration: underline;
}
}
58 changes: 20 additions & 38 deletions src/components/StartPanel/StartPanel.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,28 +110,6 @@ Default.args = {
onClickStart: () => {},
};

export const WithGamificationLevel = Template.bind({});
WithGamificationLevel.args = {
memori: {
...memori,
enableCompletions: false,
},
tenant,
gamificationLevel: {
points: 61,
pointsForCurrentBadge: 60,
badge: '🌍',
},
language: 'it',
userLang: 'en',
setUserLang: () => {},
openPositionDrawer: () => {},
instruct: false,
sessionId: sessionID,
clickedStart: false,
onClickStart: () => {},
};

export const WithCompletionsEnabled = Template.bind({});
WithCompletionsEnabled.args = {
memori: {
Expand Down Expand Up @@ -167,18 +145,13 @@ WithNSFWFlag.args = {
onClickStart: () => {},
};

export const WithAllTheBadges = Template.bind({});
WithAllTheBadges.args = {
export const WithCompletionsAndNSFW = Template.bind({});
WithCompletionsAndNSFW.args = {
memori: {
...memori,
enableCompletions: true,
nsfw: true,
},
gamificationLevel: {
points: 61,
pointsForCurrentBadge: 60,
badge: '🌍',
},
tenant,
language: 'it',
userLang: 'en',
Expand Down Expand Up @@ -261,10 +234,24 @@ BoardOfExpert.args = {
enableBoardOfExperts: true,
enableCompletions: true,
},
gamificationLevel: {
points: 61,
pointsForCurrentBadge: 60,
badge: '🌍',
tenant,
language: 'it',
userLang: 'en',
setUserLang: () => {},
openPositionDrawer: () => {},
instruct: false,
sessionId: sessionID,
clickedStart: false,
onClickStart: () => {},
};

export const BoardOfExpertNSFW = Template.bind({});
BoardOfExpertNSFW.args = {
memori: {
...memori,
enableBoardOfExperts: true,
enableCompletions: true,
nsfw: true,
},
tenant,
language: 'it',
Expand All @@ -281,11 +268,6 @@ export const Instruct = Template.bind({});
Instruct.args = {
memori,
tenant,
gamificationLevel: {
points: 61,
pointsForCurrentBadge: 60,
badge: '🌍',
},
language: 'it',
userLang: 'en',
setUserLang: () => {},
Expand Down
34 changes: 0 additions & 34 deletions src/components/StartPanel/StartPanel.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,6 @@ it('renders StartPanel unchanged', () => {
expect(container).toMatchSnapshot();
});

it('renders StartPanel with gamification level unchanged', () => {
const { container } = render(
<StartPanel
memori={memori}
tenant={tenant}
gamificationLevel={{
points: 61,
pointsForCurrentBadge: 60,
badge: '🌍',
}}
language="it"
userLang="en"
setUserLang={() => {}}
openPositionDrawer={() => {}}
instruct={false}
sessionId={sessionID}
clickedStart={false}
onClickStart={() => {}}
setShowLoginDrawer={jest.fn()}
/>
);
expect(container).toMatchSnapshot();
});

it('renders StartPanel with completions enabled unchanged', () => {
const { container } = render(
<StartPanel
Expand Down Expand Up @@ -172,11 +148,6 @@ it('renders StartPanel on instruct unchanged', () => {
<StartPanel
memori={memori}
tenant={tenant}
gamificationLevel={{
points: 61,
pointsForCurrentBadge: 60,
badge: '🌍',
}}
language="it"
userLang="en"
setUserLang={() => {}}
Expand All @@ -199,11 +170,6 @@ it('renders StartPanel with position required unchanged', () => {
needsPosition: true,
}}
tenant={tenant}
gamificationLevel={{
points: 61,
pointsForCurrentBadge: 60,
badge: '🌍',
}}
language="it"
userLang="en"
setUserLang={() => {}}
Expand Down
23 changes: 1 addition & 22 deletions src/components/StartPanel/StartPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
GamificationLevel,
Memori,
Tenant,
Venue,
Expand All @@ -25,7 +24,6 @@ import MapMarker from '../icons/MapMarker';
export interface Props {
memori: Memori;
tenant?: Tenant;
gamificationLevel?: GamificationLevel;
language?: string;
userLang?: string;
setUserLang: (lang: string) => void;
Expand All @@ -51,7 +49,6 @@ export interface Props {
const StartPanel: React.FC<Props> = ({
memori,
tenant,
gamificationLevel,
language,
userLang,
setUserLang,
Expand All @@ -69,7 +66,7 @@ const StartPanel: React.FC<Props> = ({
showLogin = false,
setShowLoginDrawer,
notEnoughCredits = false,
isMultilanguageEnabled
isMultilanguageEnabled,
}) => {
const { t, i18n } = useTranslation();
const [translatedDescription, setTranslatedDescription] = useState(
Expand Down Expand Up @@ -118,24 +115,6 @@ const StartPanel: React.FC<Props> = ({
})}")`,
}}
>
{!!gamificationLevel?.badge?.length && !memori.enableBoardOfExperts && (
<div className="memori--gamification-badge">
<Tooltip
align="left"
content={`${t('gamification.level')} ${
gamificationLevel.badge
}, ${gamificationLevel.points} ${t('gamification.points')}`}
>
<span
aria-label={`${t('gamification.level')} ${
gamificationLevel.badge
}, ${gamificationLevel.points} ${t('gamification.points')}`}
>
{gamificationLevel.badge}
</span>
</Tooltip>
</div>
)}
{!!memori.enableCompletions && !memori.enableBoardOfExperts && (
<div className="memori--completions-enabled">
<Tooltip align="left" content={t('completionsEnabled')}>
Expand Down
Loading

0 comments on commit 64c3f7e

Please sign in to comment.