mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-26 14:54:55 +00:00
code: nextjs,frontends,transfer (4 files)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { useEffect, useMemo, useState } from 'react'
|
||||
import { useEffect, useMemo, useState, type MouseEvent } from 'react'
|
||||
import {
|
||||
Box,
|
||||
Button,
|
||||
@@ -591,20 +591,26 @@ export function LuaBlocksEditor({ scripts, onScriptsChange }: LuaBlocksEditorPro
|
||||
}
|
||||
|
||||
const handleRequestAddBlock = (
|
||||
event: React.MouseEvent<HTMLElement>,
|
||||
event: MouseEvent<HTMLElement>,
|
||||
target: { parentId: string | null; slot: BlockSlot }
|
||||
) => {
|
||||
setMenuAnchor(event.currentTarget)
|
||||
setMenuTarget(target)
|
||||
}
|
||||
|
||||
const handleAddBlock = (type: LuaBlockType) => {
|
||||
if (!selectedScriptId || !menuTarget) return
|
||||
const handleAddBlock = (type: LuaBlockType, target?: { parentId: string | null; slot: BlockSlot }) => {
|
||||
const resolvedTarget = target ?? menuTarget
|
||||
if (!selectedScriptId || !resolvedTarget) return
|
||||
|
||||
const newBlock = createBlock(type)
|
||||
setBlocksByScript((prev) => ({
|
||||
...prev,
|
||||
[selectedScriptId]: addBlockToTree(prev[selectedScriptId] || [], menuTarget.parentId, menuTarget.slot, newBlock),
|
||||
[selectedScriptId]: addBlockToTree(
|
||||
prev[selectedScriptId] || [],
|
||||
resolvedTarget.parentId,
|
||||
resolvedTarget.slot,
|
||||
newBlock
|
||||
),
|
||||
}))
|
||||
|
||||
setMenuAnchor(null)
|
||||
@@ -884,9 +890,7 @@ export function LuaBlocksEditor({ scripts, onScriptsChange }: LuaBlocksEditorPro
|
||||
key={block.type}
|
||||
className={styles.libraryBlock}
|
||||
data-category={block.category}
|
||||
onClick={(event) =>
|
||||
handleRequestAddBlock(event, { parentId: null, slot: 'root' })
|
||||
}
|
||||
onClick={() => handleAddBlock(block.type, { parentId: null, slot: 'root' })}
|
||||
>
|
||||
<Box sx={{ display: 'flex', justifyContent: 'space-between', gap: 2 }}>
|
||||
<Box>
|
||||
@@ -898,8 +902,7 @@ export function LuaBlocksEditor({ scripts, onScriptsChange }: LuaBlocksEditorPro
|
||||
variant="outlined"
|
||||
onClick={(event) => {
|
||||
event.stopPropagation()
|
||||
handleRequestAddBlock(event, { parentId: null, slot: 'root' })
|
||||
handleAddBlock(block.type)
|
||||
handleAddBlock(block.type, { parentId: null, slot: 'root' })
|
||||
}}
|
||||
>
|
||||
Add
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import type { PowerTransferRequest } from '@/lib/level-types'
|
||||
import { requestJson } from '@/lib/api/request-json'
|
||||
|
||||
interface CreatePowerTransferRequestPayload {
|
||||
fromUserId: string
|
||||
toUserId: string
|
||||
}
|
||||
|
||||
export async function createPowerTransferRequest(
|
||||
payload: CreatePowerTransferRequestPayload
|
||||
): Promise<PowerTransferRequest> {
|
||||
const response = await requestJson<{ request: PowerTransferRequest }>('/api/power-transfers', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(payload),
|
||||
})
|
||||
return response.request
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import type { PowerTransferRequest } from '@/lib/level-types'
|
||||
import { requestJson } from '@/lib/api/request-json'
|
||||
|
||||
export async function fetchPowerTransferRequests(): Promise<PowerTransferRequest[]> {
|
||||
const payload = await requestJson<{ requests: PowerTransferRequest[] }>('/api/power-transfers')
|
||||
return payload.requests
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { PackageDefinition } from './types'
|
||||
|
||||
type PackageSeedConfig = {
|
||||
export type PackageSeedConfig = {
|
||||
metadata: Omit<PackageDefinition, 'components' | 'scripts' | 'scriptFiles' | 'examples'>
|
||||
components: any[]
|
||||
examples: any
|
||||
|
||||
Reference in New Issue
Block a user