Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | import React, { useRef } from 'react'; import { css } from '@emotion/react'; import { InputNumberWithSubmitBlock as InputNumberWithSubmitBlockModel, InputNumberWithSubmitBlockStyle } from '@uniquegood/realworld-web-interface/lib/models/game/Block/InputNumberWithSubmit'; import { useGameStateContext } from '@lib/providers/GameState'; import produce from 'immer'; import { useRunStatement } from '@lib/utils/Game/Statement'; import { useContentAnalyticsContext } from '@lib/providers/ContentAnalytics'; import { useGameParameterContext } from '@lib/providers/GameParameter'; export default function InputNumberWithSubmitBlock({ placeholder, actionMap, style, id, buttonLabel }: InputNumberWithSubmitBlockModel) { const { consumeEvent } = useContentAnalyticsContext(); const { gameStateRef, render, saveOnServer } = useGameStateContext(); const { runStatement } = useRunStatement(); const inputNumberRef = useRef<number>(); const { parameterMapRef } = useGameParameterContext(); const isProcessingRef = React.useRef(false); async function handleSubmitText() { const inputNumber = inputNumberRef.current; if (inputNumber === undefined || Number.isNaN(inputNumber)) return; if (isProcessingRef.current) return; isProcessingRef.current = true; parameterMapRef.current = produce(parameterMapRef.current, (draft) => { if (!draft[`block-${id}`]) { draft[`block-${id}`] = {}; } if (!draft[`block-${id}`].submitNumber) { draft[`block-${id}`].submitNumber = {}; } draft[`block-${id}`]!.submitNumber!.input = { value: inputNumber, type: 'number' }; return draft; }); const statementList = actionMap.submitNumber?.statementList; if (statementList) { // CA: 사용자 텍스트 입력 이벤트 consumeEvent({ eventType: 'UserInput', metadata: { currentScreen: gameStateRef.current.currentScreenId, blockId: id, inputNumber: `${inputNumber}` // FIXME: number는 못보냄 } }); for await (const statement of statementList) { await runStatement({ statement, withParameter: { blockId: id, originActionType: 'submitNumber' } }); } saveOnServer(); render(); } isProcessingRef.current = false; } const inputStyle = React.useMemo(() => { const styleObj = InputNumberWithSubmitBlockStyle.parse(style); return css` text-align: ${styleObj.align}; background-color: ${styleObj.backgroundColor}; border-width: ${styleObj.borderWidth}px; border-color: ${styleObj.borderColor}; border-radius: ${styleObj.borderRadius}px; font-size: ${styleObj.fontSize}px; color: ${styleObj.fontColor}; font-family: ${styleObj.fontFamily}; &::placeholder { color: ${styleObj.placeholderColor}; } `; }, [style]); const submitButtonStyle = React.useMemo(() => { const styleObj = InputNumberWithSubmitBlockStyle.parse(style); return css` background-color: ${styleObj.buttonBackgroundColor}; border-radius: ${styleObj.borderRadius}px; font-size: ${styleObj.fontSize}px; color: ${styleObj.buttonFontColor}; font-family: ${styleObj.fontFamily}; `; }, [style]); return ( <div css={container}> <input type="number" css={[defaultInputNumberWrap, inputStyle]} placeholder={placeholder || '텍스트를 입력해주세요.'} onChange={(e) => { inputNumberRef.current = e.target.valueAsNumber; }} /> <button onClick={handleSubmitText} type="button" css={[submitButton, submitButtonStyle]} color="white" > {buttonLabel} </button> </div> ); } const container = css` display: flex; flex-direction: column; gap: 8px; width: 100%; height: 100%; `; const defaultInputNumberWrap = css` width: 100%; flex-grow: 1; border-style: solid; padding: 0 12px; outline: none; `; const submitButton = css` border: none; display: flex; align-items: center; justify-content: center; user-select: none; height: 40px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; `; |