diff --git a/client/main.lua b/client/main.lua index 9e8dffd..ca74c1d 100644 --- a/client/main.lua +++ b/client/main.lua @@ -27,8 +27,8 @@ CreateThread(function() description = 'Group app to do stuff together', developer = 'solareon', defaultApp = true, - ui = 'slrn_groups/web/dist/assets/index.html', - icon = 'https://cfx-nui-slrn_groups/web/dist/icon.png' + ui = 'http://localhost:3000', + icon = 'https://cfx-nui-slrn_groups/ui/dist/icon.svg' }) if not added then print('Could not add app:', errorMessage) @@ -54,22 +54,22 @@ RegisterNuiCallback('getPlayerData', function(_, cb) end) RegisterNuiCallback('getGroupData', function(_, cb) - cb({}) local groups, inGroup, groupStatus, groupStages = lib.callback.await('slrn_groups:server:getAllGroups') if groups then - exports['lb-phone']:SendCustomAppMessage(identifier, { - action = 'setGroups', - data = groups, - }) + cb(groups) end exports['lb-phone']:SendCustomAppMessage(identifier, { action = 'setInGroup', data = inGroup and true or false }) - exports['lb-phone']:SendCustomAppMessage(identifier, { - action = 'setCurrentGroup', - data = inGroup or nil - }) + lib.callback('slrn_groups:server:getGroupMembersNames', false, function(groupData) + lib.print.error('currentGroupData') + lib.print.error(groupData) + exports['lb-phone']:SendCustomAppMessage(identifier, { + action = 'setCurrentGroup', + data = groupData or {} + }) + end) exports['lb-phone']:SendCustomAppMessage(identifier, { action = 'setGroupJobSteps', data = groupStages or {} @@ -80,11 +80,12 @@ RegisterNuiCallback('getGroupData', function(_, cb) data = {} }) end + -- cb({}) end) RegisterNuiCallback('createGroup', function(data, cb) TriggerServerEvent('slrn_groups:server:createGroup', data) - cb({}) + cb('ok') end) RegisterNuiCallback('joinGroup', function(data, cb) @@ -118,7 +119,7 @@ RegisterNuiCallback('deleteGroup', function(_, cb) end) RegisterNUICallback('getMemberList', function(_, cb) - local groupNames = lib.callback.await('slrn_groups:server:getGroupMembers') + local groupNames = lib.callback.await('slrn_groups:server:getGroupMembersNames') cb(groupNames) end) diff --git a/fxmanifest.lua b/fxmanifest.lua index fa2d5fa..0302fe3 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -17,11 +17,10 @@ server_script 'server/**/*' shared_script '@ox_lib/init.lua' files { - "web/dist/**/*", - "web/icon.png" + "ui/dist/**/*", } -ui_page "web/dist/index.html" +ui_page "ui/dist/index.html" dependency '/assetpacks' diff --git a/server/api.lua b/server/api.lua index 58a2c3c..b793a5a 100644 --- a/server/api.lua +++ b/server/api.lua @@ -164,7 +164,7 @@ function api.DestroyGroup(groupID) table.remove(groups, groupID) TriggerEvent('slrn_groups:server:GroupDeleted', groupID, group:getGroupMembers()) - lib.TriggerClientEvent('slrn_groups:client:refreshGroups', -1, api.GetAllGroups()) + lib.triggerClientEvent('slrn_groups:client:refreshGroups', -1, api.GetAllGroups()) end utils.exportHandler('DestroyGroup', api.DestroyGroup) @@ -177,7 +177,7 @@ function api.AddMember(groupID, source) group:addMember(source) - lib.TriggerClientEvent('slrn_groups:client:refreshGroups', -1, api.GetAllGroups()) + lib.triggerClientEvent('slrn_groups:client:refreshGroups', -1, api.GetAllGroups()) end utils.exportHandler('AddMember', api.AddMember) @@ -232,7 +232,7 @@ function api.RemovePlayerFromGroup(source, groupID) if member.Player == source then table.remove(group.members, i) - lib.TriggerClientEvent('slrn_groups:client:refreshGroups', -1, api.GetAllGroups()) + lib.triggerClientEvent('slrn_groups:client:refreshGroups', -1, api.GetAllGroups()) -- There are no more members in the group, destroy it if memberCount == 1 then @@ -347,14 +347,14 @@ function api.GetGroupMembersNames(groupId) end local members = {} - local amount = 0 for i = 1, #group.members do - amount += 1 - local member = {} - member.name = group.members[i].name - member.Player = group.members[i].Player - members[amount] = member + local member = group.members[i] + + members[i] = { + name = member.name, + Player = member.Player + } end return members @@ -397,8 +397,9 @@ function api.CreateGroup(src, name, password) groups[id] = group + lib.print.error(groups) -- Send non-sensitive data to all clients (id, name, memberCount) - lib.TriggerClientEvent('slrn_groups:client:refreshGroups', -1, api.GetAllGroups()) + lib.triggerClientEvent('slrn_groups:client:refreshGroups', -1, api.GetAllGroups()) return id end diff --git a/server/main.lua b/server/main.lua index d217e21..120281d 100644 --- a/server/main.lua +++ b/server/main.lua @@ -51,6 +51,7 @@ end) ---@param data {name: string, pass: string} RegisterNetEvent('slrn_groups:server:createGroup', function(data) api.CreateGroup(source, data.name, data.pass) + lib.print.error('Group Created') end) @@ -61,16 +62,30 @@ lib.callback.register('slrn_groups:server:getGroupMembers', function(source) local groupId = api.GetGroupByMembers(source) if groupId then + lib.print.error(api.getGroupMembers(groupId)) return api.getGroupMembers(groupId) end end) +---Gets all the player names of the players in the group +---@param source number +---@return table? +lib.callback.register('slrn_groups:server:getGroupMembersNames', function(source) + local groupId = api.GetGroupByMembers(source) + + if groupId then + lib.print.error(api.GetGroupMembersNames(groupId)) + return api.GetGroupMembersNames(groupId) + end +end) + ---Get all groups ---@param source number lib.callback.register('slrn_groups:server:getAllGroups', function(source) local groupId = api.GetGroupByMembers(source) + lib.print.error(api.GetAllGroups()) if groupId then return api.GetAllGroups(), groupId, api.getJobStatus(groupId), api.GetGroupStages(groupId) diff --git a/web/.gitignore b/ui/.gitignore similarity index 100% rename from web/.gitignore rename to ui/.gitignore diff --git a/web/index.html b/ui/index.html similarity index 100% rename from web/index.html rename to ui/index.html diff --git a/web/package.json b/ui/package.json similarity index 100% rename from web/package.json rename to ui/package.json diff --git a/web/postcss.config.js b/ui/postcss.config.js similarity index 100% rename from web/postcss.config.js rename to ui/postcss.config.js diff --git a/web/public/.gitkeep b/ui/public/.gitkeep similarity index 100% rename from web/public/.gitkeep rename to ui/public/.gitkeep diff --git a/web/public/icon.svg b/ui/public/icon.svg similarity index 100% rename from web/public/icon.svg rename to ui/public/icon.svg diff --git a/web/public/screenshot-dark.png b/ui/public/screenshot-dark.png similarity index 100% rename from web/public/screenshot-dark.png rename to ui/public/screenshot-dark.png diff --git a/web/public/screenshot-light.png b/ui/public/screenshot-light.png similarity index 100% rename from web/public/screenshot-light.png rename to ui/public/screenshot-light.png diff --git a/web/src/App.css b/ui/src/App.css similarity index 100% rename from web/src/App.css rename to ui/src/App.css diff --git a/web/src/App.tsx b/ui/src/App.tsx similarity index 85% rename from web/src/App.tsx rename to ui/src/App.tsx index d60022b..e25db55 100644 --- a/web/src/App.tsx +++ b/ui/src/App.tsx @@ -6,7 +6,6 @@ import DataHandler from "./components/DataHandler"; import { GroupJobStep } from "./types/GroupJobStep"; import { Group } from "./types/Group"; import { useNuiEvent } from "./hooks/useNuiEvent"; -import { fetchReactNui } from "./utils/fetchReactNui"; import { useGroupJobStepStore } from "./storage/GroupJobStepStore"; import { useGroupStore } from "./storage/GroupStore"; import { usePlayerDataStore } from "./storage/PlayerDataStore"; @@ -42,35 +41,12 @@ const App = () => { }, [theme]); useEffect(() => { - fetchReactNui("getPlayerData", {}, { - source: 1, - citizenId: 'ABCD1234', - }).then((data) => { + fetchNui("getPlayerData").then((data) => { setPlayerData(data); }); - fetchReactNui("getGroupData", {}, [ - { - id: 1, - name: "Group 1", - memberCount: 1, - }, - { - id: 2, - name: "Group 2", - memberCount: 2, - }, - { - id: 3, - name: "Group 3", - memberCount: 3, - }, - { - id: 4, - name: "Group 4", - memberCount: 4, - } - ]).then((data) => setGroups(data)); + fetchNui("getGroupData").then((data) => setGroups(data)); + // fetchNui("getGroupData").then(() => void); }, []); useEffect(() => { @@ -139,7 +115,7 @@ const App = () => {
Groups
{currentPage === "GroupDashboard" && ( )} {currentPage === "GroupJob" && ( diff --git a/web/src/components/ConfirmationDialog.tsx b/ui/src/components/ConfirmationDialog.tsx similarity index 100% rename from web/src/components/ConfirmationDialog.tsx rename to ui/src/components/ConfirmationDialog.tsx diff --git a/web/src/components/CreateGroup.tsx b/ui/src/components/CreateGroup.tsx similarity index 100% rename from web/src/components/CreateGroup.tsx rename to ui/src/components/CreateGroup.tsx diff --git a/web/src/components/DataHandler.tsx b/ui/src/components/DataHandler.tsx similarity index 100% rename from web/src/components/DataHandler.tsx rename to ui/src/components/DataHandler.tsx diff --git a/web/src/components/GroupDashboard.tsx b/ui/src/components/GroupDashboard.tsx similarity index 91% rename from web/src/components/GroupDashboard.tsx rename to ui/src/components/GroupDashboard.tsx index ee6108c..2ba0610 100644 --- a/web/src/components/GroupDashboard.tsx +++ b/ui/src/components/GroupDashboard.tsx @@ -4,7 +4,6 @@ import JoinGroup from "./JoinGroup"; import PlayerList from "./PlayerList"; import ConfirmationDialog from "./ConfirmationDialog"; import { Group } from "../types/Group"; -import { fetchReactNui } from "../utils/fetchReactNui"; import { usePlayerDataStore } from "../storage/PlayerDataStore"; import { useGroupStore } from "../storage/GroupStore"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; @@ -16,7 +15,7 @@ import { faRightFromBracket, } from "@fortawesome/free-solid-svg-icons"; -const GroupDashboard = ({ setCurrentPage }) => { +const GroupDashboard = ({ setCurrentPage, fetchNui }) => { const { currentGroups, currentGroup, inGroup, } = useGroupStore(); const { playerData } = usePlayerDataStore(); const [showCreateGroup, setShowCreateGroup] = useState(false); @@ -26,26 +25,22 @@ const GroupDashboard = ({ setCurrentPage }) => { const [confirmation, setConfirmation] = useState({ message: null, type: null }); useEffect(() => { - setCurrentGroup( - currentGroups.find((group) => - group.members.some((member) => member.Player === playerData.source) - ) - ); + fetchNui('getMemberList').then((data) => setCurrentGroup(data)); }, [currentGroups]); const handleConfirm = () => { - fetchReactNui(confirmation.type, {}, {}); + fetchNui(confirmation.type); console.log(confirmation); setIsDialogOpen(false); }; const createGroup = (groupData) => { console.log(groupData); - fetchReactNui("createGroup", groupData); + fetchNui("createGroup", {name: groupData.groupName, pass: groupData.password}); }; const joinGroup = (groupData) => { - fetchReactNui("joinGroup", groupData); + fetchNui("joinGroup", {groupData}); console.log(groupData); }; @@ -128,9 +123,10 @@ const GroupDashboard = ({ setCurrentPage }) => {
{currentGroups.map((group) => { let isLeader = group.leader === playerData.source; - let isMember = group.members.some( - (member) => member.Player === playerData.source - ); + // let isMember = group.members.some( + // (member) => member.Player === playerData.source + // ); + let isMember = true; return (
{ {isMember && renderIcons(isLeader, isMember, group)} - {group.members.length} + {group.membercount}
@@ -187,6 +183,7 @@ const GroupDashboard = ({ setCurrentPage }) => { {showPlayerList && ( setShowPlayerList(false)} + fetchNui={fetchNui} currentGroup={currentGroup} /> )} diff --git a/web/src/components/GroupJob.tsx b/ui/src/components/GroupJob.tsx similarity index 97% rename from web/src/components/GroupJob.tsx rename to ui/src/components/GroupJob.tsx index e1fe7e9..9494a9f 100644 --- a/web/src/components/GroupJob.tsx +++ b/ui/src/components/GroupJob.tsx @@ -12,6 +12,10 @@ interface GroupJobProps { initialSteps: GroupJobStep[]; } +const { + fetchNui, +} = window as any; + const GroupJob: React.FC = ({ setCurrentPage }) => { const { currentGroups, currentGroup, setCurrentGroup, inGroup, setInGroup } = useGroupStore(); const { playerData } = usePlayerDataStore(); @@ -35,7 +39,7 @@ const GroupJob: React.FC = ({ setCurrentPage }) => { }, [currentGroups]); const handleConfirm = () => { - fetchReactNui(confirmation.type); + fetchNui(confirmation.type); setIsDialogOpen(false); }; diff --git a/web/src/components/JoinGroup.tsx b/ui/src/components/JoinGroup.tsx similarity index 100% rename from web/src/components/JoinGroup.tsx rename to ui/src/components/JoinGroup.tsx diff --git a/web/src/components/PlayerList.tsx b/ui/src/components/PlayerList.tsx similarity index 86% rename from web/src/components/PlayerList.tsx rename to ui/src/components/PlayerList.tsx index e6a4a11..e0ec3ce 100644 --- a/web/src/components/PlayerList.tsx +++ b/ui/src/components/PlayerList.tsx @@ -4,7 +4,7 @@ import { faUser, faTrash, faCrown } from '@fortawesome/free-solid-svg-icons'; import { usePlayerDataStore } from '../storage/PlayerDataStore'; import { useGroupStore } from '../storage/GroupStore'; -const PlayerList: React.FC = ({ onClose }) => { +const PlayerList: React.FC = ({ onClose, fetchNui }) => { const { playerData } = usePlayerDataStore(); const { currentGroup } = useGroupStore(); @@ -16,17 +16,15 @@ const PlayerList: React.FC = ({ onClose }) => { console.log('Promote Member', member); } - const isLeader = currentGroup.members.find(member => member.Player === playerData.source) && true; - return (

Group Members

-

{currentGroup.GName}

+

{currentGroup.name}

- {currentGroup.members.map((member, index) => { + {currentGroup.map((member, index) => { return (
{ > <> - { (isLeader && member.Player !== playerData.source) && ( + {/* { (isLeader && member.Player !== playerData.source) && ( */} + { (member.Player !== playerData.source) && ( <> ((set) => ({ currentGroups: [], inGroup: false, - setGroups: (data) => set({ currentGroups: data }), - setCurrentGroup: (data) => set({ currentGroup: data }), - setInGroup: (data) => set({ inGroup: data }), + setGroups: (data) => { + console.log("Setting current groups:", data); + set({ currentGroups: data }); + }, + setCurrentGroup: (data) => { + console.log("Setting current group:", data); + set({ currentGroup: data }); + }, + setInGroup: (data) => { + console.log("Setting inGroup:", data); + set({ inGroup: data }); + }, })); \ No newline at end of file diff --git a/web/src/storage/PlayerDataStore.ts b/ui/src/storage/PlayerDataStore.ts similarity index 100% rename from web/src/storage/PlayerDataStore.ts rename to ui/src/storage/PlayerDataStore.ts diff --git a/web/src/storage/PlayerListStore.ts b/ui/src/storage/PlayerListStore.ts similarity index 100% rename from web/src/storage/PlayerListStore.ts rename to ui/src/storage/PlayerListStore.ts diff --git a/web/src/types/Group.ts b/ui/src/types/Group.ts similarity index 100% rename from web/src/types/Group.ts rename to ui/src/types/Group.ts diff --git a/web/src/types/GroupJobStep.ts b/ui/src/types/GroupJobStep.ts similarity index 100% rename from web/src/types/GroupJobStep.ts rename to ui/src/types/GroupJobStep.ts diff --git a/web/src/types/Member.ts b/ui/src/types/Member.ts similarity index 100% rename from web/src/types/Member.ts rename to ui/src/types/Member.ts diff --git a/web/src/utils/fetchReactNui.ts b/ui/src/utils/fetchReactNui.ts similarity index 100% rename from web/src/utils/fetchReactNui.ts rename to ui/src/utils/fetchReactNui.ts diff --git a/web/src/utils/misc.ts b/ui/src/utils/misc.ts similarity index 100% rename from web/src/utils/misc.ts rename to ui/src/utils/misc.ts diff --git a/web/tailwind.config.js b/ui/tailwind.config.js similarity index 100% rename from web/tailwind.config.js rename to ui/tailwind.config.js diff --git a/web/tsconfig.json b/ui/tsconfig.json similarity index 100% rename from web/tsconfig.json rename to ui/tsconfig.json diff --git a/web/vite.config.ts b/ui/vite.config.ts similarity index 100% rename from web/vite.config.ts rename to ui/vite.config.ts