Skip to content

Commit

Permalink
update hivemind ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdi-torabiv committed Dec 12, 2024
1 parent 61a76f3 commit cd7b332
Showing 1 changed file with 45 additions and 47 deletions.
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);
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

0 comments on commit cd7b332

Please sign in to comment.