|
1 | 1 | import { ElementType } from "@/components/workspace/elements"; |
2 | 2 | import { dataAttributes, selectors } from "@/constants"; |
3 | 3 | import { store } from "@/store"; |
4 | | -import { ISTKData } from "@/types"; |
| 4 | +import { ISTKData, ISeat } from "@/types"; |
5 | 5 | import { rgbToHex } from "."; |
6 | 6 | import { default as d3Extended } from "./d3"; |
7 | 7 |
|
8 | | -export const domSeatsToJSON = () => { |
| 8 | +export const domSeatsToJSON = (seats: ISeat[]) => { |
9 | 9 | return d3Extended.selectAll(`[${dataAttributes.elementType}="${ElementType.Seat}"]`).map((seat) => { |
| 10 | + const id = seat.attr("id"); |
10 | 11 | const square = (seat.node() as any)?.nodeName === "rect"; |
| 12 | + const seatFromStore = seats.find((s) => s.id === id); |
11 | 13 | return { |
12 | | - id: seat.attr("id"), |
| 14 | + id, |
13 | 15 | x: +seat.attr(square ? "x" : "cx"), |
14 | 16 | y: +seat.attr(square ? "y" : "cy"), |
15 | | - label: document.getElementById(`${seat.attr("id")}-label`)?.textContent, |
| 17 | + label: document.getElementById(`${seat.attr("id")}-label`)?.textContent ?? seatFromStore?.label, |
16 | 18 | status: seat.attr(dataAttributes.status), |
17 | 19 | category: seat.attr(dataAttributes.category), |
18 | 20 | square, |
@@ -102,7 +104,7 @@ export const stateToJSON = (): ISTKData => { |
102 | 104 | name: state.location, |
103 | 105 | categories: state.categories.slice(1), |
104 | 106 | sections: state.sections.slice(1), |
105 | | - seats: domSeatsToJSON(), |
| 107 | + seats: domSeatsToJSON(state.seats), |
106 | 108 | text: domTextToJSON(), |
107 | 109 | shapes: domShapesToJSON(), |
108 | 110 | polylines: domPolylineToJSON(), |
|
0 commit comments