Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Click on the phone number and Serial Number to add to clipboard in settings app #394

Merged
merged 3 commits into from
Jul 25, 2024

Conversation

mrdiamonddirt
Copy link
Contributor

Description

Phone Number and Serial Number copied to clipboard when clicked in settings page
image

Checklist

  • I have personally loaded this code into an updated qbcore project and checked all of its functionality.
  • My code fits the style guidelines.
  • My PR fits the contribution guidelines.

@gononono64
Copy link

gononono64 commented May 4, 2024

Looks solid. This should be added because often, people want to send or use their in-game phone number outside of fivem or are unaware of the radial menu option. Ill test it in a few

Copy link
Contributor

@Z3rio Z3rio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont really think we should be importing yet another library just for something which can be done in 2-3 lines of standard JS, aka setting the clipboard.

QB-Phone is already bloated enough as it is...

@gononono64
Copy link

I dont really think we should be importing yet another library just for something which can be done in 2-3 lines of standard JS, aka setting the clipboard.

QB-Phone is already bloated enough as it is...

Imo copy to clipboard should be part of core

@Z3rio
Copy link
Contributor

Z3rio commented Jun 24, 2024

I dont really think we should be importing yet another library just for something which can be done in 2-3 lines of standard JS, aka setting the clipboard.
QB-Phone is already bloated enough as it is...

Imo copy to clipboard should be part of core

Apart of qb-core? Yeah, perhaps, would be nice when trying to set the clipboard from lua.

Wouldnt really be useable/ideal in this situation even if it was in qb-core though.
As you'd have to go from the UI of qb-phone, to the clientside of qb-phone, then to the clientside of qb-core, then to the UI of qb-core.

Much better to just write those 2-3 lines of JS in qb-phone in this situation.

@mrdiamonddirt
Copy link
Contributor Author

Absolutely 👍 didn't spend too much time with it but I would've thought i'd tried it without a library and thought it didn't work for some reason so probably did that naturally I thought I could do it with native js but not looked at this really since posting was just a quick implementation that worked

@mrdiamonddirt
Copy link
Contributor Author

I might pull it down and have a look again and see why I didn't use the clipboard I'm sure I remember trying it, but someone could always pull it down remove the package add the 2-3 lines of js and that I maybe missed and create the pr again and comment on this to say it's outdated because of pr # I don't have or use qb-phone and am not a "qb-core developer" obviously this isn't top of list of things for me todo 😀 but I appreciate the comments and the response @Z3rio and any constructive criticism is always appreciated

@Z3rio
Copy link
Contributor

Z3rio commented Jun 25, 2024

I might pull it down and have a look again and see why I didn't use the clipboard I'm sure I remember trying it, but someone could always pull it down remove the package add the 2-3 lines of js and that I maybe missed and create the pr again and comment on this to say it's outdated because of pr # I don't have or use qb-phone and am not a "qb-core developer" obviously this isn't top of list of things for me todo 😀 but I appreciate the comments and the response @Z3rio and any constructive criticism is always appreciated

Yeah, well, if qb-core actually cared about PRs and merged them, I'd 110% help you fix up this PR.
But I already have 6 PRs of my own waiting to be merged/reviewed lmfao

@mrdiamonddirt
Copy link
Contributor Author

I completely get that buddy I also like to not have a load of outstanding pr's, so I keep them few and fairly minimal my argument for this way could be yeah it adds 25 lines and a libary but it is a very minimal libary and makes re-use of the copy function I implemented to be very easily re-used elsewhere, yes it may able to be done more minimally, but I honestly like this implementation,😂🤣 and I'm not flaming your comments at all @Z3rio they are obviously valid

Copy link

@ChristianBDev ChristianBDev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add this to the settings.js, line 38

$(document).on(
    "click",
    "#phoneNumberSelect, #serialNumberSelect",
    function (e) {
        // Get the title of the clicked element
        var title = "";
        if ($(this).attr("id") == "phoneNumberSelect") {
            title = "Phone Number";
        } else {
            title = "Serial Number";
        }

        // get the result id of myPhoneNumber or mySerialNumber
        var textToCopy =
            $(this).attr("id") == "phoneNumberSelect"
                ? $("#myPhoneNumber").text()
                : $("#mySerialNumber").text();

        // Copying the text to clipboard using Clipboard.js
        var clipboard = new ClipboardJS(this, {
            text: function () {
                QB.Phone.Notifications.Add("fas fa-phone", "Copied " + title + "!", textToCopy);
                return textToCopy;
            },
        });
    }
);

and delete the line on 1135
<script src="./js/copyclipboard.js"></script>

Copy link

@ChristianBDev ChristianBDev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add this to the ./settings.js instead

$(document).on(
    "click",
    "#phoneNumberSelect, #serialNumberSelect",
    function (e) {
        // Get the title of the clicked element
        var title = "";
        if ($(this).attr("id") == "phoneNumberSelect") {
            title = "Phone Number";
        } else {
            title = "Serial Number";
        }

        // get the result id of myPhoneNumber or mySerialNumber
        var textToCopy =
            $(this).attr("id") == "phoneNumberSelect"
                ? $("#myPhoneNumber").text()
                : $("#mySerialNumber").text();

        // Copying the text to clipboard using Clipboard.js
        var clipboard = new ClipboardJS(this, {
            text: function () {
                QB.Phone.Notifications.Add("fas fa-phone", "Copied " + title + "!", textToCopy);
                return textToCopy;
            },
        });
    }
);

html/index.html Outdated Show resolved Hide resolved
html/js/copyclipboard.js Outdated Show resolved Hide resolved
…opying clipboard as per christians suggestions
Copy link

@ChristianBDev ChristianBDev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested, LGTM

@GhzGarage GhzGarage merged commit bd396e1 into qbcore-framework:main Jul 25, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants