This commit is contained in:
Linden
2022-04-14 06:45:55 +00:00
6 changed files with 53 additions and 14 deletions

View File

@@ -24,11 +24,13 @@ function lib.registerContext(context)
end
end
RegisterNUICallback('openContext', function(id)
RegisterNUICallback('openContext', function(id, cb)
cb(1)
lib.showContext(id)
end)
RegisterNUICallback('clickContext', function(data)
RegisterNUICallback('clickContext', function(data, cb)
cb(1)
if data.event then TriggerEvent(data.event, data.args) end
if data.serverEvent then TriggerServerEvent(data.serverEvent, data.args) end
SetNuiFocus(false, false)
@@ -37,6 +39,7 @@ RegisterNUICallback('clickContext', function(data)
})
end)
RegisterNUICallback('closeContext', function()
RegisterNUICallback('closeContext', function(_, cb)
cb(1)
SetNuiFocus(false, false)
end)

View File

@@ -0,0 +1,22 @@
function lib.inputDialog(heading, rows)
if input then return end
input = promise.new()
SetNuiFocus(true, true)
SendNUIMessage({
action = 'openDialog',
data = {
heading = heading,
inputs = rows
}
})
return Citizen.Await(input)
end
RegisterNUICallback('inputData', function(data, cb)
cb(1)
if not input then return end
if not data then input:resolve() else input:resolve(data) end
SetNuiFocus(false, false)
input = nil
end)

View File

@@ -0,0 +1,14 @@
function lib.showTextUI(text, options)
if not options then options = {} end
options.text = text
SendNUIMessage({
action = 'textUi',
data = options
})
end
function lib.hideTextUI()
SendNUIMessage({
action = 'textUiHide'
})
end

View File

@@ -76,7 +76,7 @@ const InputDialog: React.FC = () => {
<ModalOverlay />
<ModalContent>
<ModalHeader textAlign="center">{inputOptions.heading}</ModalHeader>
<ModalBody>
<ModalBody fontFamily="Poppins">
{inputOptions.inputs.map((input: string, index: number) => (
<Box mb={3} key={`input-${index}`}>
<Text>{input}</Text>

View File

@@ -12,7 +12,7 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
interface Props {
title?: string;
description: string;
description?: string;
duration?: number;
position?: ToastPositionWithLogical;
status?: "info" | "warning" | "success" | "error";
@@ -21,7 +21,7 @@ interface Props {
interface CustomProps {
style?: React.CSSProperties;
description: string;
description?: string;
title?: string;
duration?: number;
icon?: IconProp;
@@ -47,7 +47,6 @@ debugData<CustomProps>([
action: "customNotify",
data: {
description: "Dunak is nerd",
title: "Dunak",
icon: "basket-shopping",
style: {
backgroundColor: "#2D3748",
@@ -61,15 +60,15 @@ const Notifications: React.FC = () => {
const toast = useToast();
useNuiEvent<CustomProps>("customNotify", (data) => {
if (!data.title && !data.description) return;
if (data.id && toast.isActive(data.id)) return;
if (!data.icon) {
//@ts-expect-error because amazing types
data.icon =
data.type === "error"
? "fa-circle-xmark"
? "circle-xmark"
: data.type === "success"
? "fa-circle-check"
: "fa-circle-info";
? "circle-check"
: "circle-info";
}
toast({
@@ -84,15 +83,14 @@ const Notifications: React.FC = () => {
boxShadow="md"
>
<HStack spacing={0}>
{
{data.icon && (
<FontAwesomeIcon
//@ts-expect-error because amazing types
icon={data.icon}
fontSize="1.3em"
style={{ paddingRight: 8 }}
color={data.iconColor}
/>
}
)}
<Box w="100%">
{data.title && <Text as="b">{data.title}</Text>}
{data.description && <Text>{data.description}</Text>}
@@ -104,6 +102,7 @@ const Notifications: React.FC = () => {
});
useNuiEvent<Props>("notify", (data) => {
if (!data.title && !data.description) return;
if (data.id && toast.isActive(data.id)) return;
toast({
title: data.title,

View File

@@ -33,6 +33,7 @@ const TextUI: React.FC = () => {
const [visible, setVisible] = React.useState(false);
useNuiEvent<Props>("textUi", (data) => {
if (!data.position) data.position = "right-center"; // Default right position
setData(data);
setVisible(true);
});