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 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | 1x 13x 13x 13x 13x 5x 5x 2x 2x 2x 2x 5x 5x 13x 13x 13x 15x 15x 15x 1x 18x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | /* eslint-disable react/no-danger,jsx-a11y/no-static-element-interactions */ /* eslint-disable jsx-a11y/click-events-have-key-events */ import React from 'react'; import { Item } from '@uniquegood/realworld-web-interface/lib/models/game/Item'; import { keyframes, css } from '@emotion/react'; import { useRunStatement } from '@lib/utils/Game/Statement'; import { useGameStateContext } from '@lib/providers/GameState'; import { Tag } from '@lib/components/Inventory/Tag'; import { ItemTag } from '@uniquegood/realworld-web-interface/lib/models/game/ItemTag'; import CloseIcon from '@lib/components/icons/Close'; export const ACQUIREITEMMODAL_CLOSE_TEST_ID = 'acquireItemModal-close-component'; interface AcquireItemModalRenderData { item: Item; content: string; } export function useAcquireItemModal() { const [isOpen, setIsOpen] = React.useState(false); const [renderData, setRenderData] = React.useState<AcquireItemModalRenderData>(); const onCloseRef = React.useRef<() => unknown>(); const openAcquireItemModalWithAwait = React.useCallback( (nextRenderData: AcquireItemModalRenderData) => new Promise((resolve) => { onCloseRef.current = () => { setRenderData(undefined); setIsOpen(false); onCloseRef.current = undefined; resolve(true); }; setRenderData(nextRenderData); setIsOpen(true); }), [setRenderData, setIsOpen] ); const acquireItemModalProps = React.useMemo( () => ({ ...renderData, isOpen, onClose: onCloseRef.current }), [renderData, isOpen, setIsOpen] ); return { props: acquireItemModalProps, openAcquireItemModalWithAwait }; } interface AcquireItemModalProps { isOpen: boolean; onClose?: () => unknown; item: Item; itemTag: ItemTag; content: string; } export function AcquireItemModal({ isOpen, onClose, item, itemTag, content }: AcquireItemModalProps) { const { render, saveOnServer } = useGameStateContext(); const { runStatement } = useRunStatement(); async function handleItemActivate() { const statementList = item.actionMap.activateItem?.statementList; if (statementList) { for await (const statement of statementList) { await runStatement({ statement }); } saveOnServer(); render(); } } return isOpen ? ( <div css={modalWrapper}> <div css={backDrop} onClick={onClose}> <div css={modalBody} onClick={(e) => e.stopPropagation()}> <div css={closeButtonContainer}> <CloseIcon css={closeButtonWrap} onClick={onClose} data-testid={ACQUIREITEMMODAL_CLOSE_TEST_ID} /> </div> <div css={itemContents} onClick={handleItemActivate} role="button" tabIndex={0}> <div css={itemName}>{item.name}</div> <img css={itemImage} src={item.mainImageUrl} alt="아이템이미지" /> <div css={tagInItemWrapper}> {item.tagList.map((tag) => ( <Tag key={tag} name={itemTag.tagMap[tag]?.name} color={itemTag.tagMap[tag]?.color} /> ))} </div> <div css={acquireNotice}>{content}</div> </div> </div> </div> </div> ) : null; } const showBounce = keyframes` 0% { transform: scale(1); } 50% { transform: scale(1.2); } 80% { transform: scale(0.9); } 100% { transform: scale(1); } `; const modalWrapper = css` position: absolute; display: flex; justify-content: center; align-items: center; padding: 0 8px; `; const backDrop = css` position: fixed; display: flex; justify-content: center; align-items: center; top: 0; right: 0; bottom: 0; left: 0; background: rgba(0, 0, 0, 0.1); backdrop-filter: blur(10px); padding: 0 16px; z-index: 10000; `; const modalBody = css` max-width: 280px; padding: 16px; background: #f9f9f9; border: 1px solid #eeeeee; border-radius: 8px; text-align: center; animation: ${showBounce} 0.4s; `; const closeButtonContainer = css` display: flex; justify-content: flex-end; `; const closeButtonWrap = css` cursor: pointer; `; const itemContents = css` margin-top: 16px; `; const acquireNotice = css` margin-top: 12px; font-size: 16px; word-wrap: break-word; `; const itemName = css` font-size: 24px; font-weight: bold; `; const itemImage = css` width: 100%; margin: 8px 0; `; const tagInItemWrapper = css` width: 100%; display: flex; flex-wrap: nowrap; overflow-x: auto; gap: 4px; `; |