react js: install downloaded apk - reactjs

I am playing around with reactjs and wanted to prompt an apk install, similar to how you would prompt a .zip download, I have:
return (
<div className="card border-0 flex-row flex-wrap p-0 m-0" style={{background:'none'}}>
<div className="col-2 p-0 m-0">
<div className="card-header border-0 m-0 mt-1 p-0">
<img className="imgBorder" src={require('./assets/img/car.jpg')} width={'95.6dp'} height={'119.5dp'} alt=""/>
</div>
</div>
<div className="col-10">
<div className="card-block align-items-center p-0 m-0">
<h4 className="card-title" style={{color:'white', fontWeight: 'bold'}}>{this.props.title}</h4>
<p className="card-text pl-5 mb-0" style={{color:'white', lineHeight:'1'}}>Sed ut perspiciatis unde omnis iste natus error sit...</p>
<p className="muted m-0 p-0" style={{color:'white', lineHeight:'1.4', fontSize:'80%'}}>05/05/20</p>
<SportsEsportsIcon /><Trans i18nKey='library.play'>Play</Trans>
</div>
</div>
<div className="w-100"></div>
</div>
);
and the href={this.props.url} is pointing to a server with a .apk file. However, when I install the app (PWA), instead of prompting for download, I get taken to the url where the file is. Anyway I can trigger the download?

You need to specify the download attribute on the link, versus linking to the location alone.
Attributes
download
Prompts the user to save the linked URL instead of navigating to it.
Can be used with or without a value
<a
href={this.props.url}
className="playBtn my-2"
download
// or download="myAwesomeApp.apk" if you wanted to provide a name hint
>
<SportsEsportsIcon />
<Trans i18nKey='library.play'>
Play
</Trans>
</a>

Related

How to make an animation in React?

I'm trying to figure out how to add an animation on the next elements. I was trying some stuff but didn't figure it out due the fact that I recently started to learn React.
<div className="gradient2">
<div className="grid grid-rows-3 stoljpi-metci grid-flow-col">
<div className="font-bold text-white pl-1.5 bojaTexta"> {metciTren}</div>
<div className="font-bold text-gray-400 -mt-1"> {clipMetci}</div>
</div>
<>
--Anim should go here, I want the className='slikea' to be animated, like slideIn
<div className='slikea'>
<img className="stoljpi mt-1" src={`${process.env.PUBLIC_URL}/images/${state}.png`} />
</div>
</>
</div>

How do i place the video inside of the React component?

So i have built a react component, and there's supposed to be a video background as a cover, but I just cant seem to make it work.
I just puts the video outside of the component. Can anyone help me with this please. Also I'm using Tailwind.
import React from "react";
export default function Example() {
return (
<div className="items-start flex flex-col p-2 h-96 w-fit ">
<div>
<video autoPlay loop muted>
<source src="Assets/img/video/test.mp4" type="video/mp4" />
</video>
<div className="items-center flex ml-2 mt-2">
<div className="flex-shrink-0 group block">
<div className="flex items-center">
<div>
<img
className="inline-block h-9 w-9 rounded-full"
src="https://images.unsplash.com/photo-1472099645785-5658abf4ff4e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80"
alt=""
/>
</div>
<div className="ml-3">
<p className="text-sm font-medium text-white">Sermad Alladin</p>
<p className="text-sm font-medium text-gray-50">
Elgiganten • 18 t.
</p>
</div>
</div>
</div>
</div>
<div className="items-end self-end flex mt-64">
<div className="flex">
<p className="font-normal h-12 leading-5 w-40 mr-2">
Amazing customer service, but i wish was better...😉
</p>
</div>
<div className="items-center flex h-7 justify-end mb-1 p-2 bg-primary rounded-tl-xl rounded-bl-xl">
<div className="font-bold mx-2 text-white">87</div>
</div>
</div>
</div>
</div>
);
}

Tailwind CSS image absolute using The Next.js Image component

