How to pass the same states to a component and a page in Next.js? - state

I'm new to Next.js and I faces some difficulties when it comes to pass props.
In my homePage (index.js) I've got a component (searchbar) and it collects the inputs from the user in states.
I want to pass theses states infos to a page (Pdrs).
With react I did that to pass props :
<Router>
<Header
/>
<Switch>
<Route path="/pdrs/:id">
<PdrsId />
</Route>
<Route path="/pdrs">
<Pdrs
setSearchCity={setSearchCity}
searchCity={searchCity}
page={page}
setPage={setPage}
/>
</Route>
<Route path="/contact">
<Contact />
</Route>
<Route path="/update">
<Update />
</Route>
{/*keep home page last route*/}
<Route path="/">
<Home
setSearchCity={setSearchCity}
searchCity={searchCity}
page={page}
setPage={setPage}
/>
</Route>
</Switch>
<Footer />
</Router>
The searchbar component was imported in the Home page. The states where passed to homePage (see code above) and then passed to the searchbar component.
But with Next.js I don't have this router anymore.
I have a folder "pages" which contains all my pages (=route).
So how can I pass the same states to my component searchbar and my page PDRS ?

Related

My App downloaded from the playstore fails to call web service

I recently developed a cordova App that is uploaded to google play store. I tested this app on my mobile and simulators for weeks and everything works fine. However, when i download the same app from the playstore it fails to call any of the web services and such doesn't display any content.
cordova : 9.0.1
npm : 6.10.1
cordova-android : 7.0.0
I have gone through every line of code and i can't seem to find the problem, i replaced every single call to window.localStorage to a global variables just to be able to fix what i thought would be the problem.
<?xml version='1.0' encoding='utf-8'?></code>
<widget defaultlocale="en-US" id="com.test.fr" version="1.0.6" android-versionCode="100050" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0" xmlns:vs="http://schemas.microsoft.com/appx/2014/htmlapps">
<content src="index.html" />
<access origin="*" />
<preference name="SplashScreen" value="screen" />
<preference name="windows-target-version" value="8.1" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<platform name="android">
<allow-intent href="market:*" />
</platform>
<platform name="ios">
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
</platform>
<platform name="android">
<icon src="www/res/icon/android/fr_mobile_icon.png" density="ldpi" />
<icon src="www/res/icon/android/fr_mobile_icon.png" density="mdpi" />
<icon src="www/res/icon/android/fr_mobile_icon.png" density="hdpi" />
<icon src="www/res/icon/android/fr_mobile_icon.png" density="xhdpi" />
</platform>
<plugin name="cordova-plugin-device" version="2.0.2" />
<plugin name="cordova-plugin-websql" version="0.0.10" />
<plugin name="cordova-plugin-dialogs" version="2.0.1" />
<plugin name="cordova-plugin-file" version="4.3.3" />
<preference name="target-device" value="handset" />
<preference name="BackupWebStorage" value="local" />
<preference name="android-targetSdkVersion" value="28" />
<preference name="android-minSdkVersion" value="17" />
<preference name="android-maxSdkVersion" value="29" />
<preference name="AndroidPersistentFileLocation" value="Compatibility" />
<plugin name="cordova-custom-config" spec="5.1.0" />
</widget>
Worst part.... No error shown on the device, it just doesn't work.
First of all, you need to figure out what is the output of this error. To allow debug on a release build use android:debuggable on application tag at AndroiManifest.xml (https://developer.android.com/guide/topics/manifest/application-element).
Then, plug the device to your computer and in dev settings (on your device) enable usb debugging. Then, navigate to chrome://inspect/#devices - your device should be appearing and will be a link to your webview.
With the inspector openned, do the request and look to the error on console tab.
I think there's a high chance that the error is a CORS error, may your production server has CORS eabled and then you need to use cordova-plugin-whitelist correctly to send a origin to the server, read more about cordova-plugin-whitelisthere: https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-whitelist/
Try adding android:usesCleartextTraffic="true" to the <application> in the AndroidManifest.xml or as below using config.xml
<platform name="android">
<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
<application android:usesCleartextTraffic="true" />
</edit-config>
</platform>
android:usesCleartextTraffic Indicates whether the app intends to use cleartext network traffic, such as cleartext HTTP. The default
value for apps that target API level 27 or lower is "true". Apps that
target API level 28 or higher default to "false". More info
Cleartext is any transmitted or stored information that is not
encrypted or meant to be encrypted. When an app communicates with
servers using a cleartext network traffic, such as HTTP, it could
raise a risk of eavesdropping and tampering of content which is why in latest Android devices, it's set to false by default.

What is a good/elegant way to handle conditional layout rendering with React Router?

I'm using react-router 2.4.0, but can upgrade to 4.x.x if it provides better ability to handle what I'm looking for, but let's say I have the following:
I have X number of pages: pageA, pageB, pageC, pageD, etc. Every page has 3 root-level components - Nav, Body, Footer. The footer is the same on every page. The Nav however depends on a redux state that indicates whether the user is logged in or not, I'd like to maybe render <Nav /> when logged in and <NavGuest /> or something when logged out. And then finally, the body just depends on which page you want to render, so pageA, pageB could use one layout and pageC, etc. could use another.
My current routes look like:
<Route path="/" component={App}>
<IndexRoute component={HomePage} />
<Route path="A" component={pageA} />
<Route path="B" component={pageB} />
<Route path="C" component={pageC} />
etc...
<Route path="*" component={NotFoundPage} />
</Route>
And inside my App component render() is where I use conditional logic based on redux to show <Nav /> or <NavGuest />, but not sure how to switch the layout based on the particular route. Can you add a custom param to a route, so that in the App component render you can read that and conditionally switch the layout?
What I ended up doing:
<Route path="/" component={App}>
<IndexRoute component={HomePage} />
<Route component={LayoutOne}>
<Route path="A" component={pageA} />
<Route path="B" component={pageB} />
</Route>
<Route component={LayoutTwo}>
<Route path="C" component={pageC} />
etc...
</Route>
<Route path="*" component={NotFoundPage} />
</Route>

making ajax call from within bootstrap modal dialog on change of an element

$('#PolicyTypeId').change(function () {
var url = '#Url.Action("GetTerm", "InsuranceSetup")';
var value = $('#PolicyTypeId').val();
var age = $('#Age').val();
$.getJSON(
url,
{ age: age, plantype: value },
function (data) {
if (data.result == "") {
Notify('There was a problem with the term', 'top-left', '5000', 'danger', 'fa-desktop', true);
}
$('#Term').val(data.result);
}
);
return false;
});
This code is supposed to make an ajax call to get some data from a controller upon a value change on a dropdown element. However, the url is changed to the below url for the request. The customerdetails/edit/id is the url from which the modal dialog is rendered with a partial view that has a form inside.
http://localhost:44379/customerdetails/edit/#Url.Action(%22GetTerm%22,%20%22InsuranceSetup%22)?age=25&plantype=17
Assuming the code you posted is in the view, it looks like Url.Action isn't working. Make sure you have the required settings in web.config:
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>
</configSections>
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Optimization"/>
<add namespace="System.Web.Routing" />
<add namespace="WebApplication1" />
</namespaces>
</pages>
</system.web.webPages.razor>
That's normally in the Views folder.
If the code is in a JavaScript file, the url helper won't actually do anything there.

Is there a way to register your app to some URLs just like in normal Android?

I would like to register my app to foursquare URLs and user would see a Intent chooser between browser and my app. It doesn't seem to work, default browser is always launched.
I was trying to call this code:
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("https://foursquare.com/v/san-francisco-international-airport-sfo/41059b00f964a520850b1fe3"));
startActivity(i);
And I registered this way in manifest:
<activity android:name=".IntentActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="https"
android:host="foursquare.com" />
</activity>
My app was never called, only browser. Are there Intent Choosers on Glass?

