Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
feat: create observable for rearrange elements
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexpeschel authored and lkuechler committed Dec 14, 2017
1 parent adfbfb2 commit b7c9c34
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/component/container/element_list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ export class ElementList extends React.Component<ElementListProps> {
value: patternPath.replace(/^.*\//, ''),
onClick: updatePageElement,
handleDragStart: (e: React.DragEvent<HTMLElement>) => {
this.props.store.setClipboardElement(element);
this.props.store.setRearrangeElement(element);
},
handleDragDropForChild: (e: React.DragEvent<HTMLElement>) => {
const transferPatternPath = e.dataTransfer.getData('patternPath');
const parentElement = element.getParent();
const pageElement = transferPatternPath ? new PageElement(this.props.store.getPattern(transferPatternPath)) : this.props.store.getClipboardElement();
const pageElement = transferPatternPath ? new PageElement(this.props.store.getPattern(transferPatternPath)) : this.props.store.getRearrangeElement();

if (!parentElement || !pageElement) {
return;
Expand All @@ -112,7 +112,7 @@ export class ElementList extends React.Component<ElementListProps> {
},
handleDragDrop: (e: React.DragEvent<HTMLElement>) => {
const transferPatternPath = e.dataTransfer.getData('patternPath');
const pageElement = transferPatternPath ? new PageElement(this.props.store.getPattern(transferPatternPath)) : this.props.store.getClipboardElement();
const pageElement = transferPatternPath ? new PageElement(this.props.store.getPattern(transferPatternPath)) : this.props.store.getRearrangeElement();

if (!pageElement) {
return;
Expand Down
9 changes: 9 additions & 0 deletions src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Project } from './project';

export class Store {
@MobX.observable private clipboardElement?: PageElement | undefined;
@MobX.observable private rearrangeElement?: PageElement | undefined;
@MobX.observable private currentPage?: Page;
@MobX.observable private patternSearchTerm: string = '';
@MobX.observable private projects: Project[] = [];
Expand All @@ -31,6 +32,10 @@ export class Store {
return this.clipboardElement;
}

public getRearrangeElement(): PageElement | undefined {
return this.rearrangeElement;
}

public getCurrentPage(): Page | undefined {
return this.currentPage;
}
Expand Down Expand Up @@ -164,6 +169,10 @@ export class Store {
this.clipboardElement = clipboardElement;
}

public setRearrangeElement(rearrangeElement: PageElement): void {
this.rearrangeElement = rearrangeElement;
}

public setSelectedElement(selectedElement: PageElement): void {
this.selectedElement = selectedElement;
}
Expand Down

0 comments on commit b7c9c34

Please sign in to comment.