I am trying to use Next.js image component for an image that is absolute.
https://play.tailwindcss.com/BGPOl7QECG
<div class="mt-12 sm:mt-16 lg:mt-0">
<div class="pl-4 -mr-48 sm:pl-6 md:-mr-16 lg:px-0 lg:m-0 lg:relative lg:h-full">
<img class="w-full rounded-xl shadow-xl ring-1 ring-black ring-opacity-5 lg:absolute lg:left-0 lg:h-full lg:w-auto lg:max-w-none" src="https://via.placeholder.com/1920x1080.png" alt="Inbox user interface">
</div>
</div>
I tried this
import Image from 'next/image'
....
<div className="mt-12 sm:mt-16 lg:mt-0">
<div className="pl-4 -mr-48 sm:pl-6 md:-mr-16 lg:px-0 lg:m-0 lg:relative lg:h-full">
<div className="w-full rounded-xl shadow-xl ring-1 ring-black ring-opacity-5 lg:absolute lg:left-0 lg:h-full lg:w-auto lg:max-w-none">
<div className="relative">
<Image src={image} alt={alt} layout="fill" />
</div>
</div>
</div>
</div>
but the image is not positioned correctly similar to how it is when not using Next.js image component. How should I use the Image so it displays similar to the one without Image?
I think you can just append the string directly into the className like so
<Image className="w-full rounded-xl shadow-xl..." ... />
As we can read in official docs layout="fill" :
When fill, the image will stretch both width and height to the
dimensions of the parent element, provided the parent element is
relative.
This is usually paired with the objectFit property.
Ensure the parent element has position: relative in their stylesheet.
Here You have official example (demo the fill layout) and how it use ;-)
And Your code with my little improvements index.js (home page):
import Head from "next/head";
import Image from "next/image";
export default function Home() {
return (
<div>
<Head>
<title>Create Next App</title>
<meta name="description" content="Generated by create next app" />
<link rel="icon" href="/favicon.ico" />
</Head>
<div className="relative bg-white pt-16 pb-32 overflow-hidden">
<div className="relative">
<div className="lg:mx-auto lg:max-w-7xl lg:px-8 lg:grid lg:grid-cols-2 lg:grid-flow-col-dense lg:gap-24">
<div className="px-4 max-w-xl mx-auto sm:px-6 lg:py-16 lg:max-w-none lg:mx-0 lg:px-0">
<div>
<div className="mt-6">
<h2 className="text-3xl font-extrabold tracking-tight text-gray-900">
Title
</h2>
<p className="mt-4 text-lg text-gray-500">
Semper curabitur ullamcorper posuere nunc sed. Ornare
iaculis bibendum malesuada faucibus lacinia porttitor.
Pulvinar laoreet sagittis viverra duis. In venenatis sem
arcu pretium pharetra at. Lectus viverra dui tellus ornare
pharetra.
</p>
</div>
</div>
</div>
<div className="mt-12 sm:mt-16 lg:mt-0">
<div className="pl-4 -mr-48 sm:pl-6 md:-mr-16 lg:px-0 lg:m-0 lg:relative lg:h-full">
<div className="w-full rounded-xl shadow-xl ring-1 ring-black ring-opacity-5 lg:absolute lg:left-0 lg:h-full lg:w-auto lg:max-w-none">
<div
className="relative"
style={{ width: "600px", height: "500px" }}
>
<Image
src="https://images.unsplash.com/photo-1636806663015-088d3d1ce2c8?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1171&q=80"
layout="fill"
alt="happy new year"
objectPosition="center"
objectFit="cover"
/>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
);
}
For these photos to be displayed you need to add this code in next.config.js
module.exports = {
reactStrictMode: true,
images: {
domains: ["images.unsplash.com"],
},
};
Output:
Tested with "tailwindcss": "^3.0.5" "next": "12.0.7", "react": "17.0.2",

tailwind css responsive grid issue

I got issue when trying to add a "screen" prefix to grid-column, the layout is perfect but when I add md: to grid-col-span-6 everything is messed up.
this is the code :
import React from "react";
import app from "../images/app.png";
const Featured = () => {
return (
<div className="mt-52 ">
<h1 className="text-primary-dark-theme text-5xl mt-14">Projects</h1>
<div className="grid grid-cols-12 grid-rows-1 mt-20 ">
<div className="row-start-1 row-span-1 col-start-1 md:col-span-6">
<img src={app} alt="" className="w-full" />
</div>
<div className="row-start-1 row-span-1 col-start-6 col-span-7">
<div className="h-full w-full">
<h1 className="text-right text-primary-dark-theme">
Featured Project
</h1>
<h1 className="text-right text-gray-300 font-bold ">Title</h1>
<p className="p-5 bg-gray-800 text-gray-400 shadow-lg rounded-md mt-5">
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Optio id
doloribus sequi repellendus aperiam dolore!
</p>
</div>
</div>
</div>
</div>
);
};
export default Featured;
This is how the ui looks in md
this is the result i want to have
this what happened when i add md predix to col-span-6
The issue seems to be that when applying the responsive md:col-span-6 it also overrides col-start-1 (you can see the styles no longer applied in the dev tools). Adding md:col-start-1 seems to fix this behaviour.
However, simply changing your image's wrapper <div /> to:
<div class="row-start-1 row-span-1 col-start-1 col-span-12">
Seems to have the desired result.

reactJS open a .pdf file from an external repository

I have a reactJS application hosted on AWS in an S3 instance. I also have a web site hosted on AWS in a different S3 instance. On the web site, I host a bunch of .pdf files. Lets assume I have 3 .pdf files located at:
https://www.mywebsite.com/pdffiles/file001.pdf
https://www.mywebsite.com/pdffiles/file002.pdf
https://www.mywebsite.com/pdffiles/file003.pdf
Is there a way for me to provide my reactJS application users with a series of links to the external .pdf files? I tried the following code:
renderDocuments = () => {
return (
<div>
<div className="documents_background">
<div className="row">
<div className="col-12 text-left text_14">
<label>Below are the links to the participant forms we have available for download. The forms are
in .pdf format. You will need to have Adabe Acrobat Reader installed in order to view these files.</label>
</div>
</div>
<div className="row">
<div className="col-9 text-left text_14">
<label>Form 1</label>
</div>
<div className="col-2 text-right text_14">
<a href="https://www.mywebsite.com/pdffiles/file001.pdf" Target="_blank" >Download</a>
</div>
<div className="col-1">
</div>
</div>
<div className="row">
<div className="col-9 text-left text_14">
<label>Form 2</label>
</div>
<div className="col-2 text-right text_14">
<a href="https://www.mywebsite.com/pdffiles/file002.pdf" Target="_blank" >Download</a>
</div>
<div className="col-1">
</div>
</div>
<div className="row">
<div className="col-9 text-left text_14">
<label>Form 3</label>
</div>
<div className="col-2 text-right text_14">
<a href="https://www.mywebsite.com/pdffiles/file003.pdf" Target="_blank" >Download</a>
</div>
<div className="col-1">
</div>
</div>
</div>
</div>
)
}
when I click on the hyperlink for form 1, I get the following in the console.log:
Resource interpreted as Document but transferred with MIME type application/pdf: "https://www.accurecord-direct.com/dotnet/PDFFILES/VSTA/vstm_enrollment_form.pdf"
The .pdf file does not open and the application just sits there waiting.
Thanks.

Resources