Giter Site home page Giter Site logo

Comments (15)

gxrsti avatar gxrsti commented on July 28, 2024 1

Will close this issue since #36 was created and this issue has a lot of irrelevant comments.

from alert.

shakthi2003-ice avatar shakthi2003-ice commented on July 28, 2024

@gxrsti can you assign me this issue?

from alert.

gxrsti avatar gxrsti commented on July 28, 2024

Sure, here you go!

from alert.

shakthi2003-ice avatar shakthi2003-ice commented on July 28, 2024

@gxrsti do we have to change all the comments in the code?

from alert.

gxrsti avatar gxrsti commented on July 28, 2024

Currently, there are no comments. We need comments at least for all the exported components/functions!

The more, the better.

from alert.

shakthi2003-ice avatar shakthi2003-ice commented on July 28, 2024

@gxrsti we should we add the toaster component?

from alert.

gxrsti avatar gxrsti commented on July 28, 2024

@gxrsti we should we add the toaster component?

Toaster component and toast function at least.

from alert.

shakthi2003-ice avatar shakthi2003-ice commented on July 28, 2024

@gxrsti while running ppm run development website I am getting this error

Turborepo requires npm workspaces to be defined in the root package.json

from alert.

gxrsti avatar gxrsti commented on July 28, 2024

@shakthi2003-ice Try these steps in the project root:

  1. Run pnpm install
  2. Run pnpm run dev:website

from alert.

shakthi2003-ice avatar shakthi2003-ice commented on July 28, 2024

@gxrsti i did the same but still getting error

from alert.

gxrsti avatar gxrsti commented on July 28, 2024

Make sure to have the newest version of the master branch.

If you follow these steps, everything should work.

Also make sure to have pnpm installed (npm install -g pnpm)

If it still doesn't work, here is my last possible solution:

Get a fresh version of the repository and add "packageManager": "[email protected]" at the end (after peerDependencies) of the package.json.

Then try the install and dev:website

from alert.

gxrsti avatar gxrsti commented on July 28, 2024

@shakthi2003-ice did you get it working?

from alert.

Moksh45-Bot avatar Moksh45-Bot commented on July 28, 2024

Hi there! I've added a comment for this code file. Please let me know if you're satisfied with it or if you'd like any changes. By the way, this is @Moksh45

import { IToast, ToastState, ToasterProps } from '../core/types';
import { Store } from '../core/store';
import { Toast } from './toast';

// A component that renders a toast notification container
const Toaster = ({
  position = 'bottom-right',
  duration = 3000,
  reverse = false,
  theme = 'light',
  style,
  className,
}: ToasterProps) => {
  // State for storing the toast notifications
  const [toasts, setToasts] = useState<IToast[]>([]);
  // State for positioning the toast container
  const [positionState, setPositionState] = useState<React.CSSProperties>({});
  // State for calculating the height of the toast container
  const [height, setHeight] = useState(0);

  // Subscribe to the toast store and add new toast notifications
  useEffect(() => {
    const unsubscribe = Store.subscribe((toast) => {
      setToasts((toasts) => [...toasts, toast]);
      handleToast(toast);
    });

    return () => {
      unsubscribe();
    };
  }, []);

  // Set the position state based on the given position prop
  useEffect(() => {
    const [y, x] = position.split('-');
    setPositionState({
      [y]: 0,
      [x]: 0,
    });
  }, [position]);

  // Update the height of the toast container based on the number of toasts
  useEffect(() => {
    setHeight(toasts.length * 41);
  }, [toasts]);

  // Handle the lifecycle of a toast notification
  function handleToast(toast: IToast) {
    setTimeout(() => updateToastState(toast, 'idle'), 300);
    setTimeout(() => updateToastState(toast, 'leave'), duration - 100);
    setTimeout(() => removeToast(toast), duration);
  }

  // Update the state of a toast notification
  function updateToastState(toast: IToast, state: ToastState) {
    setToasts((toasts) => {
      var copy = toasts.slice();
      var index = copy.findIndex((x) => x.id === toast.id);
      copy[index] = { ...copy[index], state: state };
      return copy;
    });
  }

  // Remove a toast notification from the state
  const removeToast = useCallback(
    (toast: IToast) => setToasts((toasts) => toasts.filter((x) => x.id !== toast.id)),
    [],
  );

  // Reverse the order of toasts if reverse prop is true
  const reversedToasts = reverse ? toasts.slice().reverse() : toasts;

  return (
    <section
      style={{
        position: 'fixed',
        zIndex: 9999,
        display: 'flex',
        flexDirection: 'column',
        gap: 5,
        margin: 16,
        transform: 'translateY(0)',
        height: height,
        transition: 'all 230ms cubic-bezier(.21, 1.02, .73, 1)',
        ...positionState,
      }}
    >
      {position.startsWith('bottom') && !reverse && <div className="flex h-full w-full grow" />}
      {reversedToasts.map((toast, index) => (
        <Toast key={index} toast={{ ...toast, zIndex: index, theme }} />
      ))}
    </section>
  );
};

export { Toaster };

from alert.

gxrsti avatar gxrsti commented on July 28, 2024

Hey @Moksh45-Bot!

For file changes, could you please open a pr? Also from what i see, i would like to use this commenting style as far as it is possible to also descripe the parameters of a function or component.

from alert.

Moksh45 avatar Moksh45 commented on July 28, 2024

@gxrsti ok

from alert.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.