How do I share an image with text on Whatsapp in reactjs? - javascript

I have tried sharethis-reactjs https://libraries.io/npm/sharethis-reactjs
and also react share https://www.npmjs.com/package/react-share.
All I am able to do is send the url or some text across , I want to send an Image with some text (only image is also fine).
The answers on the internet is only to react-native , I am looking for a solution in reactjs.
I am creating a PWA so it will be working in mobiles.
<InlineShareButtons
config={{
alignment: 'center', // alignment of buttons (left, center, right)
color: 'social', // set the color of buttons (social, white)
enabled: true, // show/hide buttons (true, false)
font_size: 16, // font size for the buttons
labels: 'cta', // button labels (cta, counts, null)
language: 'en', // which language to use (see LANGUAGES)
networks: [ // which networks to include (see SHARING NETWORKS)
'whatsapp',
'linkedin',
'messenger',
'facebook',
'twitter'
],
padding: 12, // padding within buttons (INTEGER)
radius: 4, // the corner radius on each button (INTEGER)
show_total: true,
size: 40, // the size of each button (INTEGER)
// OPTIONAL PARAMETERS
url: '', // (defaults to current url)
image: '', // (defaults to og:image or twitter:image)
description: 'custom text', // (defaults to og:description or twitter:description)
title: 'custom title', // (defaults to og:title or twitter:title)
message: 'custom email text', // (only for email sharing)
subject: 'custom email subject', // (only for email sharing)
username: 'custom twitter handle' // (only for twitter sharing)
}}
/>
Can someone please tell me what I can enter in the image=" " to share an image or any other way to share an image in react js

You can use Web Share API in your React.js web application to share text, URLs, and files.
With the Web Share API, web apps are able to share text, URLs, and files to other apps installed on the device in the same way as native apps.
Web Share API has some limitations:
It can only be used on a site that supports HTTPS.
It must be invoked in response to a user action such as a click.
Invoking it through the onload handler is impossible.
As of mid-2020, it is only available on Safari and on Android in
Chromium forks.
https://web.dev/web-share/
Following code can be used to share text and URL along with an image:
const handleOnSubmit= async()=> {
const response = await fetch(image);
// here image is url/location of image
const blob = await response.blob();
const file = new File([blob], 'share.jpg', {type: blob.type});
console.log(file);
if(navigator.share) {
await navigator.share({
title: "title",
text: "your text",
url: "url to share",
files: [file]
})
.then(() => console.log('Successful share'))
.catch((error) => console.log('Error in sharing', error));
}else {
console.log(`system does not support sharing files.`);
}
}
useEffect(()=> {
if (navigator.share === undefined) {
if (window.location.protocol === 'http:') {
window.location.replace(window.location.href.replace(/^http:/, 'https:'));
}
}
}, []);

Related

WordPress media library with metadata limit

I want to create a media library window. attachment should filter with mime types and metadata.
the mime-type filter is done. How can I build a metadata filter just for this?
function upload_image_tinymce(e) {
e.preventDefault();
var $input_field = $('.mce-my_input_image');
var custom_uploader = wp.media.frames.file_frame = wp.media({
title: 'Add Video',
button: {
text: 'Add Video'
},
library: {
type: [
'video/MP4',
'video/quicktime',
'video/x-m4v',
],
},
multiple: false
});
custom_uploader.on('select', function() {
var attachment = custom_uploader.state().get('selection').first().toJSON();
$input_field.val(attachment.id);
});
custom_uploader.open();
}
I cant help you with the whole filter code (not enoth knowlage ...)
But you can use the hook wp_get_attachment_metadata('attachment id') to get an array with the whole metadata of the attachment.
$meta = wp_get_attachment_metadata(126);
Will produce an array with the metadata from the attachment 126.
$cam = $meta[camera]
$cam will then hold the camera string from the metadata ...
Not much but maybe it will lead you a little bit in the right direction.

Discord.js converting Javascript with console into embeds for discord

So I'm working on a bot right now and when looking at the api I get this as the example of how it'll work.
(async () => {
console.log(await bookwebsite.getHomepage(1))
})()
{
results: [ { bookId: 'web id',
thumbnail: 'thumbnail link',
title: 'book title' },
{ bookId: 'web id',
thumbnail: 'thumbnail link',
title: 'book title' },
{ bookId: 'web id',
thumbnail: 'thumbnail link',
title: 'book title' },
...
],
}
Can anyone lead me in the right direction on how to translate this from a console log script to running it within discord embeds? API WARNING NSFW
I'm not extremely sure what you're meaning as of translating console into embeds but I'm guessing you're trying to format the data returned in the api in to a embed in Discord.
const bookwebsite = require('nhentai-js');
(async () => {
var data = await bookwebsite.getHomepage(1);
data = data.results.slice(0, 25);
if(!data) return message.channel.send('Failed to retrieve data from api. ')
// slices to avoid discord embeds going beyond 25 fields
var embed = new Discord.MessageEmbed()
.setTitle('Results found');
// For each the data that's received(after its trimmed)
data.forEach(d=>{
// For every object inside of data, it takes the name and sets it as a field title and sets the description of the field as the id and thumbnail link.
embed.addField(`Name: ${d.title}`, `ID: ${d.bookId}\nThumbnail: ${d.thumbnail}`)
})
// Embeds done, now need to send into the channel
message.channel.send(embed)
})()
If you need any help further on, please comment below.

