electron-react-boilerplate :sub window on clicking a button - reactjs

i have a doubt that how the reactjs file can be loaded into a new window on
clicking a button in electron-react-boilerplate.
const handleVideoCall=()=>{
const remote=require('electron').remote;
const BrowserWindow=remote.BrowserWindow;
const win = new BrowserWindow({
height: 600,
width: 800,
});
win.loadFile(fileName);
}
handleVideoCall is the method which is called on clicking the button.
FileName is the reactjs file that i needed to open.
As there is no documentation from react-electron-boilerplate i was stuck with this. Any help is appreciable.

i got the answer i think that this will be helpful for lot of peoples as there are no documentation for electron-react-boilerplate.
Make the nodeIntegration to true or preload js.
const handleVideoCallNew = async number => {
const remote=require('electron').remote;
const BrowserWindow=remote.BrowserWindow;
const win = new BrowserWindow({
height: 600,
width: 800,
frame:false,
webPreferences: {
nodeIntegration: true,
}
});
win.loadURL(`file://${__dirname}/app.html#/login`);
}
And on the router file
<Route path="/login" component={Login} />
By using this code we can open the reactjs file and route to login. The app.html is main file which is loaded in main.dev.js in electron-react-boilerplate code. The hashing is simplest method to open the reactjs file.
As the loadURL in electron only loads urls and htmls files we can't open js files. So open the main app.html and hash using routes.

Just create a react videoCall Component then create a window and load a url with query params like this,
const videoCallWidow = new BrowserWindow({
height: 600,
width: 800,
webPreferences: {
nodeIntegration: true,
webSecurity: false,
},
})
videoCallWidow.loadURL(
url.format({
pathname: path.join(__dirname, '../build/index.html'),
protocol: 'file:',
slashes: true,
query: {
page: 'videoCall',
},
})
)
after that, In your index.js file you will get query params so on that you can put a condition to load videoCall Component or app component .
ReactDOM.render(
locationPath === 'videoCall' ? <videoCallComponent /> : <App />,
document.getElementById('root')
)

Related

TradingView widget, advanced chart, not showing in React

I am trying to implement the Advanced chart widget of TradingView in my web application, that is created in React/Javascript, using primereact. I have tried several options before, and the only thing that worked so far was by importing the TradingViewEmbed from "react-tradingview-embed". Unfortunately it only worked with the old version "1.0.2", that has the old advertisement bar in it and also the banner below.
In order to remove those and implement it the way TradingView states I have done the below:
import React, { useEffect } from "react";
import './market-data.css';
const MarketData = () => {
const useScript = url => {
useEffect(() => {
const script = document.createElement('script');
script.src = url;
script.async = true;
document.body.appendChild(script);
return () => {
document.body.removeChild(script);
}
}, [url]);
};
return (
<div className="tradingview-widget-container">
{useScript('https://s3.tradingview.com/tv.js')}
<div id="tradingview_dc023"></div>
<div className="tradingview-widget-copyright"></div>
<script type="text/javascript" nonce>
{
new window.TradingView.widget(
{
autosize: true,
symbol: "FX_IDC:EURUSD",
timezone: "Europe/Amsterdam",
theme: "dark",
style: "2",
enable_publishing: false,
hide_top_toolbar: false,
hide_legend: false,
withdateranges: true,
range: "1D",
hide_side_toolbar: true,
allow_symbol_change: true,
save_image: false,
watchlist: [
"FX_IDC:EURUSD",
"FX_IDC:EURGBP",
"FX_IDC:EURJPY"
],
details: true,
hotlist: false,
calendar: true,
studies: [],
height: "100%",
width: "100%",
container_id: "tradingview_dc023"
})
}
</script>
</div>
)
}
export default MarketData;
Looking at the inspect of the web application it looks fine to me, but the chart/widget is just not showing.
tv.js is loaded:
tv.js
script is loaded and shows the way TradingView states on its website:
script
Could anybody please help and direct me in the right way of fixing this?

Export React Big Scheduler view to PDF / CSV

Has anyone succeeded in exporting the React Scheduler library view(day/week) into PDF or CSV?
Am working on a project that has ability to export to either PDF or CSV.
I have tried html2Canvas and pdfMake solution and the page seem blank.
Kindly help if you have.
Here is how i convert elements to canvas to generate pdf.
const handleExportToPDF = async () => {
html2canvas(document.querySelector('#printpdf'), {height: 1000, width: 800}).then(canvas => {
var data = canvas.toDataURL();
console.log(canvas)
var pdfExportSetting = {
content: [
{
image: await data,
width: 500
}
]
};
pdfMake.createPdf(pdfExportSetting).download("test_file.pdf");
});
};
Here is my scheduler
<span ref={scheduleRef} id='printpdf'>
<Scheduler
schedulerData={schedulerData}
prevClick={prevClick}
nextClick={nextClick}
onSelectDate={onSelectDate}
/>
</span>
Will appreciate.

Is there way to add "Loading screen" when DOM rendering in Next.js app?

