Skip to content

Commit 855407d

Browse files
πŸ”¨ Switch Header to use useOvermind (#3218)
* πŸ”¨ Switch Header to use useOvermind * Fix linting errors * fix header Co-authored-by: Sara Vieira <[email protected]>
1 parent 646977a commit 855407d

File tree

42 files changed

+292
-364
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+292
-364
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
export { useInterval } from './useInterval';
12
export { useScript } from './useScript';
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { useEffect, useRef } from 'react';
2+
3+
const noop = () => undefined;
4+
5+
export const useInterval = (callback: () => void, delay: number | null) => {
6+
const savedCallback = useRef<() => void>();
7+
8+
useEffect(() => {
9+
savedCallback.current = callback;
10+
}, [callback]);
11+
12+
useEffect(() => {
13+
if (delay !== null) {
14+
const tick = () => {
15+
if (savedCallback?.current) {
16+
savedCallback.current();
17+
}
18+
};
19+
20+
const interval = setInterval(tick, delay);
21+
22+
return () => clearInterval(interval);
23+
}
24+
25+
return noop;
26+
}, [delay]);
27+
};

β€Žpackages/app/src/app/pages/Sandbox/Editor/Header/Buttons/Action/Action.tsxβ€Ž

Lines changed: 0 additions & 98 deletions
This file was deleted.
Lines changed: 114 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,114 @@
1-
export { Action } from './Action';
1+
import Tooltip from '@codesandbox/common/lib/components/Tooltip';
2+
import React, { FunctionComponent } from 'react';
3+
4+
import {
5+
Title,
6+
Container,
7+
ActionLink,
8+
ActionA,
9+
ActionTooltip,
10+
IconContainer,
11+
MoreInfoIcon,
12+
} from './elements';
13+
import { ActionProps } from './types';
14+
15+
export const Action: FunctionComponent<ActionProps> = ({
16+
onClick,
17+
href,
18+
a,
19+
Icon,
20+
title,
21+
tooltip,
22+
highlight,
23+
placeholder,
24+
moreInfo,
25+
unresponsive,
26+
iconProps = {},
27+
iconContainerProps = {},
28+
children,
29+
...props
30+
}) => {
31+
if (!href && (placeholder || tooltip)) {
32+
return (
33+
<Container onClick={onClick} {...props}>
34+
<Tooltip content={placeholder || tooltip} hideOnClick={false}>
35+
<IconContainer {...iconContainerProps}>
36+
<Icon {...iconProps} />
37+
38+
{title !== undefined && <Title>{title}</Title>}
39+
40+
{moreInfo && <MoreInfoIcon />}
41+
</IconContainer>
42+
43+
{children}
44+
</Tooltip>
45+
</Container>
46+
);
47+
}
48+
49+
if (onClick) {
50+
return (
51+
<Container onClick={onClick} highlight={highlight} {...props}>
52+
<IconContainer {...iconContainerProps}>
53+
<Icon {...iconProps} />
54+
55+
{title !== undefined && <Title>{title}</Title>}
56+
57+
{moreInfo && <MoreInfoIcon />}
58+
</IconContainer>
59+
60+
{children}
61+
</Container>
62+
);
63+
}
64+
65+
if (href && a && (placeholder || tooltip)) {
66+
return (
67+
<ActionA href={href} target="_blank" rel="noopener noreferrer">
68+
<ActionTooltip content={placeholder || tooltip}>
69+
<IconContainer {...iconContainerProps}>
70+
<Icon {...iconProps} />
71+
72+
{title !== undefined && <Title>{title}</Title>}
73+
74+
{moreInfo && <MoreInfoIcon />}
75+
</IconContainer>
76+
</ActionTooltip>
77+
78+
{children}
79+
</ActionA>
80+
);
81+
}
82+
83+
if (href && (placeholder || tooltip)) {
84+
return (
85+
<ActionLink to={href} {...props}>
86+
<ActionTooltip content={placeholder || tooltip}>
87+
<IconContainer>
88+
<Icon {...iconProps} />
89+
90+
{title !== undefined && <Title>{title}</Title>}
91+
92+
{moreInfo && <MoreInfoIcon />}
93+
</IconContainer>
94+
</ActionTooltip>
95+
96+
{children}
97+
</ActionLink>
98+
);
99+
}
100+
101+
return (
102+
<ActionLink to={href} {...props}>
103+
<IconContainer {...iconContainerProps}>
104+
<Icon {...iconProps} />
105+
106+
{title !== undefined && <Title>{title}</Title>}
107+
108+
{moreInfo && <MoreInfoIcon />}
109+
</IconContainer>
110+
111+
{children}
112+
</ActionLink>
113+
);
114+
};

β€Žpackages/app/src/app/pages/Sandbox/Editor/Header/Buttons/Action/types.tsβ€Ž

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import { ComponentType } from 'react';
22

33
export type OptionProps = {
44
blink?: boolean;
@@ -20,6 +20,5 @@ export interface ActionProps {
2020
href?: string;
2121
a?: boolean;
2222
onClick?: () => void;
23-
children?: React.ReactNode;
24-
Icon: React.ComponentType;
23+
Icon: ComponentType;
2524
}

β€Žpackages/app/src/app/pages/Sandbox/Editor/Header/Buttons/ForkButton/elements.tsβ€Ž

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import styled from 'styled-components';
2-
import { default as BaseProgressButton } from '@codesandbox/common/lib/components/ProgressButton';
1+
import { default as ProgressButtonBase } from '@codesandbox/common/lib/components/ProgressButton';
32
import BaseForkIcon from 'react-icons/lib/go/repo-forked';
3+
import styled from 'styled-components';
44

5-
export const ProgressButton = styled(BaseProgressButton)`
5+
export const ProgressButton = styled(ProgressButtonBase)`
66
font-size: 0.75rem;
77
`;
88

β€Žpackages/app/src/app/pages/Sandbox/Editor/Header/Buttons/ForkButton/index.tsβ€Ž

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ export const ForkButton: FunctionComponent = () => {
1111
},
1212
state: {
1313
editor: {
14-
isForkingSandbox,
1514
currentSandbox: { owned },
15+
isForkingSandbox,
1616
},
1717
},
1818
} = useOvermind();

β€Žpackages/app/src/app/pages/Sandbox/Editor/Header/Buttons/LikeButton/index.tsβ€Ž

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
Β (0)