Giter Site home page Giter Site logo

Multiple pages about ui HOT 46 CLOSED

SebastianStehle avatar SebastianStehle commented on July 28, 2024 1
Multiple pages

from ui.

Comments (46)

JIVIN0902 avatar JIVIN0902 commented on July 28, 2024 1

Sounds good! I'll get working and I pls bear with my questions :)

from ui.

JIVIN0902 avatar JIVIN0902 commented on July 28, 2024 1

Ohh ok. I understand that. I Do know redux but I am still unfamiliar with the project structure.

from ui.

SebastianStehle avatar SebastianStehle commented on July 28, 2024 1

One the left sidebar where we have Shapes and Icons I would add another Tab called "Pages".

This tab shows a list of pages. On top a button to add new page. When you click on a page, the selectDiagram() action is invoked.

from ui.

JIVIN0902 avatar JIVIN0902 commented on July 28, 2024 1

Sorry. Silly me!

from ui.

JIVIN0902 avatar JIVIN0902 commented on July 28, 2024 1

Hi. Had a fever so took some time off. Working on it now.

from ui.

SebastianStehle avatar SebastianStehle commented on July 28, 2024 1

Yes, exactly.

from ui.

JIVIN0902 avatar JIVIN0902 commented on July 28, 2024

If this is a beginner friendly issue, I am willing to work on it.

from ui.

SebastianStehle avatar SebastianStehle commented on July 28, 2024

I think it is an easy task. The most stuff is already prepared for it.

e.g. the editor state already has a diagrams state which should be used for pages: https://github.com/mydraft-cc/ui/blob/master/src/wireframes/model/editor-state.ts#L19

from ui.

JIVIN0902 avatar JIVIN0902 commented on July 28, 2024

Sounds good. Any other files that might be helpful? Pls share. I'll start working on it.

from ui.

SebastianStehle avatar SebastianStehle commented on July 28, 2024

No, I don't think so. Just ask if you have any questions.

from ui.

JIVIN0902 avatar JIVIN0902 commented on July 28, 2024
     <Editor
        diagram={getDiagram(state)}
        rendererService={renderer}
        onChangeItemsAppearance={doChangeItemsAppearance}
        onSelectItems={doSelectItems}
        onTransformItems={doTransformItems}
        selectedItems={getSelectedItems(state)}
        selectedItemsWithLocked={getSelectedItemsWithLocked(state)}
        viewSize={editor.size}
        zoom={zoom}
        zoomedSize={zoomedSize}
    />

From What I have observed through trial and error, I think we need to supply different props to this edtor in order to create new pages? For example if I just copy and paste this and create a new page like that. When I drag and drop the icons they get replicated to both the pages. So what I think is that we need to supply new instances of some of these props to create a new page? Pls Correct me wherever I am wrong

from ui.

SebastianStehle avatar SebastianStehle commented on July 28, 2024

It depends how you want to implement it. There are 2 alternatives:

  1. Like powerpoint or Moqup where you see always one page only
  2. Like Word where you see all the pages in a list.

I thought you want to implement option 1, but I guess you want to implement option 2. I recommend to go with a one page approach because it is faster and easier to implement. The current code is designed for that, as it sends the current diagram to the Editor component.

from ui.

JIVIN0902 avatar JIVIN0902 commented on July 28, 2024

Alright. So u mean like slides in powerpoint? For example we can switch pages? So it would work like layers on top of each other and changing their visibility or something?

from ui.

SebastianStehle avatar SebastianStehle commented on July 28, 2024

Kind of. It would destroy the SVG for one page and then render the SVG for the other page. If you have too many DOM elements in your browser it will become really slow.

from ui.

JIVIN0902 avatar JIVIN0902 commented on July 28, 2024

So maybe we can limit the number of pages for that? I'll try some stuff and get familiar with the workings of this.

from ui.

SebastianStehle avatar SebastianStehle commented on July 28, 2024

If we use option one 1 it is not necessary. We just need a page management like moqup:

image

