-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
149 additions
and
152 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,74 @@ | ||
import React from 'react' | ||
import {AppBskyEmbedRecord} from '@atproto/api' | ||
|
||
export interface ComposerOptsPostRef { | ||
uri: string | ||
cid: string | ||
text: string | ||
author: { | ||
handle: string | ||
displayName?: string | ||
avatar?: string | ||
} | ||
} | ||
export interface ComposerOptsQuote { | ||
uri: string | ||
cid: string | ||
text: string | ||
indexedAt: string | ||
author: { | ||
did: string | ||
handle: string | ||
displayName?: string | ||
avatar?: string | ||
} | ||
embeds?: AppBskyEmbedRecord.ViewRecord['embeds'] | ||
} | ||
export interface ComposerOpts { | ||
replyTo?: ComposerOptsPostRef | ||
onPost?: () => void | ||
quote?: ComposerOptsQuote | ||
mention?: string // handle of user to mention | ||
} | ||
|
||
type StateContext = ComposerOpts | undefined | ||
type ControlsContext = { | ||
openComposer: (opts: ComposerOpts) => void | ||
closeComposer: () => void | ||
} | ||
|
||
const stateContext = React.createContext<StateContext>(undefined) | ||
const controlsContext = React.createContext<ControlsContext>({ | ||
openComposer(_opts: ComposerOpts) {}, | ||
closeComposer() {}, | ||
}) | ||
|
||
export function Provider({children}: React.PropsWithChildren<{}>) { | ||
const [state, setState] = React.useState<StateContext>() | ||
const api = React.useMemo( | ||
() => ({ | ||
openComposer(opts: ComposerOpts) { | ||
setState(opts) | ||
}, | ||
closeComposer() { | ||
setState(undefined) | ||
}, | ||
}), | ||
[setState], | ||
) | ||
return ( | ||
<stateContext.Provider value={state}> | ||
<controlsContext.Provider value={api}> | ||
{children} | ||
</controlsContext.Provider> | ||
</stateContext.Provider> | ||
) | ||
} | ||
|
||
export function useComposerState() { | ||
return React.useContext(stateContext) | ||
} | ||
|
||
export function useComposerControls() { | ||
return React.useContext(controlsContext) | ||
} |
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
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
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
Oops, something went wrong.