Browser is not working in my Blackberry Simulator

I am working on developing Blackberry application using PhoneGap framwork. I have executed the sample app using below link
http://wiki.phonegap.com/w/page/31930982/Getting%20Started%20with%20PhoneGap%20BlackBerry%20WebWorks
But browser is not working in my Simulator.I mean if I try to goto Google site I am getting below error
I tried following steps too
1)I have installed 'BlackBerry Email and MDS Services Simulators 4.1.2'
2)Run the MDS and Run my application
Even I am getting issue. Please advice!
Device details:
Windows OS,PhoneGap,BlackBerry Email and MDS Services Simulators 4.1.2,Simulator:9550,BlackBerry WebWorks SDK 2.3.1.5
Config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--
Widget Configuration Reference:
http://docs.blackberry.com/en/developers/deliverables/15274/
-->
<widget xmlns="http://www.w3.org/ns/widgets"
xmlns:rim="http://www.blackberry.com/ns/widgets"
version="1.0.0.0">
<name>Corperate Directory</name>
<access subdomains="false" uri="http://www.google.com"/>
<description>
A sample application written with Cordova.
</description>
<license href="http://opensource.org/licenses/alphabetical">
</license>
<!-- Cordova API -->
<feature id="blackberry.system" required="true" version="1.0.0.0" />
<feature id="org.apache.cordova" required="true" version="1.0.0" />
<feature id="blackberry.find" required="true" version="1.0.0.0" />
<feature id="blackberry.identity" required="true" version="1.0.0.0" />
<feature id="blackberry.pim.Address" required="true" version="1.0.0.0" />
<feature id="blackberry.pim.Contact" required="true" version="1.0.0.0" />
<feature id="blackberry.io.file" required="true" version="1.0.0.0" />
<feature id="blackberry.utils" required="true" version="1.0.0.0" />
<feature id="blackberry.io.dir" required="true" version="1.0.0.0" />
<feature id="blackberry.app" required="true" version="1.0.0.0" />
<feature id="blackberry.app.event" required="true" version="1.0.0.0" />
<feature id="blackberry.system.event" required="true" version="1.0.0.0"/>
<feature id="blackberry.widgetcache" required="true" version="1.0.0.0"/>
<feature id="blackberry.media.camera" />
<feature id="blackberry.ui.dialog" />
<!-- Cordova API -->
<access subdomains="true" uri="file:///store/home" />
<access subdomains="true" uri="file:///SDCard" />
<!-- Expose access to all URIs, including the file and http protocols -->
<access subdomains="true" uri="*" />
<icon rim:hover="false" src="resources/icon.png" />
<icon rim:hover="true" src="resources/icon.png" />
<rim:loadingScreen backgroundColor="#CFCFCF"
foregroundImage="resources/loading_foreground.png"
onFirstLaunch="true">
<rim:transitionEffect type="fadeOut" />
</rim:loadingScreen>
<content src="index.html" />
<rim:permissions>
<rim:permit>use_camera</rim:permit>
<rim:permit>read_device_identifying_information</rim:permit>
<rim:permit>access_shared</rim:permit>
<rim:permit>read_geolocation</rim:permit>
</rim:permissions>
</widget>
You probably need to whitelist google.com in your config.xml:
<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns="http://www.w3.org/ns/widgets"
xmlns:rim="http://www.blackberry.com/ns/widgets"
version="1.0.0.0">
<name>commonPitfalls</name>
<access subdomains="false" uri="http://www.google.com"/>
</widget>
From: http://supportforums.blackberry.com/t5/Web-and-WebWorks-Development/Common-BlackBerry-WebWorks-development-pitfalls-that-can-be/ta-p/624712
Alternatively, instead of checking google.com, you could use the connection api that PhoneGap offers:
http://docs.phonegap.com/en/1.8.0/cordova_connection_connection.md.html#Connection
Or use an xhr to google.com (with the appropriate whitelisting in your config.xml) to see if you get a response that way instead of loading in a page.