Folders are not needed, but perhaps:

  1. Add Page
  2. Delete Page
  3. Select page
  4. Reorder Pages (https://github.com/atlassian/react-beautiful-dnd)
  5. Rename and Name a page.

A page is just he same as a diagram in this context. As you can see the editor state already has methods for the most parts [0], so we just need the reducer actions for that and trigger the actions in the UI.

For feature 1. to 3. we don't need any changes in the model at all I think.

[0] https://github.com/mydraft-cc/ui/blob/master/src/wireframes/model/editor-state.ts
[1] https://github.com/mydraft-cc/ui/blob/master/src/wireframes/model/actions/diagrams.ts

from ui.

JIVIN0902 avatar JIVIN0902 commented on July 28, 2024

Hi

export const addDiagram =
    createAction('diagram/add', (diagramId?: string) => {
        return { payload: createDiagramAction(diagramId || MathHelper.guid()) };
    });

So I am trying to use this method in the editor state to create a new instance of a diagram and its giving me a circular dependency detected error. Am I doing something wrong or is there another way?

from ui.

SebastianStehle avatar SebastianStehle commented on July 28, 2024

How do you import that? have a look to the import statements. e.g. if you have something like this

import { addDiagram } from '@app/wireframes';

you get the problem, because @app/wireframes is the parent of the component.

Therefore you have to import it from

import { addDiagram } from '@app/wireframes/model';

from ui.

SebastianStehle avatar SebastianStehle commented on July 28, 2024

e.g. https://github.com/mydraft-cc/ui/blob/master/src/wireframes/components/properties/VisualProperties.tsx#L10

from ui.

JIVIN0902 avatar JIVIN0902 commented on July 28, 2024

import { addDiagram } from '@app/wireframes/model'; calling this inside the editor-state.ts still gives the same error.

from ui.

SebastianStehle avatar SebastianStehle commented on July 28, 2024

Why do you want to use it in the editor-state?

addDiagram calls editor-state, you have to invoke addDiagram in your component.

This project uses redux: https://redux.js.org/tutorials/fundamentals/part-1-overview

So basically

  • EditorState is the state, implemented as classes.
  • addDiagram is a reducer action.
  • Recucer + addDiagram is invoking the EditorState methods.

from ui.

SebastianStehle avatar SebastianStehle commented on July 28, 2024

No problem. Nothing is documented :D

from ui.

JIVIN0902 avatar JIVIN0902 commented on July 28, 2024

So what I am thinking is to add a + button add the top that will add a page. On clicking that button it will create a new page and replace the current page with that new blank one

from ui.

JIVIN0902 avatar JIVIN0902 commented on July 28, 2024

When I am invoking the addDiagram function on the editor component and try to log the new state its showing 1 diagram only. Maybe i need to pass some dependencies in the useEffect?

    React.useEffect(() => {

        addDiagram();
        console.log(state.editor.present);
        console.log(state.editor.present.diagrams)
    }, [])

from ui.

SebastianStehle avatar SebastianStehle commented on July 28, 2024

You have to use dispatch method

React.useEffect(() => {

    dispatch(addDiagram());
    console.log(state.editor.present);
    console.log(state.editor.present.diagrams)
}, [])

from ui.

JIVIN0902 avatar JIVIN0902 commented on July 28, 2024

Hey. Could you briefly explain how the editor state is structured. Some of the variables nested inside the object are the same . Getting a little bit confused. Thanks

from ui.

SebastianStehle avatar SebastianStehle commented on July 28, 2024

The state in the redux toolkit can be a little bit confusing, because of the custom Record class we use to represent states. But the structure is described with types:

https://github.com/mydraft-cc/ui/blob/master/src/wireframes/model/editor-state.ts#L14

type EditorProps = {
    // The id of the selected diagram.
    selectedDiagramId: string | null;

    // The actual diagrams.
    diagrams: DiagramMap; equivalent to a list of objects

    // The size of all diagrams.
    size: Vec2;

    // The color for all diagrams.
    color?: Color;
};

I guess we need to change the diagrams property to an ImmutableList to support changing the order.

The actual editor is wrapped in an undo-redo state:

image

The undoable state has a present state, a list previous states (to go back aka UNDO) and future states (to go forward aka REDO). Each state is stored with the action that belongs to the state because when a diagram is saved all actions are saved to keep the history.

from ui.

JIVIN0902 avatar JIVIN0902 commented on July 28, 2024

The thing is.. on dispatching addDiagram() function when I log the editor.present.diagrams, its showing 1 diagram only. Is the new diagram a part of the future state or something else?

from ui.

SebastianStehle avatar SebastianStehle commented on July 28, 2024

Make a PR so i can have a look to the code and install redux debugging tools for chrome

from ui.

JIVIN0902 avatar JIVIN0902 commented on July 28, 2024

I have redux tools for chrome. And over there it shows 2 I guess. I'll be sending a screenshot shortly

from ui.

SebastianStehle avatar SebastianStehle commented on July 28, 2024

Okay.

from ui.

SebastianStehle avatar SebastianStehle commented on July 28, 2024

Hi, how is it going?

from ui.

JIVIN0902 avatar JIVIN0902 commented on July 28, 2024

Screen Shot 2021-12-15 at 9 59 13 AM

The addDigram() is working and I guess the state also has 2 diagrams by looking at it in redux devtools, but when I log the same it shows only 1 diagram

from ui.

SebastianStehle avatar SebastianStehle commented on July 28, 2024

Hard to tell without seeing the code. Perhaps you just have a dependency wrong in a useEffect, e.g. If you log just after a dispatch you would not see the change immediately.

from ui.

JIVIN0902 avatar JIVIN0902 commented on July 28, 2024

But It is being created right by looking from the state?

from ui.

JIVIN0902 avatar JIVIN0902 commented on July 28, 2024
 React.useEffect(() => {
        dispatch(addDiagram());
    }, [dispatch]);

In the editor I have added this button to check the new state. but here too it shows only 1 diagram.

<span style={{color: "black", cursor: "pointer"}} onClick={() => console.log(getDiagrams(state))}>Show List</span>
            <Editor
                diagram={getDiagram(state)}
                rendererService={renderer}
                onChangeItemsAppearance={doChangeItemsAppearance}
                onSelectItems={doSelectItems}
                onTransformItems={doTransformItems}
                selectedItems={getSelectedItems(state)}
                selectedItemsWithLocked={getSelectedItemsWithLocked(state)}
                viewSize={editor.size}
                zoom={zoom}
                zoomedSize={zoomedSize}
            />

from ui.

SebastianStehle avatar SebastianStehle commented on July 28, 2024

I would just start building the list of pages. Then you see immediately whether it works or not.

from ui.

JIVIN0902 avatar JIVIN0902 commented on July 28, 2024

Ok. The list on the left side? Like right now it has 2 existing tabs and add another tab for pages? I'll work on it

from ui.

JIVIN0902 avatar JIVIN0902 commented on July 28, 2024

Hey. Trying to render the pages using previously built Grid component but unable to display

  const pages = useStore((s) => s.editor.present.diagrams);
<Grid
        className="asset-shapes-list"
        renderer={cellRenderer}
        columns={1}
        items={pages.values}
        keyBuilder={keyBuilder}
      />

The error

ShapeImage.tsx:49 Uncaught TypeError: Cannot read properties of undefined (reading 'toLowerCase')

from ui.

SebastianStehle avatar SebastianStehle commented on July 28, 2024

Hi, the grid renderer was built to be able to render a list of thousands of elements. In this case it is not needed (and also not a list), so I would just use a normal list of elements.

Ant design has a ready to use list: https://ant.design/components/list/

If you want to use the Grid you also have to define your own cell renderer. The cell renderer is a function that returns the component to be rendered for each cell and is then invoked while you scroll down or up.

But in the long term, a component like the Tree makes more sense: https://ant.design/components/tree/

from ui.

JIVIN0902 avatar JIVIN0902 commented on July 28, 2024

Yeah makes sense.

from ui.

SebastianStehle avatar SebastianStehle commented on July 28, 2024

The tree does not support ordering I guess :( ...

from ui.

SebastianStehle avatar SebastianStehle commented on July 28, 2024

We need:

  • Add
  • Rename
  • Remove
  • Ordering

from ui.

SebastianStehle avatar SebastianStehle commented on July 28, 2024

Do you have an estimation how long it takes to implement that? I have some other features that are dependent on that.

from ui.

JIVIN0902 avatar JIVIN0902 commented on July 28, 2024

I am using the ant design list to show the pages. I think it should be done shortly.

from ui.

SebastianStehle avatar SebastianStehle commented on July 28, 2024

I am sorry, but I would really like to get this done.

from ui.

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.