Skip to content

Commit

Permalink
some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sspenst committed May 15, 2024
1 parent ef254f3 commit e992397
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 51 deletions.
14 changes: 7 additions & 7 deletions components/profile/profileAchievements.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import AchievementRulesMultiplayer from '@root/constants/achievements/Achievemen
import AchievementRulesProgress from '@root/constants/achievements/AchievementRulesProgress';
import AchievementRulesReviewer from '@root/constants/achievements/AchievementRulesReviewer';
import AchievementRulesSkill from '@root/constants/achievements/AchievementRulesSkill';
import AchievementRulesThinky from '@root/constants/achievements/AchievementRulesSocial';
import AchievementRulesSocial from '@root/constants/achievements/AchievementRulesSocial';
import AchievementType from '@root/constants/achievements/achievementType';
import { AppContext } from '@root/contexts/appContext';
import Achievement from '@root/models/db/achievement';
Expand All @@ -29,20 +29,20 @@ export function ProfileAchievments({ achievements }: { achievements: Achievement
}).filter(achievement => achievement !== null);
}

const globalAchievements = { 'Social Achievements': getAchievementsOfCategory(AchievementRulesThinky) } as { [key: string]: JSX.Element[] };

const achievementsByCategory = game.isNotAGame ? globalAchievements : {
const achievementsByCategory: { [key: string]: JSX.Element[] } = game.isNotAGame ? {
'Social Achievements': getAchievementsOfCategory(AchievementRulesSocial),
} : {
'Progress': getAchievementsOfCategory(AchievementRulesProgress),
'Creator': getAchievementsOfCategory(AchievementRulesCreator),
'Skill': getAchievementsOfCategory(AchievementRulesSkill),
'Reviewer': getAchievementsOfCategory(AchievementRulesReviewer),
'Multiplayer': getAchievementsOfCategory(AchievementRulesMultiplayer),
} as { [key: string]: JSX.Element[] };
};

