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

Development #368

Merged
merged 2 commits into from
Dec 12, 2024
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
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-case-declarations */
import React, { useEffect, useState } from 'react';
import { Box, CircularProgress, Paper, Tab, Tabs } from '@mui/material';
import clsx from 'clsx';
Expand Down Expand Up @@ -52,6 +53,18 @@ function a11yProps(index: number) {
};
}

const PLATFORM_ORDER = [
IntegrationPlatform.Discord,
IntegrationPlatform.Github,
IntegrationPlatform.Notion,
IntegrationPlatform.MediaWiki,
IntegrationPlatform.Discourse,
IntegrationPlatform.Telegram,
IntegrationPlatform.X,
IntegrationPlatform.Snapshot,
IntegrationPlatform.GDrive,
];

function HivemindSettings() {
const { retrievePlatforms, retrieveModules, patchModule } = useAppStore();
const [loading, setLoading] = useState<boolean>(false);
Expand Down Expand Up @@ -113,22 +126,6 @@ function HivemindSettings() {
case 1:
setIsActivePlatformLoading(true);
const { results: googleResults } = await retrievePlatforms({
name: 'google',
community: communityId,
});
const gdriveHivemindModule = hivemindModules.results.find(
(hivemindModule: IModuleProps) =>
hivemindModule.community === communityId
);

setHivemindModule(gdriveHivemindModule);
setPlatforms(googleResults);
setIsActivePlatformLoading(false);
break;

case 2:
setIsActivePlatformLoading(true);
const { results: githubResults } = await retrievePlatforms({
name: 'github',
community: communityId,
});
Expand All @@ -138,28 +135,27 @@ function HivemindSettings() {
);

setHivemindModule(githubHivemindModule);
setPlatforms(githubResults);
setPlatforms(googleResults);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix misleading variable names in platform fetching

The variable names don't match their content:

  • googleResults is used for GitHub data
  • githubResults is used for Notion data

Apply this fix:

- const { results: googleResults } = await retrievePlatforms({
+ const { results: githubResults } = await retrievePlatforms({
    name: 'github',
    community: communityId,
  });
...
- setPlatforms(googleResults);
+ setPlatforms(githubResults);

...
- const { results: githubResults } = await retrievePlatforms({
+ const { results: notionResults } = await retrievePlatforms({
    name: 'notion',
    community: communityId,
  });
...
- setPlatforms(githubResults);
+ setPlatforms(notionResults);

Also applies to: 154-154

setIsActivePlatformLoading(false);
break;

case 3:
case 2:
setIsActivePlatformLoading(true);
const { results: notionResults } = await retrievePlatforms({
const { results: githubResults } = await retrievePlatforms({
name: 'notion',
community: communityId,
});

const notionHivemindModule = hivemindModules.results.find(
(hivemindModule: IModuleProps) =>
hivemindModule.community === communityId
);

setHivemindModule(notionHivemindModule);
setPlatforms(notionResults);
setPlatforms(githubResults);
setIsActivePlatformLoading(false);
break;

case 4:
case 3:
setIsActivePlatformLoading(true);
const { results: mediaWikiResults } = await retrievePlatforms({
name: 'mediaWiki',
Expand All @@ -174,6 +170,8 @@ function HivemindSettings() {
setHivemindModule(mediaWikiHivemindModule);
setPlatforms(mediaWikiResults);
setIsActivePlatformLoading(false);
break;

default:
break;
}
Expand Down Expand Up @@ -341,14 +339,14 @@ function HivemindSettings() {

return (
<>
<div className='bg-gray-100 py-4 px-5'>
<div className='bg-gray-100 px-5 py-4'>
<Tabs
orientation='horizontal'
variant='scrollable'
value={activePlatform}
onChange={(event, newValue) => setActivePlatform(newValue)}
>
{Object.keys(IntegrationPlatform).map((platform, index) => (
{PLATFORM_ORDER.map((platform, index) => (
<Tab
className={clsx(
'mr-3 min-h-[6rem] min-w-[10rem] rounded-sm shadow-lg',
Expand All @@ -365,7 +363,7 @@ function HivemindSettings() {
<div className='flex flex-col items-center space-x-2'>
<TcCommunityPlatformIcon platform={platform} />
<TcText text={platform} variant='body2' />
{platform === 'GDrive' && (
{platform === IntegrationPlatform.GDrive && (
<TcText
variant='caption'
className='text-gray-300'
Expand All @@ -382,7 +380,7 @@ function HivemindSettings() {
))}
</Tabs>
</div>
<div className='bg-gray-100 py-4 px-5'>
<div className='bg-gray-100 px-5 py-4'>
{platforms && platforms.length > 0 ? (
<Tabs
orientation='horizontal'
Expand Down Expand Up @@ -476,23 +474,6 @@ function HivemindSettings() {
)}
{activePlatform === 1 && (
<TabPanel value={activePlatform} index={1}>
{platforms && platforms.length > 0 && (
<TcHivemindGoogle
defaultGoogleHivemindConfig={
hivemindModule?.options?.platforms.find(
(platform) => platform.name === 'google'
)?.metadata || { driveIds: [], folderIds: [], fileIds: [] }
}
handlePatchHivemindGoogle={(payload) =>
handlePatchModule('google', payload)
}
isLoading={loading}
/>
)}
</TabPanel>
)}
{activePlatform === 2 && (
<TabPanel value={activePlatform} index={2}>
{platforms && platforms.length > 0 && (
<TcHivemindGithub
defaultGithubHivemindConfig={
Expand All @@ -508,8 +489,8 @@ function HivemindSettings() {
)}
</TabPanel>
)}
{activePlatform === 3 && (
<TabPanel value={activePlatform} index={3}>
{activePlatform === 2 && (
<TabPanel value={activePlatform} index={2}>
{platforms && platforms.length > 0 && (
<TcHivemindNotion
isLoading={loading}
Expand All @@ -525,8 +506,8 @@ function HivemindSettings() {
)}
</TabPanel>
)}
{activePlatform === 4 && (
<TabPanel value={activePlatform} index={4}>
{activePlatform === 3 && (
<TabPanel value={activePlatform} index={3}>
{platforms && platforms.length > 0 && (
<TcHivemindMediaWiki
isLoading={loading}
Expand All @@ -542,6 +523,23 @@ function HivemindSettings() {
)}
</TabPanel>
)}
{activePlatform === 4 && (
<TabPanel value={activePlatform} index={4}>
{platforms && platforms.length > 0 && (
<TcHivemindGoogle
defaultGoogleHivemindConfig={
hivemindModule?.options?.platforms.find(
(platform) => platform.name === 'google'
)?.metadata || { driveIds: [], folderIds: [], fileIds: [] }
}
handlePatchHivemindGoogle={(payload) =>
handlePatchModule('google', payload)
}
isLoading={loading}
/>
)}
</TabPanel>
)}
</Paper>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { FaGoogleDrive } from 'react-icons/fa';
import { FaWikipediaW } from 'react-icons/fa';
import { FaGoogle } from 'react-icons/fa';
import { FaTelegram, FaTwitter } from 'react-icons/fa6';
import { FaSquareXTwitter } from "react-icons/fa6";
Comment on lines 9 to +10
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Clean up Twitter-related imports

Since Twitter has rebranded to X, we should clean up the imports and remove the unused Twitter icon.

-import { FaTelegram, FaTwitter } from 'react-icons/fa6';
+import { FaTelegram } from 'react-icons/fa6';
import { FaSquareXTwitter } from "react-icons/fa6";
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import { FaTelegram, FaTwitter } from 'react-icons/fa6';
import { FaSquareXTwitter } from "react-icons/fa6";
import { FaTelegram } from 'react-icons/fa6';
import { FaSquareXTwitter } from "react-icons/fa6";

import { RiNotionFill } from 'react-icons/ri';

interface TcCommunityPlatformIconProps {
Expand All @@ -24,6 +25,8 @@ function TcCommunityPlatformIcon({
return <FaDiscord size={size} />;
case 'Twitter':
return <FaTwitter size={size} />;
case 'X':
return <FaSquareXTwitter size={size} />;
case 'Discourse':
return <FaDiscourse size={size} />;
case 'Telegram':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ function TcCommunityPlatforms() {
const fetchPlatformsByType = async () => {
const platformNames = [
'discord',
'google',
'github',
'discourse',
'notion',
'mediaWiki',
'discourse',
'google',
Comment on lines 72 to +76
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Align platform order with IntegrationPlatform enum

The platform order in fetchPlatformsByType doesn't match the order defined in the IntegrationPlatform enum, which could lead to confusion and maintenance issues.

const platformNames = [
  'discord',
  'github',
  'discourse',
  'notion',
  'mediaWiki',
-  'google',
+  'gdrive',
];
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
'github',
'discourse',
'notion',
'mediaWiki',
'discourse',
'google',
'github',
'discourse',
'notion',
'mediaWiki',
'gdrive',

];

const platformName = platformNames[activeTab];
Expand Down Expand Up @@ -180,7 +180,7 @@ function TcCommunityPlatforms() {
return (
<div>
<Paper className='rounded-none bg-gray-100 p-4 shadow-none'>
<div className='flex flex-col space-y-3 md:flex-row md:items-center md:space-y-0 md:space-x-3'>
<div className='flex flex-col space-y-3 md:flex-row md:items-center md:space-x-3 md:space-y-0'>
<TcText text='Platforms' variant='h6' fontWeight='bold' />
<TcText text='Add/remove platform integrations' variant='body1' />
</div>
Expand Down Expand Up @@ -246,7 +246,7 @@ function TcCommunityPlatforms() {
)}
{activeTab === 1 && (
<TabPanel value={activeTab} index={1}>
<TcGdriveIntegration
<TcGithubIntegration
isLoading={isLoading}
connectedPlatforms={platforms}
handleUpdateCommunityPlatform={handleUpdateCommunityPlatform}
Expand All @@ -255,7 +255,7 @@ function TcCommunityPlatforms() {
)}
{activeTab === 2 && (
<TabPanel value={activeTab} index={2}>
<TcGithubIntegration
<TcDiscourse
isLoading={isLoading}
connectedPlatforms={platforms}
handleUpdateCommunityPlatform={handleUpdateCommunityPlatform}
Expand All @@ -282,7 +282,7 @@ function TcCommunityPlatforms() {
)}
{activeTab === 5 && (
<TabPanel value={activeTab} index={5}>
<TcDiscourse
<TcGdriveIntegration
isLoading={isLoading}
connectedPlatforms={platforms}
handleUpdateCommunityPlatform={handleUpdateCommunityPlatform}
Expand All @@ -292,15 +292,15 @@ function TcCommunityPlatforms() {
</Box>
</Paper>
<div className='py-4'>
<div className='flex flex-col space-y-3 md:flex-row md:items-center md:space-y-0 md:space-x-3'>
<div className='flex flex-col space-y-3 md:flex-row md:items-center md:space-x-3 md:space-y-0'>
<TcText text='Modules' variant='h6' fontWeight='bold' />
<TcText
text='Turn on/off modules and change their settings'
variant='body1'
/>
</div>

<div className='flex flex-col space-y-4 md:flex-row md:space-y-0 md:space-x-4'>
<div className='flex flex-col space-y-4 md:flex-row md:space-x-4 md:space-y-0'>
<TcCard
className='max-h-[6rem] min-h-[6rem] min-w-[10rem] max-w-[10rem] flex-grow'
children={
Expand Down
21 changes: 0 additions & 21 deletions src/components/global/SafaryClubScript.tsx

This file was deleted.

2 changes: 0 additions & 2 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import 'react-toastify/dist/ReactToastify.css';
import { wagmiConfig } from '@/rainbowKitConfig';

import AmplitudeAnalytics from '../components/global/AmplitudeAnalytics';
import SafaryClubScript from '../components/global/SafaryClubScript';
import { conf } from '../configs';
import { ChannelProvider } from '../context/ChannelContext';
import { TokenProvider } from '../context/TokenContext';
Expand All @@ -56,7 +55,6 @@ export default function App({ Component, pageProps }: ComponentWithPageLayout) {
return (
<>
<AmplitudeAnalytics />
<SafaryClubScript />
<Script id='tawk' strategy='lazyOnload'>
{`
var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
Expand Down
6 changes: 3 additions & 3 deletions src/utils/enums.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
export enum IntegrationPlatform {
Discord = 'Discord',
GDrive = 'GDrive',
Github = 'Github',
Discourse = 'Discourse',
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Platform order needs to be aligned with PLATFORM_ORDER

The enum order in src/utils/enums.ts doesn't match the order defined in PLATFORM_ORDER. To maintain consistency:

  • Move Discourse, Telegram, and X platforms after MediaWiki in the IntegrationPlatform enum to match the order in PLATFORM_ORDER
  • Current order in enum: Discord, Github, Discourse, Notion, MediaWiki, Telegram, X, Snapshot, GDrive
  • Expected order based on PLATFORM_ORDER: Discord, Github, Notion, MediaWiki, Discourse, Telegram, X

Note: The Discourse platform is actively used in the codebase and should not be removed, contrary to the initial concern in the AI summary.

🔗 Analysis chain

Verify the status and order of integration platforms

The changes to the IntegrationPlatform enum raise a few concerns:

  1. The presence of both Discourse and X platforms needs verification as the AI summary indicates Discourse was meant to be removed
  2. The platform order here might need to align with the PLATFORM_ORDER constant mentioned in the AI summary

Also applies to: 8-10


Let me verify the enum order and Discourse usage further by checking the complete enum definition and its usage across the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for PLATFORM_ORDER constant and Discourse platform usage
rg -A 5 "PLATFORM_ORDER\s*=" 
rg "case 'Discourse':" 

Length of output: 785


Script:

#!/bin/bash
# Get the complete IntegrationPlatform enum definition
ast-grep --pattern 'enum IntegrationPlatform {
  $$$
}'

# Check Discourse platform usage in the codebase
rg "IntegrationPlatform.Discourse" -A 2

Length of output: 876

Notion = 'Notion',
MediaWiki = 'MediaWiki',
Discourse = 'Discourse',
Twitter = 'Twitter',
Telegram = 'Telegram',
X = 'X',
Snapshot = 'Snapshot',
GDrive = 'GDrive',
}

export enum StatusCode {
Expand Down
Loading