Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use gantt-schedule-timeline-calendar in a redux application? #392

Open
gadyonysh opened this issue Apr 17, 2024 · 2 comments
Open
Labels
👨‍🏫 Help wanted Extra attention is needed ❓ Question Further information is requested

Comments

@gadyonysh
Copy link

Your question and description of the problem goes here
Hi!
I have a React-Redux application and I want to integrate the "gantt-schedule-timeline-calendar" into it. Can you please advise me on the best way to manage the calendar's state using Redux? Specifically, I am interested in how to set the initial state of the calendar, update it based on changes in Redux data, and dispatch actions in response to user interactions.
Thank you for your help.

@gadyonysh gadyonysh added ❓ Question Further information is requested 👨‍🏫 Help wanted Extra attention is needed labels Apr 17, 2024
@neuronetio
Copy link
Owner

neuronetio commented Apr 19, 2024

GSTC works in a separate internal ecosystem, so you need to listen to state or connect to plugin events to be notified about changes or events.

You can listen events from item movement plugin or item resizing plugin and then dispatch your events to redux if you want.

If you need you can listen state changes directly.
For example when user is scrolling through a timeline you can listen scroll position changes or time changes.

First of all save your state object somewhere and then

// Generate GSTC state from configuration object
const state = GSTC.api.stateFromConfig(config);

// for testing
globalThis.state = state;

const element = document.getElementById('gstc');
//@ts-ignore
element.addEventListener('gstc-loaded', (ev) => {
  // @ts-ignore
  globalThis.dispatchEvent(new Event('gstc-loaded', ev.target));
});

// Mount the component
const app = (globalThis.gstc = GSTC({
  // @ts-ignore
  element,
  state,
}));

// subscribe horizontal scroll
const usubscribeHorizontalScroll = state.subscribe('config.scroll.horizontal', horizontalScroll => {
  console.log(horizontalScroll);
  // dispatch event to your redux store here if you need
});

// subscribe time changes

const unsubscribeChartTime = state.subscribe('config.chart.time', chartTime => {
  console.log(chartTime);
  // dispatch event to your redux store here if you need
});

@gadyonysh
Copy link
Author

@neuronetio Thank you very much. It was very helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
👨‍🏫 Help wanted Extra attention is needed ❓ Question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants