Skip to content

Commit

Permalink
Merge pull request #24 from graasp/13/ws-refactor
Browse files Browse the repository at this point in the history
refactor: use integrated ws hooks API
  • Loading branch information
Alexandre Chau authored Aug 10, 2021
2 parents 84926fc + 62ee09b commit 49253df
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 28 deletions.
12 changes: 6 additions & 6 deletions cypress/integration/ws.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ describe('Websocket interactions', () => {
client.receive({
realm: 'notif',
type: 'update',
topic: 'item',
channel: parent.id,
body: {
entity: 'item',
kind: 'childItem',
kind: 'child',
op: 'create',
value: newChild,
item: newChild,
},
});

Expand All @@ -74,12 +74,12 @@ describe('Websocket interactions', () => {
client.receive({
realm: 'notif',
type: 'update',
topic: 'item',
channel: parent.id,
body: {
entity: 'item',
kind: 'childItem',
kind: 'child',
op: 'delete',
value: newChild,
item: newChild,
},
});

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@graasp/query-client": "git://github.com/graasp/graasp-query-client.git#35b96c40d668bbded90882c9b8a88cf15d747c09",
"@graasp/query-client": "git://github.com/graasp/graasp-query-client.git#main",
"@graasp/ui": "git://github.com/graasp/graasp-ui.git#41/rollup",
"@material-ui/core": "4.11.4",
"@material-ui/icons": "4.11.2",
Expand Down Expand Up @@ -72,7 +72,7 @@
"@commitlint/config-conventional": "^13.1.0",
"@cypress/code-coverage": "3.9.6",
"@cypress/instrument-cra": "1.4.0",
"@graasp/websockets": "git://github.com/graasp/graasp-websockets.git",
"@graasp/websockets": "git://github.com/graasp/graasp-websockets.git#master",
"@testing-library/jest-dom": "5.11.6",
"@testing-library/react": "11.2.2",
"@testing-library/user-event": "13.1.8",
Expand Down
4 changes: 2 additions & 2 deletions src/components/common/Item.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import Alert from '@material-ui/lab/Alert';
import { useTranslation } from 'react-i18next';
import PropTypes from 'prop-types';
import { hooks, ws } from '../../config/queryClient';
import { hooks } from '../../config/queryClient';
import { ITEM_TYPES } from '../../enums';
import FolderButton from './FolderButton';
import {
Expand Down Expand Up @@ -48,8 +48,8 @@ const Item = ({ id, isChildren }) => {
const isFolder = Boolean(item?.get('type') === ITEM_TYPES.FOLDER);
const { data: children, isLoading: isChildrenLoading } = useChildren(id, {
enabled: isFolder,
getUpdates: isFolder,
});
ws.hooks.useChildrenUpdates(isFolder ? id : null);

// fetch file content if type is file
const { data: content, isError: isFileError } = useFileContent(id, {
Expand Down
12 changes: 3 additions & 9 deletions src/components/common/MainMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
Loader,
} from '@graasp/ui';
import { buildTreeItemClass, MAIN_MENU_ID } from '../../config/selectors';
import { hooks, ws } from '../../config/queryClient';
import { hooks } from '../../config/queryClient';
import { ITEM_TYPES } from '../../enums';

const { useItem, useChildren } = hooks;
Expand All @@ -33,8 +33,8 @@ const MainMenu = () => {
isError: childrenIsError,
} = useChildren(rootId, {
enabled: isFolder,
getUpdates: isFolder,
});
ws.hooks.useChildrenUpdates(isFolder ? rootId : null);

// display nothing when no item is defined
if (!rootId) {
Expand All @@ -49,19 +49,13 @@ const MainMenu = () => {
return <Alert severity="error">{t('An unexpected error occured.')}</Alert>;
}

const useChildrenWithUpdates = (childId, ...args) => {
const ret = useChildren(childId, ...args);
ws.hooks.useChildrenUpdates(childId);
return ret;
};

return (
<GraaspMainMenu id={MAIN_MENU_ID}>
<DynamicTreeView
rootLabel={rootItem.get('name')}
rootId={rootId}
useItem={useItem}
useChildren={useChildrenWithUpdates}
useChildren={useChildren}
buildTreeItemClass={(nodeId) => buildTreeItemClass(nodeId)}
initialExpendedItems={[rootId]}
showCheckbox={false}
Expand Down
2 changes: 0 additions & 2 deletions src/config/queryClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const {
queryClient,
QueryClientProvider,
hooks,
ws,
useMutation,
ReactQueryDevtools,
} = configureQueryClient({
Expand All @@ -18,7 +17,6 @@ export {
queryClient,
QueryClientProvider,
hooks,
ws,
useMutation,
ReactQueryDevtools,
};
14 changes: 7 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2147,9 +2147,9 @@ __metadata:
languageName: node
linkType: hard

"@graasp/query-client@git://github.com/graasp/graasp-query-client.git#35b96c40d668bbded90882c9b8a88cf15d747c09":
"@graasp/query-client@git://github.com/graasp/graasp-query-client.git#main":
version: 0.1.0
resolution: "@graasp/query-client@git://github.com/graasp/graasp-query-client.git#commit=35b96c40d668bbded90882c9b8a88cf15d747c09"
resolution: "@graasp/query-client@git://github.com/graasp/graasp-query-client.git#commit=b7aa5e2e66d8e23152f55be894b1bfc6d0fd6fc1"
dependencies:
http-status-codes: 2.1.4
immutable: 4.0.0-rc.12
Expand All @@ -2160,7 +2160,7 @@ __metadata:
uuid: 8.3.2
peerDependencies:
react: ^17.0.0
checksum: c194a207703a7de9c97812f5cb4707373ae64078859dad16e6dc9fffa1718c1f317e0541dc47f4ee01034132204dde0fa175d32a027f6ee7a9c1ea4b4d534702
checksum: 53b9ca38abb73890dc6f0e91c9e936f52131556b0ff21ead9bc0d8e4fee5497eeba7e933c97da7c01b20e6e7a606470351760a4f93da85af8dcd8f8bd7013549
languageName: node
linkType: hard

Expand All @@ -2178,11 +2178,11 @@ __metadata:
"@material-ui/lab": 4.0.0-alpha.58
react: ^16.13.1
react-dom: 16.13.1
checksum: 93418bb4b34eaab44c8ac6aee1e751847c249879682f7b0e92b4c8a600f2cf485c9de0c0144c8ddb99aceb9347809a06bd755210c18b612c237d8383c02ebf77
checksum: a90e58ad39023ede26cc497b34bb56e31ccb60b245c58a7ee3b1cdf73da3f245ff5b335273872765f9b15ec11707467b62455f9e2140befcb181f1ccf7691b79
languageName: node
linkType: hard

"@graasp/websockets@git://github.com/graasp/graasp-websockets.git":
"@graasp/websockets@git://github.com/graasp/graasp-websockets.git#master":
version: 1.0.0
resolution: "@graasp/websockets@git://github.com/graasp/graasp-websockets.git#commit=64fe09b0529249282e476e03eaeedd0b5586e5f7"
dependencies:
Expand Down Expand Up @@ -9881,9 +9881,9 @@ fsevents@^1.2.7:
"@commitlint/config-conventional": ^13.1.0
"@cypress/code-coverage": 3.9.6
"@cypress/instrument-cra": 1.4.0
"@graasp/query-client": "git://github.com/graasp/graasp-query-client.git#35b96c40d668bbded90882c9b8a88cf15d747c09"
"@graasp/query-client": "git://github.com/graasp/graasp-query-client.git#main"
"@graasp/ui": "git://github.com/graasp/graasp-ui.git#41/rollup"
"@graasp/websockets": "git://github.com/graasp/graasp-websockets.git"
"@graasp/websockets": "git://github.com/graasp/graasp-websockets.git#master"
"@material-ui/core": 4.11.4
"@material-ui/icons": 4.11.2
"@material-ui/lab": 4.0.0-alpha.58
Expand Down

0 comments on commit 49253df

Please sign in to comment.