Skip to content

Commit

Permalink
chore(docs): add post action mods to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
stephancill committed Jan 24, 2024
1 parent eefd381 commit f6e256e
Show file tree
Hide file tree
Showing 4 changed files with 158 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/pages/integrate/creation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { CreationMod } from "@mod-protocol/react";
/>
```

if you want to support the user choosing between Mods, you can give them a UI to select a Mod, or use our component.
If you want to support the user choosing between Mods, you can give them a UI to select a Mod, or use our component.

## Full example with the Mod Editor

Expand Down
6 changes: 4 additions & 2 deletions docs/pages/integrate/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@ You can integrate as much or as little of Mod as you'd like, as Mod supports pro

You also have free choice of which Mods you want to support in your App. You can pick and choose from our open source ones, or even build and bring your own.

There are two kinds of Mods currently:
There are three kinds of Mods currently:

1. [Creation Mods](creation.mdx): Enable users to use Mods when creating a post, such as Mods for adding Gifs, Images, Videos, Polls or using AI.
You can integrate these with or without the Mod Editor, which is a great Farcaster cast creator with batteries included.
2. [Rich-embed Mods](rich-embeds.mdx): Turn urls into rich embeds, with a fallback to an open graph style card embed. These enable Images, Videos, Polls, Games, Minting NFTs,
or any other mini-interaction to happen directly in the interface.
You can integrate these with or without the Mod Metadata Cache.
3. [Post Action Mods](post-actions.mdx): Enable users to use Mods when interacting with posts, such as Mods for tipping, sharing, traslating or other mini-interactions that require the context of the post such as its author and contents.
You can integrate these with or without the Mod Metadata Cache.

## Support

Mod currently only has SDKs for React, and we're working on adding React-native support.

## Boilerplate starter

Fork the [Mod-starter repo](https://github.com/mod-protocol/mod-starter) to get started
Fork the [Mod-starter repo](https://github.com/mod-protocol/mod-starter) to get started
153 changes: 153 additions & 0 deletions docs/pages/integrate/post-actions.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
import Image from "next/image";

# Post Action Mods

Post Action Mods enable users to use Mods when interacting with posts, such as Mods for tipping, sharing, traslating or other mini-interactions that require the context of the post such as its author and contents.

Here's an example of where post action Mods will typically be used:

<Image
src="/post-action.png"
alt="Post Action Mod example"
width="400"
height="200"
/>

You can integrate Post Action Mods with or without our [Mod Metadata Cache](../metadata-cache.mdx).

## Integration Example

```tsx
import { ActionMod } from "@mod-protocol/react";

...

<ActionMod
input={text}
embeds={embeds}
api={API_URL}
variant="action"
manifest={currentMod}
renderers={renderers}
onOpenFileAction={handleOpenFile}
onExitAction={hideCurrentMod}
/>
```

## Full Example with Mod Search

```tsx
import { Embed, ModManifest, handleOpenFile } from "@mod-protocol/core";
import { actionMods, actionModsExperimental } from "@mod-protocol/mod-registry";
import { ActionMod } from "@mod-protocol/react";
import { ModsSearch } from "@mod-protocol/react-ui-shadcn/dist/components/creation-mods-search";
import { Button } from "@mod-protocol/react-ui-shadcn/dist/components/ui/button";
import {
Popover,
PopoverContent,
PopoverTrigger,
} from "@mod-protocol/react-ui-shadcn/dist/components/ui/popover";
import { renderers } from "@mod-protocol/react-ui-shadcn/dist/renderers";
import { KebabHorizontalIcon } from "@primer/octicons-react";
import React, { useMemo } from "react";
import { getAddress } from "viem";
import { useAccount } from "wagmi";
import { API_URL } from "./constants";
import { useExperimentalMods } from "./use-experimental-mods";
import { sendEthTransaction } from "./utils";

export function Actions({
author,
post,
}: {
author: {
farcaster: {
fid: string;
};
};
post: {
id: string;
text: string;
embeds: Embed[];
};
}) {
const experimentalMods = useExperimentalMods();
const [currentMod, setCurrentMod] = React.useState<ModManifest | null>(null);

const { address: unchecksummedAddress } = useAccount();
const checksummedAddress = React.useMemo(() => {
if (!unchecksummedAddress) return null;
return getAddress(unchecksummedAddress);
}, [unchecksummedAddress]);
const user = React.useMemo(() => {
return {
wallet: {
address: checksummedAddress,
},
};
}, [checksummedAddress]);

const onSendEthTransactionAction = useMemo(() => sendEthTransaction, []);

return (
<Popover
open={!!currentMod}
onOpenChange={(op: boolean) => {
if (!op) setCurrentMod(null);
}}
>
<PopoverTrigger></PopoverTrigger>
<ModsSearch
mods={experimentalMods ? actionModsExperimental : actionMods}
onSelect={setCurrentMod}
>
<Button variant="ghost" role="combobox" type="button">
<KebabHorizontalIcon></KebabHorizontalIcon>
</Button>
</ModsSearch>
<PopoverContent className="w-[400px] ml-2" align="start">
<div className="space-y-4">
<h4 className="font-medium leading-none">{currentMod?.name}</h4>
<hr />
<ActionMod
api={API_URL}
user={user}
variant="action"
manifest={currentMod}
renderers={renderers}
onOpenFileAction={handleOpenFile}
onExitAction={() => setCurrentMod(null)}
onSendEthTransactionAction={onSendEthTransactionAction}
author={author}
post={{
text: post.text,
embeds: post.embeds,
}}
/>
</div>
</PopoverContent>
</Popover>
);
}
```

This component can then be included in your post to allow it to be invoked by the user:

```tsx
...
<div className="ml-auto">
<Actions
post={{
id: props.cast.hash,
text: props.cast.text,
embeds: props.cast.embeds,
}}
author={{
farcaster: {
fid: props.cast.fid,
},
}}
/>
</div>
...
```
Binary file added docs/public/post-action.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f6e256e

Please sign in to comment.