Skip to content

Commit

Permalink
fixed a few issues on the leveling page and added /tutorials
Browse files Browse the repository at this point in the history
  • Loading branch information
almeidx committed Aug 4, 2021
1 parent b9d377c commit 90045b7
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 31 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Expand Up @@ -31,6 +31,7 @@
"selector": "function"
}
],
"@typescript-eslint/no-dynamic-delete": 0,
"@typescript-eslint/no-extraneous-class": 0,
"@typescript-eslint/no-non-null-assertion": 0,
"@typescript-eslint/space-before-function-paren": 0,
Expand Down
5 changes: 5 additions & 0 deletions packages/bot/next.config.js
Expand Up @@ -32,6 +32,11 @@ module.exports = {
permanent: true,
source: '/docs',
},
{
destination: 'https://www.youtube.com/playlist?list=PLeDA5I-uV0EcC1FDT6JufwxMjBun9iMx2',
permanent: true,
source: '/tutorials',
},
];
},
/**
Expand Down
4 changes: 2 additions & 2 deletions packages/bot/src/components/dashboard/XpMultiplier.tsx
Expand Up @@ -62,12 +62,12 @@ export default function XpMultiplier({
</div>
</div>

{type !== 'global' && (
{type !== 'global' && targets && (
<div className="w-full mx-2">
<Selector
id={`m-${id}-selector`}
limit={getDatabaseLimit('xpMultiplierTargets', premium).maxLength}
initialItems={targets!}
initialItems={targets}
items={type === 'channel' ? channels : roles}
onSelect={(i) => onItemChange(i, id)}
type={type}
Expand Down
33 changes: 20 additions & 13 deletions packages/bot/src/components/dashboard/pages/Leveling.tsx
Expand Up @@ -3,7 +3,6 @@ import cloneDeep from 'lodash.clonedeep';
import { MouseEventHandler, useCallback, useContext, useEffect, useRef, useState } from 'react';
import { BiLayerPlus } from 'react-icons/bi';

import type { DatabaseGuildChanges } from '../../../__generated__/updateDatabaseGuildMutation.graphql';
import { GuildContext } from '../../../contexts/GuildContext';
import {
AutoResetLevels,
Expand Down Expand Up @@ -83,6 +82,15 @@ const resolveAutoResetLevelsTypeByName = (name: string) =>
: AutoResetLevels.NONE;

const resolveInitialXpResponseType = (database: DashboardDatabaseGuild) =>
database.xpResponseType
? /^\d+$/.test(database.xpResponseType)
? ResponseType.CHANNEL
: database.xpResponseType === 'dm'
? ResponseType.DM
: ResponseType.SAME_CHANNEL
: ResponseType.NONE;

const resolveInitialXpResponseTypeValue = (database: DashboardDatabaseGuild) =>
database.xpResponseType
? /^\d+$/.test(database.xpResponseType)
? ResponseType.CHANNEL
Expand All @@ -107,14 +115,14 @@ export default function Leveling({ channels, database, roles, openMenu }: Leveli
const [xpMultipliers, setXpMultipliers] = useState<MultiplierWithStringValue[]>(
database.xpMultipliers.map((m) => ({ ...m, multiplier: m.multiplier.toString() })),
);
const [xpResponseType, setXpResponseType] = useState<string>(resolveInitialXpResponseType(database));
const [xpResponseType, setXpResponseType] = useState<string>(resolveInitialXpResponseTypeValue(database));
const [xpChannelsType, setXpChannelsType] = useState<'whitelist' | 'blacklist'>(
database.xpBlacklistedChannels ? 'blacklist' : 'whitelist',
);
const [newXpMultiplierType, setNewXpMultiplierType] = useState<Multiplier['type']>('channel');
const [newXpRolesLevel, setNewXpRolesLevel] = useState<string>('');
const newXpRoleSubmitRef = useRef<HTMLButtonElement>(null);
const { addChange, changes, removeChange } = useContext(GuildContext);
const { addChange } = useContext(GuildContext);

const xpMessageLimit = getDatabaseLimit('xpMessage', database.premium).maxLength;
const xpChannelsLimit = getDatabaseLimit('xpChannels', database.premium).maxLength;
Expand Down Expand Up @@ -149,7 +157,6 @@ export default function Leveling({ channels, database, roles, openMenu }: Leveli
const clone = cloneDeep<Record<string, Snowflake[]>>(xpRoles);

if (roleIds.length) clone[level] = roleIds;
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
else delete clone[level];

setXpRoles(clone);
Expand All @@ -162,16 +169,14 @@ export default function Leveling({ channels, database, roles, openMenu }: Leveli
const currentType = `${xpChannelsType}` as const;
setXpChannelsType(currentType === 'blacklist' ? 'whitelist' : 'blacklist');

const clone = cloneDeep<Partial<DatabaseGuildChanges>>(changes);

if (currentType === 'blacklist') {
if ('xpBlacklistedChannels' in clone) removeChange('xpBlacklistedChannels');
addChange('xpBlacklistedChannels', null);
return addChange('xpWhitelistedChannels', xpChannels);
}

if ('xpWhitelistedChannels' in clone) removeChange('xpWhitelistedChannels');
addChange('xpWhitelistedChannels', null);
addChange('xpBlacklistedChannels', xpChannels);
}, [addChange, changes, removeChange, xpChannels, xpChannelsType]);
}, [addChange, xpChannels, xpChannelsType]);

const handleXpMultiplierDelete: XpMultiplierOnDeleteFn = useCallback(
(id) => {
Expand Down Expand Up @@ -265,7 +270,7 @@ export default function Leveling({ channels, database, roles, openMenu }: Leveli
<div className="w-full lg:w-1/2">
<BasicSelect
closeOnSelect
initialItem={resolveXpResponseNameByType(ResponseType.SAME_CHANNEL)}
initialItem={resolveXpResponseNameByType(resolveInitialXpResponseType(database))}
items={['Same Channel', 'DM', 'Custom Channel', 'None']}
onSelect={(i) => {
const type = resolveXpResponseTypeByName(i);
Expand Down Expand Up @@ -457,9 +462,11 @@ export default function Leveling({ channels, database, roles, openMenu }: Leveli
<Selector
id="xpChannels"
initialItems={
(database.xpBlacklistedChannels as Snowflake[] | null) ??
(database.xpWhitelistedChannels as Snowflake[] | null) ??
[]
database.xpBlacklistedChannels?.length
? (database.xpBlacklistedChannels as Snowflake[])
: database.xpWhitelistedChannels?.length
? (database.xpWhitelistedChannels as Snowflake[])
: []
}
items={channels}
limit={xpChannelsLimit}
Expand Down
17 changes: 1 addition & 16 deletions packages/bot/src/contexts/GuildContext.tsx
Expand Up @@ -42,7 +42,6 @@ interface GuildContextData {
data: DatabaseChanges | null;
errors: string[];
guildId: Snowflake | null;
removeChange: (key: keyof DatabaseChanges) => void;
section: Section;
updateData: (newData: DashboardDatabaseGuild) => void;
updateGuildId: (newId: Snowflake) => void;
Expand Down Expand Up @@ -159,11 +158,11 @@ export default function GuildContextProvider({ children }: GuildContextProps) {
data &&
(data[key] === value ||
(Array.isArray(value) && !value.length && data[key] === null) ||
(Array.isArray(data[key]) && !(data[key] as any[]).length && value === null) ||
(data[key] === null && value === 0) ||
(data[key] === 0 && value === null))
) {
if (key in clone) {
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete clone[key];
setChanges(clone);
updateErrorsAndWarnings(clone, data);
Expand All @@ -178,19 +177,6 @@ export default function GuildContextProvider({ children }: GuildContextProps) {
[changes, data, updateErrorsAndWarnings],
);

const removeChange = useCallback(
(key: keyof DatabaseChanges) => {
const clone = cloneDeep<Partial<DatabaseChanges>>(changes);

if (key in clone) {
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete clone[key];
setChanges(clone);
}
},
[changes],
);

const clearChanges = useCallback(() => setChanges({}), []);

const updateGuildId = useCallback(
Expand All @@ -210,7 +196,6 @@ export default function GuildContextProvider({ children }: GuildContextProps) {
data,
errors,
guildId,
removeChange,
section,
updateData: setData,
updateGuildId,
Expand Down

2 comments on commit 90045b7

@vercel
Copy link

@vercel vercel bot commented on 90045b7 Aug 4, 2021

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

pepe-bot – ./packages/bot

pepe-bot-almeidx.vercel.app
pepe-bot-git-main-almeidx.vercel.app
pepemanager.com

@vercel
Copy link

@vercel vercel bot commented on 90045b7 Aug 4, 2021

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

pepe-main – ./packages/main

pepe-is.life
pepe-main-git-main-almeidx.vercel.app
pepe-main-almeidx.vercel.app

Please sign in to comment.