intermediate checkin during chart order form work
This commit is contained in:
@@ -1,45 +1,58 @@
|
||||
import {routeInverted, timestamp} from "@/misc.js";
|
||||
import {routeInverted, timestamp, uuid} from "@/misc.js";
|
||||
import {MAX_FRACTION, newTranche} from "@/blockchain/orderlib.js";
|
||||
import {useOrderStore} from "@/store/store.js";
|
||||
import {encodeIEE754} from "@/common.js";
|
||||
import {defineStore} from "pinia";
|
||||
import {computed, ref} from "vue";
|
||||
import {ref} from "vue";
|
||||
|
||||
|
||||
function unimplemented() { throw Error('Unimplemented') }
|
||||
|
||||
// Builders are data objects which store a configuration state
|
||||
function TrancheBuilder( component, options = {}) {
|
||||
const id = crypto.randomUUID()
|
||||
// the component name must match a corresponding Vue component in the BuilderFactory.vue component, which is responsible
|
||||
// for instantiating the UI component for a given builder dictionary, based on its builder.component field.
|
||||
export function newBuilder( component, options = {}) {
|
||||
const id = uuid()
|
||||
return {id, component, options, points: {}, shapes: {}, props: {}, build: unimplemented}
|
||||
}
|
||||
|
||||
// Orders hold an amount and builders
|
||||
const Order = {
|
||||
id: uuid(),
|
||||
amount: 0,
|
||||
builders: [],
|
||||
}
|
||||
|
||||
|
||||
export const useChartOrderStore = defineStore('chart_orders', () => {
|
||||
const chartReady = ref(false)
|
||||
|
||||
const builderIdList = ref([]) // this is where we keep the UI ordering
|
||||
const builderList = computed(()=>{
|
||||
console.log('builder list', builderIdList.value.map((id)=>builderDict.value[id]))
|
||||
return builderIdList.value.map((id)=>builderDict.value[id])
|
||||
}) // convenience
|
||||
const builderDict = ref({}) // builders stored by id
|
||||
const orders = ref([])
|
||||
const selectedOrder = ref(null)
|
||||
|
||||
const drawing = ref(false)
|
||||
const drawingCallbacks = ref(null) // only during draw mode
|
||||
|
||||
function addBuilder(component, options={}) {
|
||||
const b = TrancheBuilder(component,options)
|
||||
builderIdList.value.push(b.id)
|
||||
builderDict.value[b.id] = b
|
||||
function newOrder() {
|
||||
console.log('cos new order')
|
||||
const order = { id:uuid(), amount:1, builders:[] }
|
||||
orders.value.push(order)
|
||||
selectedOrder.value = order
|
||||
}
|
||||
|
||||
function removeBuilder(builder) {
|
||||
builderIdList.value = builderIdList.value.filter((v)=>v!==builder.id)
|
||||
delete builderDict.value[builder.id]
|
||||
function removeOrder(order) {
|
||||
let index = orders.value.findIndex((o)=>o.id===order.id)
|
||||
if (index === -1) return
|
||||
orders.value = orders.value.filter((o)=>o.id!==order.id)
|
||||
if (orders.value.length === 0)
|
||||
selectedOrder.value = null
|
||||
else
|
||||
selectedOrder.value = orders.value[Math.max(0,index-1)] // select the order above the removed one
|
||||
}
|
||||
|
||||
return { chartReady, builderList, builderDict, drawing, drawingCallbacks, addBuilder, removeBuilder, }
|
||||
return {
|
||||
chartReady, orders, drawing, drawingCallbacks, newOrder, removeOrder,
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user