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

fix: flickering on vote #594

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default [
},
...fixupConfigRules(
compat.extends(
"airbnb",
"airbnb",
"plugin:import/typescript", // this is needed because airbnb uses eslint-plugin-import
"prettier",
"plugin:cypress/recommended",
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@
"check": "concurrently --kill-others-on-fail -s all -n \"type-check,linter,prettier\" \"yarn type-check\" \"yarn lint\" \"yarn prettier:check\"",
"pre-commit": "concurrently --kill-others-on-fail -s all -n \"checks,tests\" \"yarn check\" \"yarn test\"",
"cypress:open": "env-cmd -f ./.env.test cypress open",
"test": "concurrently -k -s first -n \"test-server,cypress\" \"yarn start:test\" \"yarn test:ci\" ",
"test": "concurrently -k -s first -n \"test-server,cypress\" \"yarn start:test\" \"yarn test:ci\"",
"test:ci": "env-cmd -f ./.env.test cypress run --browser chrome --headless && nyc report --reporter=text --reporter=text-summary",
"unit-tests": "vitest",
"unit-tests": "vitest run",
"cov:report": "open ./coverage/lcov-report/index.html"
},
"devDependencies": {
Expand Down Expand Up @@ -114,7 +114,6 @@
"eslint": "9.12.0",
"eslint-config-airbnb": "19.0.4",
"eslint-config-prettier": "9.1.0",
"eslint-config-react-app": "7.0.1",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-cypress": "4.0.0",
"eslint-plugin-import": "2.31.0",
Expand All @@ -129,6 +128,7 @@
"nyc": "17.1.0",
"prettier": "3.3.3",
"pretty-quick": "4.0.0",
"react-devtools": "^6.0.1",
"stylis-plugin-rtl": "^2.1.1",
"uuid": "^10.0.0",
"vite": "^5.1.3",
Expand Down
137 changes: 0 additions & 137 deletions src/hooks/useActivityState.ts

This file was deleted.

24 changes: 15 additions & 9 deletions src/hooks/useAssistants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
promptForSingleResponse,
promptForSingleResponseAndProvideResponses,
} from '@/config/prompts';
import { mutations } from '@/config/queryClient';
import { hooks, mutations } from '@/config/queryClient';
import {
AssistantPersona,
AssistantType,
Expand All @@ -28,8 +28,8 @@ import {
ListAssistantStateData,
} from '@/interfaces/assistant';
import { ResponseVisibilityMode } from '@/interfaces/interactionProcess';
import { useActivityContext } from '@/modules/context/ActivityContext';
import { useAppDataContext } from '@/modules/context/AppDataContext';
import { useActivityStateContext } from '@/modules/context/ActivityStateContext';
import { useResponses } from '@/modules/context/ResponsesContext';
import { useSettings } from '@/modules/context/SettingsContext';

import { joinMultipleResponses } from './utils/responses';
Expand Down Expand Up @@ -62,18 +62,24 @@ const useAssistants = (): UseAssistantsValues => {
} = useSettings();

const { includeDetails, promptMode } = assistants;
const { postAppDataAsync, appData, patchAppDataAsync } = useAppDataContext();

const { data: appData } = hooks.useAppData();

const { mutateAsync: postAppDataAsync } = mutations.usePostAppData();
const { mutateAsync: patchAppDataAsync } = mutations.usePatchAppData();

const { mode, numberOfParticipantsResponsesTriggeringResponsesGeneration } =
activity;

const { assistantsResponsesSets, round, allResponses, postResponse } =
useActivityContext();
const { round } = useActivityStateContext();

const { assistantsResponsesSets, allResponses, postResponse } =
useResponses();

const listAssistantsStates = useMemo(
() =>
appData.filter(
(a) => a.type === AppDataTypes.ListAssistantState,
) as Array<ListAssistantStateAppData>,
(appData?.filter((a) => a.type === AppDataTypes.ListAssistantState) ??
[]) as Array<ListAssistantStateAppData>,
[appData],
);

Expand Down
13 changes: 13 additions & 0 deletions src/hooks/useInvalidateAppData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { useMemo } from 'react';

import { QUERY_KEYS, queryClient } from '@/config/queryClient';

const useInvalidateAppData = (): (() => void) => {
const invalidateAppData = useMemo(
() => () => queryClient.invalidateQueries(QUERY_KEYS.appDataKeys.all),
[],
);
return invalidateAppData;
};

export default useInvalidateAppData;
16 changes: 10 additions & 6 deletions src/hooks/usePrompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { AppData, AppDataVisibility, PermissionLevel } from '@graasp/sdk';

import { AppDataTypes, PromptsAppData } from '@/config/appDataTypes';
import { CATEGORY_COLORS } from '@/config/constants';
import { hooks, mutations } from '@/config/queryClient';
import whatIfs from '@/config/what-ifs.json';
import { FullPromptCategory, Prompt, PromptsData } from '@/interfaces/prompt';
import { useAppDataContext } from '@/modules/context/AppDataContext';
import { useSettings } from '@/modules/context/SettingsContext';
import { getRandomInteger } from '@/utils/utils';

Expand All @@ -25,8 +25,12 @@ interface UsePromptsValues extends Partial<PromptsData> {
}

const usePrompts = (): UsePromptsValues => {
const { appData, postAppData, patchAppData, deleteAppData } =
useAppDataContext();
const { data: appData } = hooks.useAppData();

const { mutate: postAppData } = mutations.usePostAppData();
const { mutate: deleteAppData } = mutations.useDeleteAppData();
const { mutate: patchAppData } = mutations.usePatchAppData();

const { accountId, permission } = useLocalContext();

const { postRequestPromptAction } = useActions();
Expand Down Expand Up @@ -62,7 +66,7 @@ const usePrompts = (): UsePromptsValues => {
);

useEffect(() => {
const promptsAppData = appData.find(
const promptsAppData = appData?.find(
({ type, creator }) =>
type === AppDataTypes.Prompts && accountId === creator?.id,
) as PromptsAppData;
Expand Down Expand Up @@ -122,9 +126,9 @@ const usePrompts = (): UsePromptsValues => {
'You must be admin to delete all prompts data for all users.',
);
} else {
const allIds = appData.filter(
const allIds = (appData?.filter(
({ type }) => type === AppDataTypes.Prompts,
) as Array<PromptsAppData>;
) ?? []) as Array<PromptsAppData>;
allIds.forEach(({ id }) => deleteAppData({ id }));
}
};
Expand Down
Loading
Loading