ChatCraft 2.0 is almost Here!
Tags: opensource, webdev, javascript, react
Published: 2024-04-14 00:03:33

That's right. The **BIG** 2.0 release for [ChatCraft](https://github.com/tarasglek/chatcraft.org) is scheduled by the end of next week. We have been working to build on ChatCraft's existing functionality in its [v1.0](https://github.com/tarasglek/chatcraft.org/tree/v1.1.0) state for almost 13 weeks now, and have successfully added lots of [cool features](https://www.youtube.com/watch?v=iW3JMSIf-Xo) (even this post's cover photo is generated by [ChatCraft](https://chatcraft.org/)).

However, adding these features in such a short span of time has also led to some [technical debt](https://en.wikipedia.org/wiki/Technical_debt) that needs to be cleaned up and [subtle bugs](https://github.com/tarasglek/chatcraft.org/issues) that need to be fixed so any future contributors have a good experience working on this project.

This week, I did some of the refactoring work, fixed a bug and also helped my peers to do the same by reviewing their PRs and help wherever possible.

In this post, I will be briefly talking about what I've been up to, and what I plan to do this upcoming week so we can make our 2.0 release a success!

## Table of Contents
&nbsp;1. [Fixing a Web Handlers related bug](#fixing-a-web-handlers-related-bug)
&nbsp;2. [Refactoring PasswordInput Component](#refactoring-passwordinput-component)
&nbsp;3. [Reviewing other PRs](#reviewing-other-prs)
&nbsp;4. [Next Plans](#next-plans)

## Fixing a Web Handlers related bug

For the past few weeks, I had been working on adding a new feature called [Web Handlers](https://dev.to/amnish04/iterating-on-web-handlers-implementation-1e30) to ChatCraft. Even though there are many more ways to still extend that feature, I think its a good time to fix any bugs introduced with it before for now since a major release is coming up.

[The issue](https://github.com/tarasglek/chatcraft.org/issues/541) was that when the user changed any of his previous messages and pressed **Re-Ask** button, it would not invoke any Web Handlers even if the updated prompt text matched with one of the registered handlers' match pattern.

The reason for this happening was that prompt text was not at all being passed to the **resubmit** function which led to the message being sent to LLM by default.

Hence, [the fix](https://github.com/tarasglek/chatcraft.org/pull/581) was as simple as follows:

![Reask bug reason](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uqq0dff5e5ndcqso28t8.png)

## Refactoring PasswordInput Component

Recently, [support for custom AI providers](https://github.com/tarasglek/chatcraft.org/pull/530) was added to ChatCraft and in implementing the UI for providers selection, changes were made to the existing `RevealablePasswordInput` component to make the appearance ideal for a particular use case.

However, I felt that the code had some design issues.

This is what it looked like:

```tsx
import { useState, type ComponentPropsWithRef } from "react";
import { Input, InputGroup, InputRightElement, Button } from "@chakra-ui/react";

type PasswordInputProps = ComponentPropsWithRef<typeof Input> & {
  inputSize?: "sm" | "md";
  isInvalid?: boolean;
};

function PasswordInput({ inputSize = "md", isInvalid, ...props }: PasswordInputProps) {
  const [show, setShow] = useState(false);

  const paddingRight = inputSize === "sm" ? "2.5rem" : "4.5rem";
  const paddingLeft = inputSize === "sm" ? "0.4rem" : undefined;
  const inputFieldSize = inputSize === "sm" ? "sm" : "md";
  const buttonSize = inputSize === "sm" ? "xs" : "sm";

  return (
    <InputGroup size={inputFieldSize}>
      <Input
        {...props}
        pr={paddingRight}
        pl={paddingLeft}
        type={show ? "text" : "password"}
        focusBorderColor={isInvalid ? "red.500" : "blue.500"}
        borderColor={isInvalid ? "red.500" : "gray.200"}
        isInvalid={isInvalid}
      />
      <InputRightElement width={paddingRight}>
        <Button variant="ghost" h="1.75rem" size={buttonSize} onClick={() => setShow(!show)}>
          {show ? "Hide" : "Show"}
        </Button>
      </InputRightElement>
    </InputGroup>
  );
}

export default PasswordInput;
```

**1.** Programatically determining styles based on other styles and hard coding values inside component caused tight coupling between different styles making it hard to reuse in other cases in the future. (Would need to add more if statements every time a new appearance was required)

**2.** In a way, it overrode Chakra's in-built styling system which is not good.

Which is why I created a [Pull Request](https://github.com/tarasglek/chatcraft.org/pull/582) to refactor that part.
I tried to make use of Chakra's own design system as much as possible turning it into a more generic wrapper around the regular [Input](https://v2.chakra-ui.com/docs/components/input) component provided by Chakra.
In other words, `PasswordInput` now behaves more like a component provided by [Chakra](https://v2.chakra-ui.com/) itself since most of the styles/props are being mapped directly.

## Reviewing other PRs

I also reviewed some Pull Requests opened by other contributors. 
Here's a list with hyperlinks.

**1.** [Replaced Show/Hide button with Eye ReactIcons](https://github.com/tarasglek/chatcraft.org/pull/579)
**2.** [Feed icon should open raw feed in a new tab](https://github.com/tarasglek/chatcraft.org/pull/573)
**3.** [Fix toast message width for mobile devices](https://github.com/tarasglek/chatcraft.org/pull/577)

You can take a look if interested.

## Next Plans

With all these contributions and many more, we were able to do a minor [v1.9.0 release](https://github.com/tarasglek/chatcraft.org/releases/tag/v1.9.0) taking us one step closer **2.0**.

![v1.9.0 release](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0cst37uvde6wv0raho3f.png)

We are **very close** to a successful major release 😎

Who else is excited? Any ChatCraft users here? Share your thoughts in comments!