Skip to content

Commit

Permalink
fix: remove code smells
Browse files Browse the repository at this point in the history
  • Loading branch information
spaenleh committed Nov 27, 2024
1 parent b6e37f9 commit af9b08b
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 40 deletions.
16 changes: 7 additions & 9 deletions cypress/e2e/account/settings/publicProfile.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,13 @@ describe('Edit public profile', () => {
],
},
].forEach(({ platform, urls }) => {
describe(platform, () => {
urls.forEach((url) =>
it(url, () => {
cy.get(`input[name=${platform}]`).clear();
cy.get(`input[name=${platform}]`).type(url);
cy.get(`#${PUBLIC_PROFILE_SAVE_BUTTON_ID}`).should('be.disabled');
}),
);
});
urls.forEach((url) =>
it(url, () => {
cy.get(`input[name=${platform}]`).clear();
cy.get(`input[name=${platform}]`).type(url);
cy.get(`#${PUBLIC_PROFILE_SAVE_BUTTON_ID}`).should('be.disabled');
}),
);
});

Object.values(SocialProfile).forEach((platform) => {
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/player/shuffle.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { buildContentPagePath, expectFolderLayout } from './utils';

export const TREE_NODE_GROUP_CLASS = 'tree-node-group';

// todo: shuffling order is dependent on member Id and item Id, which can change.
// Warning: shuffling order is dependent on member Id and item Id, which can change.
// re-enable this test once we can compute the order in advance without it depending on specific ids.
describe.skip('Shuffle', () => {
describe('Anna', () => {
Expand Down
11 changes: 4 additions & 7 deletions cypress/e2e/player/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,10 @@ const {

export class TestHelper {
private isLoggedIn: boolean = false;
private hasAccessToItem: boolean = true;

private pseudoMember: CompleteGuest;

private item: DiscriminatedItem;

private returnItemLoginSchemaType: boolean = true;
private readonly hasAccessToItem: boolean = true;
private readonly pseudoMember: CompleteGuest;
private readonly item: DiscriminatedItem;
private readonly returnItemLoginSchemaType: boolean = true;

constructor(args: {
pseudoMember: CompleteGuest;
Expand Down
11 changes: 5 additions & 6 deletions cypress/support/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
ChatMessage,
CompleteMember,
HttpMethod,
ItemGeolocation,
Member,
PublicProfile,
getIdsFromPath,
Expand Down Expand Up @@ -417,12 +418,10 @@ export const mockGetAccessibleItems = (items: MockItem[]): void => {
const page = parseInt(params.get('page') ?? '1', 10);
const pageSize = parseInt(params.get('pageSize') ?? '10', 10);

// as { page: number; pageSize: number };

// warning: we don't check memberships
const root = items.filter(isRootItem);

// todo: filter
// improvement: apply requested filters

const result = root.slice((page - 1) * pageSize, page * pageSize);

Expand Down Expand Up @@ -700,7 +699,7 @@ export const mockGetLoginSchemaType = (itemLogins: {
({ reply, url }) => {
const itemId = url.slice(API_HOST.length).split('/')[2];

// todo: add response for itemLoginSchemaType
// improvement: add response for itemLoginSchemaType
const itemLogin = itemLogins[itemId];

if (itemLogin) {
Expand Down Expand Up @@ -859,10 +858,10 @@ export const mockGetItemGeolocation = (items: MockItem[]): void => {
const geolocs = items
.filter((i) => parentIds.includes(i.id))
.filter(Boolean)
.map((i) => i.geolocation);
.map((i) => i.geolocation) as Partial<ItemGeolocation>[];

if (geolocs.length) {
return reply(geolocs[0]!);
return reply(geolocs[0]);
}

return reply({ statusCode: StatusCodes.NOT_FOUND });
Expand Down
3 changes: 1 addition & 2 deletions cypress/support/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CompleteMember } from '@graasp/sdk';
import {
ChatMessage,
CompleteMember,
Member,
PermissionLevel,
PermissionLevelCompare,
Expand All @@ -13,7 +13,6 @@ import { MockItem } from '../fixtures/mockTypes';

export const ID_FORMAT = '(?=.*[0-9])(?=.*[a-zA-Z])([a-z0-9-]+)';

// TODO: not ideal, to change?
export type MemberForTest = CompleteMember & { thumbnail?: string };
export const getDataCy = (dataCy: string): string => `[data-cy="${dataCy}"]`;
export const buildDataCySelector = (
Expand Down
3 changes: 1 addition & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta name="description" content="Graasp Account" />
<meta name="description" content="Graasp" />
<meta
name="version-info"
content="%VITE_VERSION% @ %VITE_BUILD_TIMESTAMP%"
/>
<!-- <link rel="icon" type="image/svg+xml" href="/graasp.svg?v=1" /> -->

<link
rel="apple-touch-icon"
Expand Down
39 changes: 27 additions & 12 deletions src/AuthContext.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { ReactNode, createContext, useCallback, useContext } from 'react';
import {
ReactNode,
createContext,
useCallback,
useContext,
useMemo,
} from 'react';

import { AccountType, getCurrentAccountLang } from '@graasp/sdk';
import { DEFAULT_LANG } from '@graasp/translations';
Expand Down Expand Up @@ -38,9 +44,9 @@ const AuthContext = createContext<AuthContextType | null>(null);

export function AuthProvider({
children,
}: {
}: Readonly<{
children: ReactNode;
}): JSX.Element {
}>): JSX.Element {
const { data: currentMember, isLoading } = hooks.useCurrentMember();

const useLogin = mutations.useSignIn();
Expand All @@ -57,13 +63,9 @@ export function AuthProvider({
[useLogin],
);

// if the query has not resolved yet, we can not render the rest of the tree
if (isLoading) {
return <CustomInitialLoader />;
}

const value = currentMember
? {
const value = useMemo(() => {
if (currentMember) {
return {
isAuthenticated: true as const,
user: {
name: currentMember.name,
Expand All @@ -73,8 +75,21 @@ export function AuthProvider({
},
logout,
login: null,
}
: { isAuthenticated: false as const, user: null, login, logout: null };
};
} else {
return {
isAuthenticated: false as const,
user: null,
login,
logout: null,
};
}
}, [currentMember, login, logout]);

// if the query has not resolved yet, we can not render the rest of the tree
if (isLoading) {
return <CustomInitialLoader />;
}

return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>;
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/ConstructionTruck.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type ConstructionTruckProps = {
};
export function ConstructionTruck({
size,
}: ConstructionTruckProps): JSX.Element {
}: Readonly<ConstructionTruckProps>): JSX.Element {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
Expand Down

0 comments on commit af9b08b

Please sign in to comment.