chorme extension - How to replace user selected text

I'm working on a translate chrome extension. I want to get the user selection and translate it after the user click on a context menu voice. I've implemented this code but not work as expected. I've tested it on instagram and seems working into the DM input field. The same code will not work as expected with facebook text input for messages or status textarea. How I can manage the selected text replacing after that it's translated?
background.js
const processSelection = (info, tab) => {
axios({
method: 'GET',
url: 'https://translate.googleapis.com/translate_a/single',
params: {
client: 'gtx',
sl: 'auto',
tl: 'en',
dt: 't',
q: info.selectionText
}
}).then( (res) => {
browser.tabs.sendMessage(tab.id, {translation: res.data[0][0][0]});
});
}
browser.contextMenus.create({
id: 'selection-translate',
title: 'Translate selection',
contexts: ['editable','selection']
});
browser.contextMenus.onClicked.addListener(processSelection);
content-script.js
browser.runtime.onMessage.addListener( (message) => {
console.log(message);
const selectedText = window.getSelection();
const range = selectedText.getRangeAt(0);
console.log(range);
// I've tried to use deleteContents() but without selecting the node it will not work
range.selectNodeContents(range.commonAncestorContainer);
range.deleteContents();
// sometimes the text is appended outside the text input/textarea if selectNodeContents isnt used
range.insertNode(document.createTextNode(message.translation));
});
Another doubt I have is about context menu. If I want to add some submenu to the main one, how I will handle the click event?I want to give the user the ability to select the destination language with other context menus, but not sure how to proceed.
Thank you for the help.

React Native - Open mail client with body

I'm using npm pacakge to open mail client with data:
https://www.npmjs.com/package/react-native-mail-compose
Also, I'm using their example:
import MailCompose from 'react-native-mail-compose';
// later in your code...
async sendMail() {
try {
await MailCompose.send({
toRecipients: ['to1#example.com', 'to2#example.com'],
ccRecipients: ['cc1#example.com'],
bccRecipients: ['bcc1#example.com', 'bcc2#example.com'],
subject: 'This is subject',
text: 'This is body',
html: '<p>This is <b>html</b> body</p>', // Or, use this if you want html body. Note that some Android mail clients / devices don't support this properly.
attachments: [{
filename: 'mytext', // [Optional] If not provided, UUID will be generated.
ext: '.txt',
mimeType: 'text/plain',
text: 'Hello my friend', // Use this if the data is in UTF8 text.
data: '...BASE64_ENCODED_STRING...', // Or, use this if the data is not in plain text.
}],
});
} catch (e) {
// e.code may be 'cannotSendMail' || 'cancelled' || 'saved' || 'failed'
}
}
and call this function on button press. All data is OK, except body, for example here in Subject there is "This is subject", in CC of mail clients, there is "cc1#example.com", but body is always empty, I can't ever see "This is body" in mail client.
I've fixed it with another package react-native-send-intent.
It works like a charm! :)
I see, give this package a try.
https://github.com/anarchicknight/react-native-communications
Its very simple to use

Add server params on PWA push notification

Is it possible to add custom title, body, etc. from server params on showNotification method ?
var title = 'My title';
event.waitUntil(
self.registration.showNotification(title, {
body: 'My body',
icon: 'images/icon.png',
tag: 'my-tag'
}));
I use an classic Firebase for stock my user token. For example, on new article, send the article title.
Yes. You can show custom push notifications using data from server, which applies to your use case as well. These notifications can be shown even with your app is not actively used by the user. Like how you receive deals notifications from Amazon app, you can show your new article title and body by getting data from the server using an push event listener like below and use that data to phrase and use it on different parts of your notification.
self.addEventListener('push', function(e) {
var body;
if (e.data) {
body = e.data.text();
} else {
body = 'Push message no payload';
}
var options = {
body: body,
icon: 'images/notification-flat.png',
vibrate: [100, 50, 100],
data: {
dateOfArrival: Date.now(),
primaryKey: 1
},
actions: [
{action: 'explore', title: 'Explore this new world',
icon: 'images/checkmark.png'},
{action: 'close', title: 'I don't want any of this',
icon: 'images/xmark.png'},
]
};
e.waitUntil(
self.registration.showNotification('Push Notification', options)
);
});
For more description, look at Receiving Data in the Service Worker section of this article.

Categories

Resources