-
Notifications
You must be signed in to change notification settings - Fork 2.4k
🔨 Hooks Refactor #1925
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
Closed
Closed
🔨 Hooks Refactor #1925
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
d19db56
🔨 Add useScript Hook, Refactor Advertisement to use useScript
Saeris dba78f5
Correct Comment Link
Saeris 22cd817
🔨 Add useScript Hook, Refactor Advertisement to use useScript
Saeris 1c87bff
Merge remote-tracking branch 'origin/code-conventions-refactor' into …
Saeris d88957c
🔨 Add mobx-react-lite, Refactor ConnectionNotice to use hooks
Saeris a5966a5
Remove analytic for deleting
CompuIves 3c0bf1a
Just added iOS Touch icons for the PWA (#1936)
twhite96 fac7134
[Dashboard] Keep sidebar open when search input is focused (#1937)
abdullahtariq1171 5d95e25
Refactor Cube to functional component with hooks (#1939)
MichaelDeBoey 48c5d5d
Fix modules that declare a global variable
CompuIves 101f04b
Remove performance statement
CompuIves 49c8a09
🔨 Add useScript Hook, Refactor Advertisement to use useScript
Saeris a4523a0
Correct Comment Link
Saeris 37edbc4
🔨 Add mobx-react-lite, Refactor ConnectionNotice to use hooks
Saeris 519b214
🔨 Add useInterval Hook, Refactor Live, SSEDownNotice
Saeris a304dac
Merge remote-tracking branch 'origin/code-conventions-refactor' into …
Saeris e05aa29
Auto stash before merge of "code-conventions-refactor" and "origin/co…
Saeris 1212065
🔨 Refactor GitHub Workspace to use hooks
Saeris 4ca14c6
Update packages/app/src/app/pages/Dashboard/index.js
Saeris 9afad2b
🔨 Refactor Deployment Workspace to use hooks
Saeris fca1605
🔨 Refactor More Workspace to use hooks
Saeris 2c0a836
🔨 Apply coding conventions to NotOwnedSandboxInfo Workspace
Saeris File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| export { useInterval } from './useInterval'; | ||
| export { useScript } from './useScript'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| // Based on https://overreacted.io/making-setinterval-declarative-with-react-hooks/ | ||
| import { useEffect, useRef } from 'react'; | ||
|
|
||
| export const useInterval = (callback = () => {}, delay: number) => { | ||
| const savedCallback: { current: any } = useRef(); | ||
Saeris marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| useEffect(() => { | ||
| savedCallback.current = callback; | ||
| }, [callback]); | ||
|
|
||
| useEffect(() => { | ||
| function tick() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be an arrow function const tick = () => savedCallback.current(); |
||
| savedCallback.current(); | ||
| } | ||
| if (delay !== null) { | ||
| const id = setInterval(tick, delay); | ||
| return () => clearInterval(id); | ||
| } | ||
| return undefined; | ||
Saeris marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, [delay]); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| // Based on https://usehooks.com/useScript/ | ||
| import { useState, useEffect } from 'react'; | ||
|
|
||
| const cachedScripts = []; | ||
|
|
||
| export const useScript = (src: string) => { | ||
| const [state, setState] = useState({ | ||
| loaded: false, | ||
| error: false, | ||
| }); | ||
|
|
||
| useEffect(() => { | ||
| if (cachedScripts.includes(src)) { | ||
| setState({ | ||
| loaded: true, | ||
| error: false, | ||
| }); | ||
| } else { | ||
| cachedScripts.push(src); | ||
|
|
||
| const script = document.createElement('script'); | ||
Saeris marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| script.src = src; | ||
| script.async = true; | ||
|
|
||
| const onScriptLoad = () => { | ||
| setState({ | ||
| loaded: true, | ||
| error: false, | ||
| }); | ||
| }; | ||
|
|
||
| const onScriptError = () => { | ||
| const index = cachedScripts.indexOf(src); | ||
|
|
||
| if (index >= 0) cachedScripts.splice(index, 1); | ||
Saeris marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| script.remove(); | ||
|
|
||
| setState({ | ||
| loaded: true, | ||
| error: true, | ||
| }); | ||
| }; | ||
|
|
||
| script.addEventListener('load', onScriptLoad); | ||
| script.addEventListener('error', onScriptError); | ||
|
|
||
| document.body.appendChild(script); | ||
|
|
||
| return () => { | ||
| script.removeEventListener('load', onScriptLoad); | ||
| script.removeEventListener('error', onScriptError); | ||
| }; | ||
Saeris marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| return undefined; | ||
Saeris marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, [src]); | ||
|
|
||
| return [state.loaded, state.error]; | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
packages/app/src/app/pages/Sandbox/Editor/Workspace/Advertisement/Advertisement.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import React from 'react'; | ||
| import { useScript } from 'app/hooks'; | ||
| import { Container } from './elements'; | ||
|
|
||
| export const Advertisement = () => { | ||
| useScript(`https://codefund.app/properties/24/funder.js`); | ||
Saeris marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return ( | ||
| <Container> | ||
| <div id="codefund" /> | ||
| </Container> | ||
| ); | ||
| }; | ||
36 changes: 0 additions & 36 deletions
36
packages/app/src/app/pages/Sandbox/Editor/Workspace/Advertisement/CodeFund.js
This file was deleted.
Oops, something went wrong.
29 changes: 0 additions & 29 deletions
29
packages/app/src/app/pages/Sandbox/Editor/Workspace/Advertisement/elements.js
This file was deleted.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
packages/app/src/app/pages/Sandbox/Editor/Workspace/Advertisement/elements.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import styled, { css } from 'styled-components'; | ||
|
|
||
| export const Container = styled.div` | ||
| ${({ theme }) => css` | ||
| color: ${theme.light | ||
| ? css`rgba(0, 0, 0, 0.8)` | ||
| : css`rgba(255, 255, 255, 0.8)`} !important; | ||
| `}; | ||
| `; |
5 changes: 0 additions & 5 deletions
5
packages/app/src/app/pages/Sandbox/Editor/Workspace/Advertisement/index.js
This file was deleted.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
packages/app/src/app/pages/Sandbox/Editor/Workspace/Advertisement/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { Advertisement } from './Advertisement'; |
14 changes: 7 additions & 7 deletions
14
...ditor/Workspace/ConnectionNotice/index.js → ...ace/ConnectionNotice/ConnectionNotice.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,18 @@ | ||
| import React from 'react'; | ||
| import { inject, observer } from 'mobx-react'; | ||
|
|
||
| import { observer } from 'mobx-react-lite'; | ||
| import { useStore } from 'app/store'; | ||
| import { Container } from './elements'; | ||
|
|
||
| function ConnectionNotice({ store }) { | ||
| export const ConnectionNotice = observer(() => { | ||
| const { connected } = useStore(); | ||
|
|
||
| return ( | ||
| !store.connected && ( | ||
| !connected && ( | ||
| <Container> | ||
| You{"'"}re not connected to the internet. You can still edit, but you | ||
| cannot save. We recommend using the {"'"}Download{"'"} function to keep | ||
| your changes. | ||
| </Container> | ||
| ) | ||
| ); | ||
| } | ||
|
|
||
| export default inject('store')(observer(ConnectionNotice)); | ||
| }); |
8 changes: 0 additions & 8 deletions
8
packages/app/src/app/pages/Sandbox/Editor/Workspace/ConnectionNotice/elements.js
This file was deleted.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
packages/app/src/app/pages/Sandbox/Editor/Workspace/ConnectionNotice/elements.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import styled, { css } from 'styled-components'; | ||
|
|
||
| export const Container = styled.div` | ||
| ${({ theme }) => css` | ||
| color: ${theme.red}; | ||
| background-color: ${theme.redBackground}; | ||
| padding: 1rem; | ||
| font-size: 0.75rem; | ||
| `} | ||
| `; |
1 change: 1 addition & 0 deletions
1
packages/app/src/app/pages/Sandbox/Editor/Workspace/ConnectionNotice/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { ConnectionNotice } from './ConnectionNotice'; |
7 changes: 0 additions & 7 deletions
7
packages/app/src/app/pages/Sandbox/Editor/Workspace/CreateRepo/elements.js
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.