init dialogue and progressbar bananza

Added dialogue system initial upload. Some modifications needed but good default.

Standardized input and output for progressbar. Accepts ox and qb (progressbar)
This commit is contained in:
gononono64 committed 2025-02-21 11:02:18 -06:00
1 parent df5dd4ffa4
commit 58782dfcd0
24 files changed
+12760 -87

No files matched your search

+6
View File
@@ -49,10 +49,16 @@ client_scripts {
'modules/input/*.lua', 'modules/input/*.lua',
'modules/menu/*.lua', 'modules/menu/*.lua',
'modules/notify/**/client.lua', 'modules/notify/**/client.lua',
'modules/dialogue/**/client/*.lua',
'init.lua', 'init.lua',
} }
ui_page 'web/dist/index.html'
files { files {
'web/dist/index.html',
'web/dist/assets/*.css',
'web/dist/assets/*.js',
'locales/*.json', 'locales/*.json',
'lib/client/*.lua', 'lib/client/*.lua',
'lib/shared/*.lua', 'lib/shared/*.lua',
@@ -0,0 +1,34 @@
--- Open a dialogue with the player
--- @param name string
--- @param dialogue string
--- @param options table example = {{ id = string, label = string}}
function OpenDialogue(name, dialogue, options)
SendNUIMessage({
type = "open",
text = dialogue,
name = name,
options = options
})
end
RegisterCommand("dialogue", function()
OpenDialogue( "Akmed" , "Hello how are you doing my friend?", {
{
label = "Trade with me",
id = 'something',
},
{
label = "Goodbye",
id = 'someotherthing',
}
}
)
end)
-- { label: 'Hello there! this is some long text that i am Dialogueing', id: '1' },
-- { label: 'Trade with me', id: '2' },
-- { label: 'Goodbye', id: '3' }
+53
View File
@@ -0,0 +1,53 @@
if GetResourceState('ox_lib') ~= 'started' or (BridgeClientConfig.ProgressBarSystem ~= "ox" and BridgeClientConfig.InputSystem ~= "auto") then return end
ProgressBar = ProgressBar or {}
local function convertFromQB(options)
if not options then return options end
return {
duration = options.duration,
label = options.label,
position = 'bottom',
useWhileDead = options.useWhileDead,
canCancel = options.canCancel,
disable = {
move = options.controlDisables?.disableMovement,
car = options.controlDisables?.disableCarMovement,
combat = options.controlDisables?.disableCombat,
mouse = options.controlDisables?.disableMouse
},
anim = {
dict = options.animation?.animDict,
clip = options.animation?.anim
}
}
end
function ProgressBar.Open(options, cb, isQBInput)
if isQBInput then
options = convertFromQB(options)
end
local style = options.style or 'bar'
local success = style == 'circle' and exports.ox_lib:progressCircle(options) or exports.ox_lib:progressBar(options)
if cb then cb(not success) end
return success
end
RegisterCommand("progressbar", function()
ProgressBar.Open({
duration = 5000,
label = "Searching",
disable = {
move = true,
combat = true
},
anim = {
dict = "anim@amb@clubhouse@tutorial@bkr_tut_ig3@",
clip = "machinic_loop_mechandplayer"
}
}, function(cancelled)
print(cancelled and "Cancelled" or "Complete")
end)
end)
+89 -34
View File
@@ -1,38 +1,93 @@
if BridgeClientConfig.ProgressBar ~= "ox" then return end -- if BridgeClientConfig.ProgressBar ~= "ox" then return end
Progressbar = {} -- Progressbar = {}
local _progBarType = BridgeClientConfig.ProgressBarStyle or "bar" -- local _progBarType = BridgeClientConfig.ProgressBarStyle or "bar"
Progressbar.StartProgressBar = function(time, label, whiledead, cancancel, disable, animTable, successAction, canceledAction) -- Progressbar.StartProgressBar = function(time, label, whiledead, cancancel, disable, animTable, successAction, canceledAction)
local runTime = time or 10000 -- local runTime = time or 10000
local textLabel = label or "Doing something" -- local textLabel = label or "Doing something"
local deadBool = whiledead or false -- local deadBool = whiledead or false
local cancelBool = cancancel or false -- local cancelBool = cancancel or false
local disableKeys = disable or { move = true, sprint = true, car = true, combat = true, } -- local disableKeys = disable or { move = true, sprint = true, car = true, combat = true, }
local anim = animTable or nil -- local anim = animTable or nil
local success = successAction or function() Prints.Debug("Success") end -- local success = successAction or function() Prints.Debug("Success") end
local canceled = canceledAction or function() Prints.Debug("Cancelled") end -- local canceled = canceledAction or function() Prints.Debug("Cancelled") end
if _progBarType == "bar" then -- if _progBarType == "bar" then
if exports.ox_lib:progressBar({ -- if exports.ox_lib:progressBar({
duration = runTime, -- duration = runTime,
label = textLabel, -- label = textLabel,
useWhileDead = deadBool, -- useWhileDead = deadBool,
canCancel = cancelBool, -- canCancel = cancelBool,
disable = disableKeys, -- disable = disableKeys,
anim = anim, -- anim = anim,
}) then success() else canceled() end -- }) then success() else canceled() end
elseif _progBarType == "circle" then -- elseif _progBarType == "circle" then
if exports.ox_lib:progressCircle({ -- if exports.ox_lib:progressCircle({
duration = runTime, -- duration = runTime,
label = textLabel, -- label = textLabel,
position = 'bottom', -- position = 'bottom',
useWhileDead = deadBool, -- useWhileDead = deadBool,
canCancel = cancelBool, -- canCancel = cancelBool,
disable = disableKeys, -- disable = disableKeys,
anim = anim, -- anim = anim,
}) then success() else canceled() end -- }) then success() else canceled() end
-- end
-- end
-- Progressbar.IsProgressBarActive = function()
-- return exports.ox_lib:progressActive()
-- end
if GetResourceState('ox_lib') ~= 'started' or (BridgeClientConfig.ProgressBarSystem ~= "ox" and BridgeClientConfig.InputSystem ~= "auto") then return end
ProgressBar = ProgressBar or {}
local function convertFromQB(options)
if not options then return options end
return {
duration = options.duration,
label = options.label,
position = 'bottom',
useWhileDead = options.useWhileDead,
canCancel = options.canCancel,
disable = {
move = options.controlDisables?.disableMovement,
car = options.controlDisables?.disableCarMovement,
combat = options.controlDisables?.disableCombat,
mouse = options.controlDisables?.disableMouse
},
anim = {
dict = options.animation?.animDict,
clip = options.animation?.anim
}
}
end
function ProgressBar.Open(options, cb, isQBInput)
if isQBInput then
options = convertFromQB(options)
end end
local style = options.style or 'bar'
local success = style == 'circle' and exports.ox_lib:progressCircle(options) or exports.ox_lib:progressBar(options)
if cb then cb(not success) end
return success
end end
Progressbar.IsProgressBarActive = function() RegisterCommand("progressbar", function()
return exports.ox_lib:progressActive() ProgressBar.Open({
end duration = 5000,
label = "Searching",
disable = {
move = true,
combat = true
},
anim = {
dict = "anim@amb@clubhouse@tutorial@bkr_tut_ig3@",
clip = "machinic_loop_mechandplayer"
}
}, function(cancelled)
print(cancelled and "Cancelled" or "Complete")
end)
end)
@@ -0,0 +1,55 @@
if GetResourceState('progressbar') ~= 'started' or (BridgeClientConfig.ProgressBarSystem ~= "qb" and BridgeClientConfig.ProgressBarSystem ~= "auto") then return end
ProgressBar = ProgressBar or {}
local function convertFromOx(options)
if not options then return options end
return {
name = options.label,
duration = options.duration,
label = options.label,
useWhileDead = options.useWhileDead,
canCancel = options.canCancel,
controlDisables = {
disableMovement = options.disable?.move,
disableCarMovement = options.disable?.car,
disableMouse = options.disable?.mouse,
disableCombat = options.disable?.combat
},
animation = {
animDict = options.anim?.dict,
anim = options.anim?.clip
},
prop = {},
propTwo = {}
}
end
function ProgressBar.Open(options, cb, qbFormat)
if not exports['progressbar'] then return false end
if not qbFormat then
options = convertFromOx(options)
end
exports['progressbar']:Progress(options, cb)
end
-- Example usage:
RegisterCommand("progressbar", function()
ProgressBar.Open({
duration = 5000,
label = "Searching",
disable = {
move = true,
combat = true
},
anim = {
dict = "anim@amb@clubhouse@tutorial@bkr_tut_ig3@",
clip = "machinic_loop_mechandplayer"
}
}, function(cancelled)
print(cancelled and "Cancelled" or "Complete")
end)
end)
+110 -53
View File
@@ -1,60 +1,117 @@
if BridgeClientConfig.ProgressBar ~= "qb" then return end -- if BridgeClientConfig.ProgressBar ~= "qb" then return end
Progressbar = {} -- Progressbar = {}
local function convertOxToQB(disabledTable, animTable) -- local function convertOxToQB(disabledTable, animTable)
local repackedTable = { disabled = {}, animations = {}} -- local repackedTable = { disabled = {}, animations = {}}
for _, v in pairs(disabledTable) do -- for _, v in pairs(disabledTable) do
if v.move then -- if v.move then
repackedTable.disabled.disableMovement = v.move -- repackedTable.disabled.disableMovement = v.move
end -- end
if v.car then -- if v.car then
repackedTable.disabled.disableCarMovement = v.car -- repackedTable.disabled.disableCarMovement = v.car
end -- end
if v.combat then -- if v.combat then
repackedTable.disabled.disableCombat = v.combat -- repackedTable.disabled.disableCombat = v.combat
end -- end
if v.mouse then -- if v.mouse then
repackedTable.disabled.disableMouse = v.mouse -- repackedTable.disabled.disableMouse = v.mouse
end -- end
end -- end
for _, v in pairs(animTable) do -- for _, v in pairs(animTable) do
if v.dict then -- if v.dict then
repackedTable.animations.animDict = v.animDict -- repackedTable.animations.animDict = v.animDict
end -- end
if v.clip then -- if v.clip then
repackedTable.animations.anim = v.anim -- repackedTable.animations.anim = v.anim
end -- end
end -- end
return repackedTable -- return repackedTable
end -- end
Progressbar.StartProgressBar = function(time, label, whiledead, cancancel, disable, animTable, successAction, canceledAction) -- Progressbar.StartProgressBar = function(time, label, whiledead, cancancel, disable, animTable, successAction, canceledAction)
local runTime = time or 10000 -- local runTime = time or 10000
local textLabel = label or "Doing something" -- local textLabel = label or "Doing something"
local deadBool = whiledead or false -- local deadBool = whiledead or false
local cancelBool = cancancel or false -- local cancelBool = cancancel or false
local success = successAction or function() Prints.Debug("Success") end -- local success = successAction or function() Prints.Debug("Success") end
local canceled = canceledAction or function() Prints.Debug("Cancelled") end -- local canceled = canceledAction or function() Prints.Debug("Cancelled") end
local repackedTable = convertOxToQB(disable, animTable) -- local repackedTable = convertOxToQB(disable, animTable)
exports['progressbar']:Progress({ -- exports['progressbar']:Progress({
name = textLabel, -- name = textLabel,
duration = runTime, -- duration = runTime,
label = textLabel, -- label = textLabel,
useWhileDead = deadBool, -- useWhileDead = deadBool,
canCancel = cancelBool, -- canCancel = cancelBool,
controlDisables = repackedTable.disabled, -- controlDisables = repackedTable.disabled,
animation = repackedTable.animations, -- animation = repackedTable.animations,
-- prop = {},
-- propTwo = {}
-- }, function(cancelled)
-- if not cancelled then
-- success()
-- else
-- canceled()
-- end
-- end)
-- end
-- Progressbar.IsProgressBarActive = function()
-- return exports["progressbar"]:isDoingSomething()
-- end
if GetResourceState('progressbar') ~= 'started' or (BridgeClientConfig.ProgressBarSystem ~= "qb" and BridgeClientConfig.ProgressBarSystem ~= "auto") then return end
ProgressBar = ProgressBar or {}
local function convertFromOx(options)
if not options then return options end
return {
name = options.label,
duration = options.duration,
label = options.label,
useWhileDead = options.useWhileDead,
canCancel = options.canCancel,
controlDisables = {
disableMovement = options.disable?.move,
disableCarMovement = options.disable?.car,
disableMouse = options.disable?.mouse,
disableCombat = options.disable?.combat
},
animation = {
animDict = options.anim?.dict,
anim = options.anim?.clip
},
prop = {}, prop = {},
propTwo = {} propTwo = {}
}, function(cancelled) }
if not cancelled then
success()
else
canceled()
end
end)
end end
Progressbar.IsProgressBarActive = function() function ProgressBar.Open(options, cb, qbFormat)
return exports["progressbar"]:isDoingSomething() if not exports['progressbar'] then return false end
if not qbFormat then
options = convertFromOx(options)
end
exports['progressbar']:Progress(options, cb)
end end
-- Example usage:
RegisterCommand("progressbar", function()
ProgressBar.Open({
duration = 5000,
label = "Searching",
disable = {
move = true,
combat = true
},
anim = {
dict = "anim@amb@clubhouse@tutorial@bkr_tut_ig3@",
clip = "machinic_loop_mechandplayer"
}
}, function(cancelled)
print(cancelled and "Cancelled" or "Complete")
end)
end)
+1
View File
@@ -5,6 +5,7 @@ BridgeClientConfig.HelpTextSystem = "auto"
BridgeClientConfig.ShowHelpText = "ox" -- [ox | jg | qb | lab | custom ] BridgeClientConfig.ShowHelpText = "ox" -- [ox | jg | qb | lab | custom ]
BridgeClientConfig.InputSystem = "auto" -- [ auto | ox | qb ] BridgeClientConfig.InputSystem = "auto" -- [ auto | ox | qb ]
BridgeClientConfig.MenuSystem = "auto" -- [ auto | ox | qb ] BridgeClientConfig.MenuSystem = "auto" -- [ auto | ox | qb ]
BridgeClientConfig.ProgressBarSystem = "auto"
BridgeClientConfig.ZoneSystem = "ox" -- [ ox | poly ] BridgeClientConfig.ZoneSystem = "ox" -- [ ox | poly ]
BridgeClientConfig.ProgressBar = "ox" -- [ ox | qb ] BridgeClientConfig.ProgressBar = "ox" -- [ ox | qb ]
+21
View File
@@ -0,0 +1,21 @@
module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
'plugin:react/recommended',
'plugin:react/jsx-runtime',
'plugin:react-hooks/recommended',
],
ignorePatterns: ['dist', '.eslintrc.cjs'],
parserOptions: { ecmaVersion: 'latest', sourceType: 'module' },
settings: { react: { version: '18.2' } },
plugins: ['react-refresh'],
rules: {
'react/jsx-no-target-blank': 'off',
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
}
+24
View File
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
dist
dist-ssr
*.local
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
+8
View File
@@ -0,0 +1,8 @@
# React + Vite
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
Currently, two official plugins are available:
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
+12
View File
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>MRC Scuba</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="./src/main.jsx"></script>
</body>
</html>
+12078
View File
File diff suppressed because it is too large. Load diff
+31
View File
@@ -0,0 +1,31 @@
{
"name": "sonar-ui",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build --watch",
"lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^6.7.2",
"@fortawesome/free-solid-svg-icons": "^6.7.2",
"@fortawesome/react-fontawesome": "^0.2.2",
"@mantine/core": "^7.17.0",
"@mantine/hooks": "^7.17.0",
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
"devDependencies": {
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@vitejs/plugin-react": "^4.3.1",
"eslint": "^8.57.0",
"eslint-plugin-react": "^7.34.2",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-react-refresh": "^0.4.7",
"vite": "^5.3.1"
}
}
+1
View File
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

+82
View File
@@ -0,0 +1,82 @@
.container {
display: flex;
flex-direction: column;
align-items: center;
width: 100%;
min-height: 100vh;
background: transparent;
}
.dialogue-container {
position: fixed;
bottom: 30px;
width: 66.666%;
background: transparent;
padding: 25px;
left: 50%;
transform: translateX(-50%);
}
.dialogue-text {
background: rgba(0, 0, 0, 0.85);
padding: 20px;
border-radius: 4px;
margin: 15px 0;
line-height: 1.6;
font-size: 1.1em;
border: 1px solid rgba(255, 255, 255, 0.15);
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}
.dialogue-options {
display: flex;
flex-direction: row;
flex-wrap: wrap;
gap: 12px;
justify-content: space-between;
margin-top: 20px;
width: 100%;
}
.dialogue-button {
background: rgba(0, 0, 0, 0.85);
border: 1px solid rgba(255, 255, 255, 0.15);
color: white;
padding: 12px 24px;
border-radius: 4px;
cursor: pointer;
transition: all 0.2s ease;
font-size: 0.95em;
flex: 1;
text-align: center;
min-width: calc(33.333% - 8px);
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}
.dialogue-button:hover {
background: rgba(51, 51, 51, 0.55);
transform: translateY(-1px);
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
border: 1px solid rgba(255, 255, 255, 0.3);
}
h2 {
color: #ffffff;
margin: 0;
font-size: 1.4em;
font-weight: 600;
text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}
p {
color: #fff;
margin: 0;
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}
/* Add this for better text rendering */
* {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
+55
View File
@@ -0,0 +1,55 @@
import { useState } from 'react'
import './dialogue.css'
function Dialogue() {
console.log("Dialogue component loaded")
const [count, setCount] = useState(0)
const [dialogueOptions, setDialogueOption] = useState([])
const [currentText, setCurrentText] = useState("Welcome traveler! How can I help you today?")
const [speakerName, setSpeakerName] = useState("Friendly NPC")
const handleMessage = (event) => {
var data = event.data;
if (data !== undefined && data.type === "hide") {
document.getElementById('root').classList.add("hidden");
}
if (data !== undefined && data.type === "open") {
console.log("Received data: ", data.text)
setDialogueOption(data.options);
setCurrentText(data.text);
setSpeakerName(data.name);
document.getElementById('root').classList.remove("hidden");
}
};
window.addEventListener("message", handleMessage);
return (
<>
<div className="container">
{/* Dialogue System */}
<div className="dialogue-container">
<h2>{speakerName}</h2>
<div className="dialogue-text">
<p>{currentText}</p>
</div>
<div className="dialogue-options">
{dialogueOptions.map((option) => (
<button
key={option.id}
onClick={() => console.log(`Selected: ${option.label}`)}
className="dialogue-button"
>
{option.label}
</button>
))}
</div>
</div>
</div>
</>
)
}
export default Dialogue
+26
View File
@@ -0,0 +1,26 @@
export const fetchNui = async (cbName, data = {}) => {
const options = {
method: 'POST',
headers: {
'Content-Type': 'application/json; charset=UTF-8',
},
body: JSON.stringify(data)
};
try {
const resourceName = window.GetParentResourceName?.() || '';
const resp = await fetch(`https://${resourceName}/${cbName}`, options);
if (!resp.ok) {
throw new Error(`HTTP error! status: ${resp.status}`);
}
return await resp.json();
} catch (error) {
console.error(`Fetch error for ${cbName}:`, error);
if (!window.GetParentResourceName?.()) {
console.error('Resource name is null - are you testing in browser?');
}
return null;
}
};
+9
View File
@@ -0,0 +1,9 @@
.hidden {
display: none;
}
* {
overflow-y: hidden;
overflow-x: hidden;
}
+9
View File
@@ -0,0 +1,9 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import Dialogue from './dialogue';
ReactDOM.createRoot(document.getElementById('root')).render(
<React.StrictMode>
<Dialogue />
</React.StrictMode>
);
+14
View File
@@ -0,0 +1,14 @@
import React from 'react'
import ReactDOM from 'react-dom/client'
import Dialogue from './dialogue.jsx'
import './index.css'
const root = document.getElementById('root')
ReactDOM.createRoot(root).render(
<React.StrictMode>
<Dialogue />
</React.StrictMode>,
)
// add hidden to root element
root.classList.add('hidden')
View File
Whitespace-only changes.
+3
View File
@@ -0,0 +1,3 @@
.hidden {
display: none;
}
+32
View File
@@ -0,0 +1,32 @@
import { useState } from 'react'
import './test.css'
function Dialogue() {
const [count, setCount] = useState(0)
const handleMessage = (event) => {
var data = event.data;
if (data !== undefined && data.type === "hide") {
document.getElementById('root').classList.add("hidden");
}
if (data !== undefined && data.type === "open") {
document.getElementById('root').classList.remove("hidden");
}
};
window.addEventListener("message", handleMessage);
return (
<>
<div className="container">
<img src= "https://dunb17ur4ymx4.cloudfront.net/wysiwyg/1364588/7b504ad7f496249800123e36ecfb3905677e337d.png"></img>
<br></br>
<button onClick={() => setCount(count + 1)}>Click me</button>
<p>You clicked {count} times</p>
</div>
</>
)
}
export default Dialogue
+7
View File
@@ -0,0 +1,7 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
})