Skip to content

Commit

Permalink
feat: remove account and unknown from context
Browse files Browse the repository at this point in the history
  • Loading branch information
LinaYahya committed Jan 11, 2024
1 parent 0eecfee commit cd7df10
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 50 deletions.
41 changes: 3 additions & 38 deletions src/components/context/DataProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,9 @@ import {
} from 'react';
import { useParams } from 'react-router-dom';

import {
Action,
Context,
DiscriminatedItem,
ItemType,
Member,
} from '@graasp/sdk';

import { DEFAULT_REQUEST_SAMPLE_SIZE } from '../../config/constants';
import { Action, DiscriminatedItem, ItemType, Member } from '@graasp/sdk';

import { Context, DEFAULT_REQUEST_SAMPLE_SIZE } from '../../config/constants';
import { hooks } from '../../config/queryClient';
import { ViewDataContext } from './ViewDataProvider';

Expand Down Expand Up @@ -63,7 +57,6 @@ const DataProvider = ({ children }: Props): JSX.Element => {
[Context.Builder]: false,
[Context.Player]: false,
[Context.Library]: false,
[Context.Unknown]: false,
});
const [actions, setActions] = useState<Action[]>([]);
const [allMembers, setAllMembers] = useState<Member[]>([]);
Expand Down Expand Up @@ -116,19 +109,6 @@ const DataProvider = ({ children }: Props): JSX.Element => {
{ enabled: Boolean(enabledArray[Context.Library]) },
);

const {
data: unknownData,
isError: unknownIsError,
isLoading: unknownIsLoading,
} = hooks.useActions(
{
itemId,
view: Context.Unknown,
requestedSampleSize,
},
{ enabled: Boolean(enabledArray[Context.Unknown]) },
);

const {
data: itemData,
isError: itemIsError,
Expand All @@ -151,16 +131,13 @@ const DataProvider = ({ children }: Props): JSX.Element => {
setIsLoading(playerIsLoading);
} else if (enabledArray[Context.Library]) {
setIsLoading(explorerIsLoading);
} else if (enabledArray[Context.Unknown]) {
setIsLoading(unknownIsLoading);
}
}, [
enabledArray,
itemIsLoading,
builderIsLoading,
playerIsLoading,
explorerIsLoading,
unknownIsLoading,
]);

useEffect(() => {
Expand Down Expand Up @@ -208,18 +185,6 @@ const DataProvider = ({ children }: Props): JSX.Element => {
}
}, [explorerData, view, actions, explorerIsError]);

useEffect(() => {
if (
unknownData &&
view === Context.Unknown &&
actions.length !== unknownData?.actions?.length
) {
setActions(unknownData?.actions ?? []);
setAllMembers(unknownData?.members ?? []);
setError(unknownIsError);
}
}, [unknownData, view, actions, unknownIsError]);

const value = useMemo(
() => ({
actions,
Expand Down
2 changes: 1 addition & 1 deletion src/components/context/ViewDataProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Dispatch, createContext, useMemo, useState } from 'react';

import { Context } from '@graasp/sdk';
import { Context } from '../../config/constants';

const defaultValue: {
// todo: use sdk context
Expand Down
3 changes: 1 addition & 2 deletions src/components/layout/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { useParams } from 'react-router-dom';

import { AppBar, Toolbar, Typography } from '@mui/material';

import { Context } from '@graasp/sdk';
import {
GraaspLogo,
Platform,
Expand All @@ -11,7 +10,7 @@ import {
usePlatformNavigation,
} from '@graasp/ui';

import { HOST_MAP } from '../../config/constants';
import { Context, HOST_MAP } from '../../config/constants';

export const platformsHostsMap = defaultHostsMapper({
[Platform.Builder]: HOST_MAP[Context.Builder],
Expand Down
3 changes: 1 addition & 2 deletions src/components/pages/ItemPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { useParams } from 'react-router-dom';
import { Box, Typography } from '@mui/material';
import { useTheme } from '@mui/material/styles';

import { Context } from '@graasp/sdk';
import {
GraaspLogo,
Main as GraaspMain,
Expand All @@ -13,7 +12,7 @@ import {
usePlatformNavigation,
} from '@graasp/ui';

import { HOST_MAP } from '../../config/constants';
import { Context, HOST_MAP } from '../../config/constants';
import ContextsWrapper from '../context/ContextsWrapper';
import CookiesBanner from '../layout/CookieBanner';
import Footer from '../layout/Footer';
Expand Down
6 changes: 1 addition & 5 deletions src/components/space/functionality/ViewSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import Grid from '@mui/material/Grid';
import Tooltip from '@mui/material/Tooltip';
import { styled } from '@mui/material/styles';

import { Context } from '@graasp/sdk';

import { Context } from '@/config/constants';
import { useAnalyticsTranslation } from '@/config/i18n';

import { ViewDataContext } from '../../context/ViewDataProvider';
Expand Down Expand Up @@ -44,9 +43,6 @@ const ViewSelect = (): JSX.Element => {
case Context.Library:
viewMessage = 'VIEW_LIBRARY_TOOLTIP';
break;
case Context.Unknown:
viewMessage = 'VIEW_UNKNOWN_TOOLTIP';
break;
default:
break;
}
Expand Down
8 changes: 6 additions & 2 deletions src/config/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { Context } from '@graasp/sdk';

import {
GRAASP_BUILDER_HOST,
GRAASP_LIBRARY_HOST,
Expand Down Expand Up @@ -68,6 +66,12 @@ export const TOP_NUMBER_OF_ITEMS_TO_DISPLAY = 10;

export const DEFAULT_REQUEST_SAMPLE_SIZE = 5000;

export enum Context {
Builder = 'builder',
Player = 'player',
Library = 'library',
Analytics = 'analytics',
}
export const HOST_MAP = {
[Context.Builder]: GRAASP_BUILDER_HOST,
[Context.Player]: GRAASP_PLAYER_HOST,
Expand Down

0 comments on commit cd7df10

Please sign in to comment.