This repository has been archived by the owner on Dec 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Updating for use in both standalone and Flipper versions
BREAKING CHANGE: The ReactotronProvider has been renamed to ReactotronAppProvider and a new ReactotronProvider has been created serving a different function
- Loading branch information
Showing
35 changed files
with
2,057 additions
and
59 deletions.
There are no files selected for viewing
This file contains 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 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 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,15 @@ | ||
/* eslint-disable @typescript-eslint/no-empty-function */ | ||
import React from "react" | ||
import { MdReorder } from "react-icons/md" | ||
|
||
import EmptyState from "./index" | ||
|
||
export default { | ||
title: "Empty State", | ||
} | ||
|
||
export const Default = () => ( | ||
<EmptyState icon={MdReorder} title="Empty!"> | ||
Some more information | ||
</EmptyState> | ||
) |
This file contains 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,42 @@ | ||
import React, { FunctionComponent } from "react" | ||
import styled from "styled-components" | ||
|
||
const Container = styled.div` | ||
height: 100%; | ||
flex: 1; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
color: ${props => props.theme.foregroundLight}; | ||
` | ||
|
||
const Title = styled.div` | ||
font-size: 2rem; | ||
padding-bottom: 50px; | ||
padding-top: 10px; | ||
` | ||
|
||
const Message = styled.div` | ||
color: ${props => props.theme.foreground}; | ||
max-width: 400px; | ||
line-height: 1.4; | ||
text-align: center; | ||
` | ||
|
||
interface Props { | ||
icon?: any // TODO: Type Better? | ||
title: string | ||
} | ||
|
||
const EmptyState: FunctionComponent<Props> = ({ title, icon: Icon, children }) => { | ||
return ( | ||
<Container> | ||
{Icon && <Icon size={100} />} | ||
<Title>{title}</Title> | ||
<Message>{children}</Message> | ||
</Container> | ||
) | ||
} | ||
|
||
export default EmptyState |
This file contains 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 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,41 @@ | ||
import React, { FunctionComponent, useContext, useCallback } from "react" | ||
|
||
import ReactotronContext from "../Reactotron" | ||
|
||
import useCustomCommands, { CustomCommand } from "./useCustomCommands" | ||
|
||
interface Context { | ||
customCommands: CustomCommand[] | ||
sendCustomCommand: (command: any, args: any) => void | ||
} | ||
|
||
const CustomCommandsContext = React.createContext<Context>({ | ||
customCommands: [], | ||
sendCustomCommand: null, | ||
}) | ||
|
||
const Provider: FunctionComponent<any> = ({ children }) => { | ||
const { sendCommand } = useContext(ReactotronContext) | ||
const { customCommands } = useCustomCommands() | ||
|
||
const sendCustomCommand = useCallback( | ||
(command, args) => { | ||
sendCommand("custom", { command, args }) | ||
}, | ||
[sendCommand] | ||
) | ||
|
||
return ( | ||
<CustomCommandsContext.Provider | ||
value={{ | ||
customCommands, | ||
sendCustomCommand, | ||
}} | ||
> | ||
{children} | ||
</CustomCommandsContext.Provider> | ||
) | ||
} | ||
|
||
export default CustomCommandsContext | ||
export const CustomCommandsProvider = Provider |
This file contains 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,109 @@ | ||
/* eslint-disable react/display-name */ | ||
import React from "react" | ||
import { renderHook } from "@testing-library/react-hooks" | ||
|
||
import ReactotronContext from "../Reactotron" | ||
import { CommandType } from "../../types" | ||
|
||
import useCustomCommands from "./useCustomCommands" | ||
|
||
function buildContextValues({ addCommandListener = null } = {}) { | ||
return { | ||
commands: [], | ||
sendCommand: jest.fn(), | ||
clearCommands: jest.fn(), | ||
addCommandListener: addCommandListener || jest.fn(), | ||
isDispatchModalOpen: false, | ||
dispatchModalInitialAction: "", | ||
openDispatchModal: jest.fn(), | ||
closeDispatchModal: jest.fn(), | ||
isSubscriptionModalOpen: false, | ||
openSubscriptionModal: jest.fn(), | ||
closeSubscriptionModal: jest.fn(), | ||
} | ||
} | ||
|
||
describe("contexts/CustomCommands/useCustomCommands", () => { | ||
it("should add and remove custom commands", () => { | ||
let addCallback = null | ||
|
||
const contextValues = buildContextValues({ | ||
addCommandListener: callback => { | ||
addCallback = callback | ||
}, | ||
}) | ||
|
||
const { result } = renderHook(() => useCustomCommands(), { | ||
wrapper: ({ children }) => ( | ||
<ReactotronContext.Provider value={contextValues}>{children}</ReactotronContext.Provider> | ||
), | ||
}) | ||
|
||
expect(result.current.customCommands).toEqual([]) | ||
|
||
addCallback({ | ||
type: CommandType.CustomCommandRegister, | ||
clientId: "1234", | ||
payload: { | ||
id: 0, | ||
}, | ||
}) | ||
|
||
expect(result.current.customCommands).toEqual([ | ||
{ | ||
clientId: "1234", | ||
id: 0, | ||
}, | ||
]) | ||
|
||
addCallback({ | ||
type: CommandType.CustomCommandUnregister, | ||
clientId: "1234", | ||
payload: { | ||
id: 0, | ||
}, | ||
}) | ||
|
||
expect(result.current.customCommands).toEqual([]) | ||
}) | ||
|
||
it("should clear all commands after a reconnect", () => { | ||
let addCallback = null | ||
|
||
const contextValues = buildContextValues({ | ||
addCommandListener: callback => { | ||
addCallback = callback | ||
}, | ||
}) | ||
|
||
const { result } = renderHook(() => useCustomCommands(), { | ||
wrapper: ({ children }) => ( | ||
<ReactotronContext.Provider value={contextValues}>{children}</ReactotronContext.Provider> | ||
), | ||
}) | ||
|
||
expect(result.current.customCommands).toEqual([]) | ||
|
||
addCallback({ | ||
type: CommandType.CustomCommandRegister, | ||
clientId: "1234", | ||
payload: { | ||
id: 0, | ||
}, | ||
}) | ||
|
||
expect(result.current.customCommands).toEqual([ | ||
{ | ||
clientId: "1234", | ||
id: 0, | ||
}, | ||
]) | ||
|
||
addCallback({ | ||
type: CommandType.ClientIntro, | ||
clientId: "1234", | ||
}) | ||
|
||
expect(result.current.customCommands).toEqual([]) | ||
}) | ||
}) |
Oops, something went wrong.