hero-org / herocast

herocast is Farcaster’s leading open-source client. Our goal is to decentralize power on the internet, faster.
https://app.herocast.xyz
GNU Affero General Public License v3.0
63 stars 29 forks source link

Compose cast text query parameter #244

Open 0xSemicolon opened 6 months ago

0xSemicolon commented 6 months ago

It's not possible to prompt for a cast template like you can in warpcast with warpcast.com/~/compose?text=&embeds[]=.

Having a quick look at the code base I think the following approach makes sense; Updating @/pages/post/index.tsx along the lines of the following:

import { useRouter } from "next/router";
export default function NewPost() {
  ...
  const router = useRouter();
  useEffect(() => {
    let text = router?.query?.text;
    if (text) {
      if (typeof text !== 'string') {
        text = text.find(t => t) ;
      }
      if (text) {
        addNewPostDraft({ text });
      }
    }
    if (drafts.length === 0) {
      addNewPostDraft({});
    }
  }, []);

This would handle the following cases:

  1. /post, empty draft added if no drafts.
  2. /post?text=Hey, a new draft added for the prompted.
  3. /post?text=1&text=2, only one draft added.

Downsides to this approach is that drafts could build up if there's lots of links being clicked like this which isn't a factor currently. Maybe it would make sense to destroy the proposed draft if the user navigates away?

hellno commented 6 months ago

hey @0xSemicolon this is a great idea! do you have capacity to add this to herocast? feel free to submit this as a PR. otherwise I'll try to look into it lateron

0xSemicolon commented 6 months ago

Hey @hellno I just created https://github.com/hellno/herocast/pull/251. I don't have the space to get the dev environment setup but I think what's there will just work. Needs someone to verify but it should be straight forward;

Test Cases

  1. If I have no drafts, and go to the /post screen, it should still add a draft
  2. If I have at least 1 draft, and no text param is present, it should not add another draft.
  3. If I go to /post?text=Blah it should add a draft with the text "Blah"
  4. If I go to /post?text=Blah1&text=Blah2 it should only add "Blah1" and ignore "Blah2"
hellno commented 6 months ago

awesome! I'll do the local testing. thanks for contributing 🙏🙏🙏