Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
5ee0bef
consoleStyles: update to ts, no verify
clairep94 Jan 10, 2026
2c3f3d9
add .svg?byContent and .svg?byUrl to custom types
clairep94 Jan 10, 2026
7445aec
consoleStyles: resolve type errors & update to named export
clairep94 Jan 10, 2026
2413816
hooks/index: update to ts
clairep94 Jan 10, 2026
3dbcf68
hooks/useWhatPage: update to ts, no-verify
clairep94 Jan 10, 2026
f6fb4c4
hooks/useWhatPage: update to named export & resolve type errors
clairep94 Jan 10, 2026
d6538ca
hooks/useIsMobile: update to ts, no-verify
clairep94 Jan 10, 2026
66ddcb7
hooks/useIsMobile: update to named export & resolve type errors
clairep94 Jan 10, 2026
164ce98
hooks/custom-hooks: update to ts, no-verify
clairep94 Jan 10, 2026
f8ceb97
hooks/custom-hooks: delete unused hooks, resolve type errors
clairep94 Jan 10, 2026
b897501
hooks/custom-hooks: update file to useDidUpdate
clairep94 Jan 10, 2026
0f40933
IDE/hooks/useInterval: update to ts, no-verify
clairep94 Jan 10, 2026
17a18c2
IDE/hooks/useInterval: update to named export and resolve type errors
clairep94 Jan 10, 2026
515f2ca
hooks/useIsMobile: add types for react-responsive
clairep94 Jan 10, 2026
e22ae36
hooks/useDidUpdate: minor cleanup
clairep94 Jan 10, 2026
218ad0f
hooks/useP5Version: update to ts, no-verify
clairep94 Jan 10, 2026
3164d15
hooks/useP5Versions: resolve type errors
clairep94 Jan 10, 2026
814d9d7
hooks/useSketchActions: update to ts, no-verify
clairep94 Jan 10, 2026
3c5a071
hooks/useSketchActions: update to named export, resolve type errors
clairep94 Jan 10, 2026
f2e0d88
hooks/useSketchActions: memoise methods
clairep94 Jan 10, 2026
ad4cdc0
hooks/useHandleMessageEvent: update to ts, no-verify
clairep94 Jan 10, 2026
04e839a
hooks/useHandleMessageEvent: resolve type errors, add Message type fr…
clairep94 Jan 10, 2026
7173565
IDE/hooks/useP5Version: correct the context type definition
clairep94 Jan 10, 2026
28b9b8c
resolve type errors
clairep94 Jan 18, 2026
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 client/components/Dropdown/TableDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {

import DownFilledTriangleIcon from '../../images/down-filled-triangle.svg';
import MoreIconSvg from '../../images/more.svg';
import useIsMobile from '../../modules/IDE/hooks/useIsMobile';
import { useIsMobile } from '../../modules/IDE/hooks';

const DotsHorizontal = styled(MoreIconSvg)`
transform: rotate(90deg);
Expand Down
12 changes: 12 additions & 0 deletions client/custom.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
declare module '*.svg?byUrl' {
const url: string;
// eslint-disable-next-line import/no-default-export
export default url;
}

declare module '*.svg?byContent' {
const content: string;
// eslint-disable-next-line import/no-default-export
export default content;
}

declare module '*.svg' {
import * as React from 'react';

Expand Down
5 changes: 2 additions & 3 deletions client/modules/IDE/components/Console.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ import DownArrowIcon from '../../../images/down-arrow.svg';

import * as IDEActions from '../actions/ide';
import * as ConsoleActions from '../actions/console';
import { useDidUpdate } from '../hooks/custom-hooks';
import useHandleMessageEvent from '../hooks/useHandleMessageEvent';
import { useDidUpdate, useHandleMessageEvent } from '../hooks';
import { listen } from '../../../utils/dispatcher';
import getConsoleFeedStyle from '../utils/consoleStyles';
import { getConsoleFeedStyle } from '../utils/consoleStyles';

const Console = () => {
const { t } = useTranslation();
Expand Down
2 changes: 1 addition & 1 deletion client/modules/IDE/components/Header/Nav.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
import { logoutUser } from '../../../User/actions';
import { CmControllerContext } from '../../pages/IDEView';
import MobileNav from './MobileNav';
import useIsMobile from '../../hooks/useIsMobile';
import { useIsMobile } from '../../hooks';

const Nav = ({ layout }) => {
const isMobile = useIsMobile();
Expand Down
8 changes: 7 additions & 1 deletion client/modules/IDE/components/Header/Toolbar.unit.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from '../../../../test-utils';
import { selectProjectName } from '../../selectors/project';
import ToolbarComponent from './Toolbar';
import { P5VersionProvider } from '../../hooks/useP5Version';

const server = setupServer(
rest.put(`/projects/id`, (req, res, ctx) => res(ctx.json(req.body)))
Expand Down Expand Up @@ -49,7 +50,12 @@ const renderComponent = (extraState = {}) => {

return {
...props,
...reduxRender(<ToolbarComponent {...props} />, { initialState })
...reduxRender(
<P5VersionProvider>
<ToolbarComponent {...props} />
</P5VersionProvider>,
{ initialState }
)
};
};

Expand Down
2 changes: 1 addition & 1 deletion client/modules/IDE/components/Header/index.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import { useSelector } from 'react-redux';
import useIsMobile from '../../hooks/useIsMobile';
import { useIsMobile } from '../../hooks';

import Nav from './Nav';
import Toolbar from './Toolbar';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { act, fireEvent, reduxRender, screen } from '../../../../test-utils';
import { initialState } from '../../reducers/preferences';
import Preferences from './index';
import * as PreferencesActions from '../../actions/preferences';
import { P5VersionProvider } from '../../hooks/useP5Version';

describe('<Preferences />', () => {
// For backwards compatibility, spy on each action creator to see when it was dispatched.
Expand All @@ -14,14 +15,19 @@ describe('<Preferences />', () => {
);

const subject = (initialPreferences = {}) =>
reduxRender(<Preferences />, {
initialState: {
preferences: {
...initialState,
...initialPreferences
reduxRender(
<P5VersionProvider>
<Preferences />
</P5VersionProvider>,
{
initialState: {
preferences: {
...initialState,
...initialPreferences
}
}
}
});
);

afterEach(() => {
jest.clearAllMocks();
Expand Down
2 changes: 1 addition & 1 deletion client/modules/IDE/components/Timer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useTranslation } from 'react-i18next';
import { useSelector } from 'react-redux';

import { distanceInWordsToNow } from '../../../utils/formatDate';
import useInterval from '../hooks/useInterval';
import { useInterval } from '../hooks/useInterval';
import { getIsUserOwner } from '../selectors/users';

const Timer = () => {
Expand Down
70 changes: 0 additions & 70 deletions client/modules/IDE/hooks/custom-hooks.js

This file was deleted.

2 changes: 0 additions & 2 deletions client/modules/IDE/hooks/index.js

This file was deleted.

6 changes: 6 additions & 0 deletions client/modules/IDE/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export * from './useSketchActions';
export * from './useWhatPage';
export * from './useIsMobile';
export * from './useDidUpdate';
export * from './useInterval';
export * from './useHandleMessageEvent';
16 changes: 16 additions & 0 deletions client/modules/IDE/hooks/useDidUpdate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React, { useEffect, useRef } from 'react';

export const useDidUpdate = (
callback: () => void,
deps: React.DependencyList = []
) => {
const hasMount = useRef(false);

useEffect(() => {
if (hasMount.current) {
callback();
} else {
hasMount.current = true;
}
}, deps);
};
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
import { useDispatch } from 'react-redux';
import { Decode } from 'console-feed';
import { Message } from 'console-feed/lib/definitions/Console';
import { dispatchConsoleEvent } from '../actions/console';
import { stopSketch, expandConsole } from '../actions/ide';

export default function useHandleMessageEvent() {
type SafeValue = string | number | boolean | null | SafeObject | SafeArray;
interface SafeObject {
[key: string]: SafeValue;
}
interface SafeArray extends Array<SafeValue> {}

export function useHandleMessageEvent() {
const dispatch = useDispatch();

const safeStringify = (
obj,
obj: unknown,
depth = 0,
maxDepth = 10,
seen = new WeakMap()
) => {
if (typeof obj !== 'object' || obj === null) return obj;
seen = new WeakMap<object, boolean>()
): SafeValue => {
if (typeof obj !== 'object' || obj === null) return obj as SafeValue;

if (depth >= maxDepth) {
if (seen.has(obj)) return '[Circular Reference]';
Expand All @@ -30,9 +37,13 @@ export default function useHandleMessageEvent() {
);
};

const handleMessageEvent = (data) => {
const handleMessageEvent = (data: Message['data']) => {
if (!data || typeof data !== 'object') return;
const { source, messages } = data;

const { source, messages } = data as {
source?: string;
messages?: { log?: unknown }[];
};
if (source !== 'sketch' || !Array.isArray(messages)) return;

const decodedMessages = messages.map((message) => {
Expand All @@ -48,8 +59,8 @@ export default function useHandleMessageEvent() {
// Detect infinite loop warnings
const hasInfiniteLoop = decodedMessages.some(
(message) =>
message?.data &&
Object.values(message.data).some(
(message as SafeObject)?.data &&
Object.values((message as SafeObject)?.data as SafeObject).some(
(arg) =>
typeof arg === 'string' &&
arg.includes('Exiting potential infinite loop')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
// https://overreacted.io/making-setinterval-declarative-with-react-hooks/
import { useState, useEffect, useRef } from 'react';

export default function useInterval(callback, delay) {
const savedCallback = useRef();
const [intervalId, setIntervalId] = useState();
export function useInterval(callback: () => void, delay: number) {
const savedCallback = useRef<() => void>();
const [intervalId, setIntervalId] = useState<
ReturnType<typeof setInterval>
>();

// Remember the latest callback.
useEffect(() => {
savedCallback.current = callback;
}, [callback]);

// Set up the interval.
// eslint-disable-next-line consistent-return
useEffect(() => {
function tick() {
savedCallback.current();
if (savedCallback.current) {
savedCallback.current();
}
}
if (delay !== null) {
const id = setInterval(tick, delay);
setIntervalId(id);
return () => clearInterval(id);
}
return null;
}, [delay]);
return () => clearInterval(intervalId);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { useMediaQuery } from 'react-responsive';

const useIsMobile = (customBreakpoint) => {
export const useIsMobile = (customBreakpoint?: number): boolean => {
const breakPoint = customBreakpoint || 770;
const isMobile = useMediaQuery({ maxWidth: breakPoint });
return isMobile;
};

export default useIsMobile;
Loading