return (
<div className='flex gap-6 justify-center p-3'>
<div className='flex flex-wrap gap-6 justify-center p-3'>
{Object.keys(achievementsByCategory).map((achievementCategory) => (
<div className='flex flex-col gap-4 max-w-80 min-w-60 max-w-full' key={achievementCategory}>
<div className='flex flex-col gap-4 min-w-60 max-w-full' key={achievementCategory}>
<h1 className='text-2xl font-medium '>{achievementCategory}</h1>
{achievementsByCategory[achievementCategory]}
</div>
Expand Down
20 changes: 10 additions & 10 deletions constants/achievements/AchievementRulesSocial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ interface IAchievementInfoSocial extends IAchievementInfo {
unlocked: ({ welcomedComments, commentCount }: { welcomedComments: Comment[]; commentCount: number }) => boolean;
}

const AchievementRulesThinky: { [achievementType: string]: IAchievementInfoSocial } = {};
const AchievementRulesSocial: { [achievementType: string]: IAchievementInfoSocial } = {};

AchievementRulesThinky[AchievementType.THINKY_SOCIAL_COMMENT_TO_1_USER] = {
AchievementRulesSocial[AchievementType.THINKY_SOCIAL_COMMENT_TO_1_USER] = {
getDescription: () => 'Wrote a comment to a user',
name: 'Social Butterfly',
emoji: '🦋',
Expand All @@ -18,7 +18,7 @@ AchievementRulesThinky[AchievementType.THINKY_SOCIAL_COMMENT_TO_1_USER] = {
return (commentCount > 0);
},
};
AchievementRulesThinky[AchievementType.THINKY_SOCIAL_WELCOMED_1_USER] = {
AchievementRulesSocial[AchievementType.THINKY_SOCIAL_WELCOMED_1_USER] = {
getDescription: () => 'Welcomed a new user to the community!',
name: 'Newbie Nod',
emoji: '👋',
Expand All @@ -28,35 +28,35 @@ AchievementRulesThinky[AchievementType.THINKY_SOCIAL_WELCOMED_1_USER] = {
return (welcomedComments.length > 0);
},
};
AchievementRulesThinky[AchievementType.THINKY_SOCIAL_WEBLCOMED_5_USERS] = {
AchievementRulesSocial[AchievementType.THINKY_SOCIAL_WELCOMED_5_USERS] = {
getDescription: () => 'Welcomed 5 new user to the community!',
name: 'Thinky-Mart Greeter',
emoji: '🛒',
discordNotification: true,
secret: true,
unlocked: ({ welcomedComments }) => {
return (welcomedComments.length > 0);
return (welcomedComments.length >= 5);
},
};
AchievementRulesThinky[AchievementType.THINKY_SOCIAL_WEBLCOMED_10_USERS] = {
AchievementRulesSocial[AchievementType.THINKY_SOCIAL_WELCOMED_10_USERS] = {
getDescription: () => 'Welcomed 10 new users to the community!',
name: 'Welcoming Committee',
emoji: '🎈',
discordNotification: true,
secret: true,
unlocked: ({ welcomedComments }) => {
return (welcomedComments.length >= 5);
return (welcomedComments.length >= 10);
},
};
AchievementRulesThinky[AchievementType.THINKY_SOCIAL_WEBLCOMED_25_USERS] = {
AchievementRulesSocial[AchievementType.THINKY_SOCIAL_WELCOMED_25_USERS] = {
getDescription: () => 'Welcomed 25 new users to the community!',
name: 'Thinky Ambassador',
emoji: '🤝',
discordNotification: true,
secret: true,
unlocked: ({ welcomedComments }) => {
return (welcomedComments.length >= 10);
return (welcomedComments.length >= 25);
},
};

export default AchievementRulesThinky;
export default AchievementRulesSocial;
6 changes: 3 additions & 3 deletions constants/achievements/achievementInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import AchievementRulesMultiplayer from './AchievementRulesMultiplayer';
import AchievementRulesProgress from './AchievementRulesProgress';
import AchievementRulesReviewer from './AchievementRulesReviewer';
import AchievementRulesSkill from './AchievementRulesSkill';
import AchievementRulesThinky from './AchievementRulesSocial';
import AchievementRulesSocial from './AchievementRulesSocial';

export interface IAchievementInfo {
discordNotification?: boolean;
Expand All @@ -16,19 +16,19 @@ export interface IAchievementInfo {
}

export enum AchievementCategory {
SOCIAL = 'SOCIAL',
PROGRESS = 'USER',
CREATOR = 'CREATOR',
SKILL = 'LEVEL_COMPLETION',
THINKY = 'THINKY',
REVIEWER = 'REVIEWER',
MULTIPLAYER = 'MULTIPLAYER',
}

export const AchievementCategoryMapping = {
[AchievementCategory.SOCIAL]: AchievementRulesSocial,
[AchievementCategory.PROGRESS]: AchievementRulesProgress,
[AchievementCategory.CREATOR]: AchievementRulesCreator,
[AchievementCategory.SKILL]: AchievementRulesSkill,
[AchievementCategory.THINKY]: AchievementRulesThinky,
[AchievementCategory.REVIEWER]: AchievementRulesReviewer,
[AchievementCategory.MULTIPLAYER]: AchievementRulesMultiplayer,
};
Expand Down
15 changes: 4 additions & 11 deletions constants/achievements/achievementType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,11 @@ enum AchievementType {
CREATOR_CREATED_10_HIGH_QUALITY_LEVELS = 'CREATOR_CREATED_10_HIGH_QUALITY_LEVELS',
CREATOR_CREATED_25_HIGH_QUALITY_LEVELS = 'CREATOR_CREATED_25_HIGH_QUALITY_LEVELS',
RECORD_AFTER_1_YEAR = 'RECORD_AFTER_1_YEAR',
//
//
THINKY_SOCIAL_WELCOMED_1_USER = 'SOCIAL_WELCOMED_1_USER',
THINKY_SOCIAL_WEBLCOMED_5_USERS = 'SOCIAL_WELCOMED_5_USERS',
THINKY_SOCIAL_WEBLCOMED_10_USERS = 'SOCIAL_WELCOMED_10_USERS',
THINKY_SOCIAL_WEBLCOMED_25_USERS = 'SOCIAL_WELCOMED_25_USERS',

THINKY_SOCIAL_COMMENT_TO_1_USER = 'SOCIAL_COMMENT_1_USER',

// THINKY_SOCIAL_FOLLOWED_1_USER = 'SOCIAL_FOLLOWED_1_USER', // TODO?
// THINKY_PLAYED_2_GAMES = 'PLAYED_2_GAMES', // TODO?
//
THINKY_SOCIAL_WELCOMED_1_USER = 'SOCIAL_WELCOMED_1_USER',
THINKY_SOCIAL_WELCOMED_5_USERS = 'SOCIAL_WELCOMED_5_USERS',
THINKY_SOCIAL_WELCOMED_10_USERS = 'SOCIAL_WELCOMED_10_USERS',
THINKY_SOCIAL_WELCOMED_25_USERS = 'SOCIAL_WELCOMED_25_USERS',
}

export default AchievementType;
16 changes: 10 additions & 6 deletions helpers/refreshAchievements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,20 @@ import queueDiscordWebhook from './discordWebhook';
import { getRecordsByUserId } from './getRecordsByUserId';

const AchievementCategoryFetch = {
[AchievementCategory.THINKY]: async (_gameId: GameId, userId: Types.ObjectId) => {
[AchievementCategory.SOCIAL]: async (_gameId: GameId, userId: Types.ObjectId) => {
// no game ID as this is a global
const [commentCount, welcomedComments] = await Promise.all([
// deletedat should be null
CommentModel.countDocuments({ author: userId, deletedAt: null,
CommentModel.countDocuments({
author: userId,
deletedAt: null,
target: { $ne: userId }
}),
CommentModel.find({ author: userId, deletedAt: null,
CommentModel.find({
author: userId,
deletedAt: null,
target: { $ne: userId },
text: { $regex: /welcome/i } }).populate('target').lean<Comment[]>()
text: { $regex: /welcome/i },
}).populate('target').lean<Comment[]>()
]);

// loop through the welcomed comments and filter out where comment.createdAt - 1000*comment.user.ts > 24 hours
Expand Down Expand Up @@ -140,7 +144,7 @@ export async function refreshAchievements(gameId: GameId, userId: Types.ObjectId

// eslint-disable-next-line @typescript-eslint/no-explicit-any
if (achievementInfo.unlocked(neededData as any)) {
achievementsCreatedPromises.push(createNewAchievement(category === AchievementCategory.THINKY ? GameId.THINKY : gameId, achievementType as AchievementType, userId, achievementsCreatedPromises.length > 0)); // for each category, only send one push notification
achievementsCreatedPromises.push(createNewAchievement(category === AchievementCategory.SOCIAL ? GameId.THINKY : gameId, achievementType as AchievementType, userId, achievementsCreatedPromises.length > 0)); // for each category, only send one push notification

if (achievementInfo.discordNotification) {
// Should be "<User.name> just unlocked <Achievement.name> achievement!" where <User.name> is a link to the user's profile and <Achievement.name> is a link to the achievement's page
Expand Down
1 change: 0 additions & 1 deletion middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ const noSubdomainPages = new Set([
'notifications',
'play-as-guest',
'profile',
'achievement',
'reset-password',
'settings',
'signup',
Expand Down
23 changes: 11 additions & 12 deletions pages/[subdomain]/profile/[name]/[[...tab]]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,6 @@ export default function ProfilePage({

/>
<div className='flex flex-wrap text-sm text-center gap-2 mt-2 justify-center items-center'>

<Link
className={getTabClassNames(ProfileTab.Profile)}
href={`/profile/${user.name}`}
Expand All @@ -829,17 +828,17 @@ export default function ProfilePage({
</div>
</Link>
{!game.isNotAGame &&
<>
<Link
className={getTabClassNames(ProfileTab.Insights)}
href={`/profile/${user.name}/${ProfileTab.Insights}`}
>
<div className='flex flex-row items-center gap-2'>
<Image alt='pro' src='/pro.svg' width='16' height='16' />
<span>Insights</span>
</div>
</Link>
</>
<>
<Link
className={getTabClassNames(ProfileTab.Insights)}
href={`/profile/${user.name}/${ProfileTab.Insights}`}
>
<div className='flex flex-row items-center gap-2'>
<Image alt='pro' src='/pro.svg' width='16' height='16' />
<span>Insights</span>
</div>
</Link>
</>
}
<Link
className={getTabClassNames(ProfileTab.Achievements)}
Expand Down
2 changes: 1 addition & 1 deletion pages/api/comment/[id].ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export default withAuth({
if (target.toString() !== req.user._id.toString()) {
await Promise.all([
createNewWallPostNotification(req.gameId, NotificationType.NEW_WALL_POST, target, comment.author, target, JSON.stringify(comment)),
queueRefreshAchievements(req.gameId, req.user._id, [AchievementCategory.THINKY]),
queueRefreshAchievements(req.gameId, req.user._id, [AchievementCategory.SOCIAL]),
]);
}
} else if (targetModel === 'Comment') {
Expand Down

0 comments on commit e992397

Please sign in to comment.