I'm trying to turn on loading screen when DOM is loading. In pure react i did it by adding another div with loading-screen in /public/index.html and disabling it when last element loaded. How to achive it in Next.js app?
To achive this, I render my loader inside body tag in _document.js file.
I thought a bit how to detect moment when all of my page content loaded (content, images, fonts, styles) and i got idea to load my fonts in footer, after all content, images and styles are loaded.
I did it, by implementing useEffect() hook in my footer file, and load fonts like this:
const Footer = () => {
React.useEffect(() => {
let fonts = [];
if (typeof window !== "undefinded") {
// Initialize Font
fonts.push(
new FontFace("font1", "url(/fonts/font1.ttf)", {
style: "normal",
weight: "400",
})
);
fonts.push(
new FontFace("font2", "url(/fonts/font2.ttf)", {
style: "bold",
weight: "700",
})
);
// Load all fonts
for (var font in fonts) {
document.fonts.add(font);
font.load();
}
// Disable loading screen when all font are loaded
document.fonts.ready.then(function (e) {
document.getElementById("loading-screen").style.display = "none";
});
}
}, []);
return <>...Footer content</>;
};

How to add default Options for markers

I want to add a different icon to the markers that are created when i click with the marker drawing control.(react-google-maps package)
I tried addding a markerOptions prop in the DrawingManager component but it doesnt seem to work like polygonOptions work.
<GoogleMap defaultZoom={13} defaultCenter={{ lat: 38.022871, lng: 23.790431 }}>
<DrawingManager
ref={props.onDrawingManagerMounted}
defaultDrawingMode={this.state.currentDrawingMode}
defaultOptions={{
drawingControl: true,
drawingControlOptions: {
position: google.maps.ControlPosition.TOP_CENTER,
drawingModes: [
google.maps.drawing.OverlayType.POLYGON,
google.maps.drawing.OverlayType.MARKER
]
},
polygonOptions: this.colorOptions(),
markerOptions: {
icon: {
url: require("../../../assets/images/helipadIcon.png"),
anchor: new google.maps.Point(5, 58)
}
}
}}
Quick tipp: name the package that you are using before you ask your question. It took me a while to find the react-google-maps package on npm.
Check out the official documentation of the named package: https://tomchentw.github.io/react-google-maps/
You will find out that the DrawingManager component doesn't offer a prop named markerOptions or polygonOptions. Instead use the Marker component (https://tomchentw.github.io/react-google-maps/#marker) which offers a property icon of type any.
<Marker icon={} .../>
If you want to change/edit markers that have been drawn using the DrawingManager, you can use the onMarkerComplete callback function that will return the marker object. You can use the marker object to change the icon. See: https://developers.google.com/maps/documentation/javascript/reference/drawing#DrawingManager.markercomplete
const icon = {
url: require("../../../assets/images/helipadIcon.png"),
anchor: new google.maps.Point(5, 58)
};
const onMarkerComplete = (marker) => {
marker.setIcon(icon);
}
return (
<DrawingManager onMarkerComplete={onMarkerComplete} ...>
...
</DrawingManager>
);

React Native - Set localStorage in WebView

I would like to set localStorage in the WebView component before loading the page.
https://facebook.github.io/react-native/docs/webview
My use case for this is that my RN app would like to open a page on it's accompanying website. The website authenticates on load by checking for a token in localStorage. If the token isn't there they will be prompted to login. Seen as the user has already logged in on the app I would prefer it if they could avoid logging in again in the WebView.
You might have overcome the issue. If not here is my solution.
You can use injectedJavaScript property of WebView and add javascript code to add the token on page load.
Example code snippet.
My Custom Javascript code that i need to inject.
let myInjectedJs = `(function(){ let tk = window.localStorage.getItem('tokenKey');
if(!tk || (tk && tk != '${token}')){
window.localStorage.setItem('tokenKey', '${token}');
window.location.reload();
}
})();`;
Code Explanation
Function is called as soon as loaded. Checks if tokenKey is already set. If not set we are setting it to the new token ${token} and reloading the page.
Note: We need to pass function as a string to injectedJavaScript in webview.
Using myInjectedJs in WebView.
<WebView
ref={webView => { this.refWeb = webView; }}
javaScriptEnabled={true}
injectedJavaScript={myInjectedJs}
...
Hope this solves your problem.
injectedJavaScript and window.ReactNativeWebView.postMessage should do the job.
import { WebView } from 'react-native-webview';
const INJECTED_JAVASCRIPT = `(function() {
const tokenLocalStorage = window.localStorage.getItem('token');
window.ReactNativeWebView.postMessage(tokenLocalStorage);
})();`;
export default function App() {
const onMessage = (payload) => {
console.log('payload', payload);
};
return (
<View style={styles.container}>
<StatusBar style="auto" />
<WebView
source={{ uri: 'https://somewebsite.com/login' }}
injectedJavaScript={INJECTED_JAVASCRIPT}
onMessage={onMessage}
/>
</View>
);
}
Payload data:
Object {
"nativeEvent": Object {
"canGoBack": true,
"canGoForward": false,
"data": "your_localstorage_value",
"loading": false,
"target": 3,
"title": "Coil",
"url": "https://somewebsite.com/home",
},
}
Works on both Android and iOS.

Resources