integrated Increase View counts when visited (#73)

This commit is contained in:
Koustav Mondal 2022-03-01 00:12:57 +05:30 committed by GitHub
parent 602a4004f7
commit ed216981f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
32 changed files with 1957 additions and 1578 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.idea

View File

@ -99,3 +99,18 @@ module.exports.addURLAuthed = async (req, res) => {
res.sendStatus(500) res.sendStatus(500)
}) })
} }
module.exports.visitor = async (req, res) => {
Minfy.findOneAndUpdate(
{ alias: req.params.alias },
{ $inc: { views: 1 } },
{ new: true }
)
.then((data) => {
res.send(`views increased`)
})
.catch((err) => {
console.error(err)
res.sendStatus(500)
})
}

View File

@ -15,4 +15,6 @@ router.patch('/edit/:id', auth, controller.updateUrlData)
router.delete('/delete/:id', auth, controller.deleteUrlData) router.delete('/delete/:id', auth, controller.deleteUrlData)
router.get('/:alias/views', controller.visitor)
module.exports = router module.exports = router

View File

@ -1,81 +1,66 @@
import CreateLinkStyle from "./createlink.style"; import CreateLinkStyle from './createlink.style'
function Links() { function Links() {
return ( return (
<div className="frame"> <div className="frame">
<h2> <h2>Create a link</h2>
Create a link
</h2>
<div className="card"> <div className="card">
<form action="#"> <form action="#">
<div className="hugediv"> <div className="hugediv">
<label for="hugeInput">Huge link</label> <label for="hugeInput">Huge link</label>
<input type="text" id="hugeInput" placeholder="https://www.example.com/abc/xyz" /> <input
type="text"
id="hugeInput"
placeholder="https://www.example.com/abc/xyz"
/>
</div> </div>
<div className="aliasdiv"> <div className="aliasdiv">
<label for="customAlias">Custom alias</label> <label for="customAlias">Custom alias</label>
<input type="text" id="customAlias" placeholder="shorturl.com/url" /> <input
type="text"
id="customAlias"
placeholder="shorturl.com/url"
/>
</div> </div>
<div className="titlediv"> <div className="titlediv">
<label for="title">Title</label> <label for="title">Title</label>
<input type="text" id="title" placeholder="Enter the Title" /> <input type="text" id="title" placeholder="Enter the Title" />
</div> </div>
<div className="textdiv"> <div className="textdiv">
<label for="desc">Description</label> <label for="desc">Description</label>
<textarea name="desc" id="desc" cols="30" rows="10" placeholder="Enter the Description"></textarea> <textarea
name="desc"
id="desc"
cols="30"
rows="10"
placeholder="Enter the Description"
></textarea>
</div> </div>
<div className="btndiv"> <div className="btndiv">
<button>Cancel</button>
<button>
Cancel
</button>
<button type="submit" className="submit"> <button type="submit" className="submit">
Submit Submit
</button> </button>
</div> </div>
</form> </form>
</div> </div>
</div> </div>
) )
} }
function CreateLink() { function CreateLink() {
return ( return (
<CreateLinkStyle> <CreateLinkStyle>
<Links /> <Links />
</CreateLinkStyle> </CreateLinkStyle>
) )
}
export default CreateLink
};
export default CreateLink;

View File

@ -1,35 +1,31 @@
import DashboardStyle from "./Dashboard.style"; import DashboardStyle from './Dashboard.style'
function Sidebar1() { function Sidebar1() {
return ( return (
<div className="sidebar"> <div className="sidebar">
<ul> <ul>
<div className="nav-item mb-2 brand-name"><h1>Brand Name</h1></div> <div className="nav-item mb-2 brand-name">
<h1>Brand Name</h1>
</div>
<div className="profile"> <div className="profile">
<div className="profile-image"><img <div className="profile-image">
src="https://png.pngtree.com/png-vector/20190307/ourlarge/pngtree-vector-edit-profile-icon-png-image_760869.jpg"/> <img src="https://png.pngtree.com/png-vector/20190307/ourlarge/pngtree-vector-edit-profile-icon-png-image_760869.jpg" />
</div> </div>
<p className="name">Hayat</p> <p className="name">Hayat</p>
<p className="profession">Product Designer</p> <p className="profession">Product Designer</p>
</div> </div>
<div className="creatButton"> <div className="creatButton">
<button className={""}>Create Link</button> <button className={''}>Create Link</button>
</div> </div>
<li className="nav-buttons"> <li className="nav-buttons">
<div className="nav-item"> <div className="nav-item">
<button> <button>Overview</button>
Overview
</button>
</div> </div>
<div className="nav-item"> <div className="nav-item">
<button> <button>My Links</button>
My Links
</button>
</div> </div>
<div className="nav-item"> <div className="nav-item">
<button> <button>Extras</button>
Extras
</button>
</div> </div>
</li> </li>
</ul> </ul>
@ -68,7 +64,6 @@ function Graph() {
) )
} }
function App() { function App() {
return ( return (
<DashboardStyle> <DashboardStyle>
@ -76,7 +71,7 @@ function App() {
<Sidebar2 /> <Sidebar2 />
<Graph /> <Graph />
</DashboardStyle> </DashboardStyle>
); )
} }
export default App; export default App

View File

@ -1,8 +1,8 @@
import styled from "styled-components" import styled from 'styled-components'
export default styled.div` export default styled.div`
.sidebar { .sidebar {
background-color:#00253A; background-color: #00253a;
float: left; float: left;
width: 20%; width: 20%;
height: 100vh; height: 100vh;
@ -39,7 +39,6 @@ export default styled.div`
} }
} }
.creatButton { .creatButton {
margin: 40px auto 80px; margin: 40px auto 80px;
width: 70%; width: 70%;
button { button {
@ -70,9 +69,9 @@ export default styled.div`
padding-left: 20px; padding-left: 20px;
text-align: left; text-align: left;
:hover { :hover {
background-color:#07344A; background-color: #07344a;
color:#43BFD6; color: #43bfd6;
border-left:5px solid #43BFD6; border-left: 5px solid #43bfd6;
} }
} }
} }

View File

@ -1,20 +1,15 @@
import styled from "styled-components"; import styled from 'styled-components'
export default styled.div` export default styled.div`
h2 { h2 {
color:#00253A; color: #00253a;
font-size: 33px; font-size: 33px;
} }
input { input {
width: 550px; width: 550px;
padding: 16px; padding: 16px;
border-radius: 5px; border-radius: 5px;
background-color:#F2F2F2; background-color: #f2f2f2;
border: none; border: none;
} }
@ -38,15 +33,13 @@ h2{
justify-content: space-between; justify-content: space-between;
align-items: start; align-items: start;
gap: 20px; gap: 20px;
} }
button { button {
width: 49%; width: 49%;
height: 45px; height: 45px;
border-radius: 5px; border-radius: 5px;
background-color:#F2F2F2; background-color: #f2f2f2;
border: none; border: none;
font-size: 16px; font-size: 16px;
cursor: pointer; cursor: pointer;
@ -58,17 +51,13 @@ h2{
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
width: 100%; width: 100%;
} }
.submit { .submit {
background-color:#43BFD6; background-color: #43bfd6;
color: white; color: white;
} }
textarea { textarea {
width: 100%; width: 100%;
height: 150px; height: 150px;
@ -76,7 +65,7 @@ h2{
box-sizing: border-box; box-sizing: border-box;
border: none; border: none;
border-radius: 4px; border-radius: 4px;
background-color:#F2F2F2; background-color: #f2f2f2;
font-size: 16px; font-size: 16px;
resize: none; resize: none;
} }
@ -84,36 +73,14 @@ h2{
width: 100%; width: 100%;
} }
.textdiv, .aliasdiv , .titlediv , .hugediv{ .textdiv,
.aliasdiv,
.titlediv,
.hugediv {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
justify-content: space-between; justify-content: space-between;
align-items: start; align-items: start;
gap: 7px; gap: 7px;
} }
` `

View File

@ -1,4 +1,4 @@
import * as React from "react"; import * as React from 'react'
import { import {
Avatar, Avatar,
Box, Box,
@ -12,21 +12,21 @@ import {
Typography, Typography,
alpha, alpha,
AppBar, AppBar,
} from "@mui/material"; } from '@mui/material'
import QrCodeScannerIcon from "@mui/icons-material/QrCodeScanner"; import QrCodeScannerIcon from '@mui/icons-material/QrCodeScanner'
import RocketLaunchIcon from "@mui/icons-material/RocketLaunch"; import RocketLaunchIcon from '@mui/icons-material/RocketLaunch'
import RemoveRedEyeIcon from "@mui/icons-material/RemoveRedEye"; import RemoveRedEyeIcon from '@mui/icons-material/RemoveRedEye'
import NotFound from "@pages/404"; import NotFound from '@pages/404'
export default function Index() { export default function Index() {
return ( return (
<Box <Box
sx={{ sx={{
flexGrow: 1, flexGrow: 1,
display: "flex", display: 'flex',
flexDirection: "column", flexDirection: 'column',
alignItems: "center", alignItems: 'center',
my: 2, my: 2,
}} }}
> >
@ -37,53 +37,53 @@ export default function Index() {
<Box <Box
sx={{ sx={{
flexGrow: 1, flexGrow: 1,
display: "flex", display: 'flex',
justifyContent: "space-around", justifyContent: 'space-around',
alignContent: "space-around", alignContent: 'space-around',
alignItems: "space-around", alignItems: 'space-around',
width: "50vw", width: '50vw',
}} }}
> >
<Box <Box
style={{ style={{
display: "flex", display: 'flex',
flexDirection: "column", flexDirection: 'column',
justifyContent: "centre", justifyContent: 'centre',
alignItems: "center", alignItems: 'center',
}} }}
> >
<a className="Link" href="NotFound"> <a className="Link" href="NotFound">
<RemoveRedEyeIcon sx={{ width: "3.5rem", height: "3.5rem" }} /> <RemoveRedEyeIcon sx={{ width: '3.5rem', height: '3.5rem' }} />
<h4>VIEW COUNTER</h4> <h4>VIEW COUNTER</h4>
</a> </a>
</Box> </Box>
<Box <Box
style={{ style={{
display: "flex", display: 'flex',
flexDirection: "column", flexDirection: 'column',
justifyContent: "centre", justifyContent: 'centre',
alignItems: "center", alignItems: 'center',
}} }}
> >
<a className="Link" href="NotFound"> <a className="Link" href="NotFound">
<QrCodeScannerIcon sx={{ width: "3.5rem", height: "3.5rem" }} /> <QrCodeScannerIcon sx={{ width: '3.5rem', height: '3.5rem' }} />
<h4>QR CODE</h4> <h4>QR CODE</h4>
</a> </a>
</Box> </Box>
<Box <Box
style={{ style={{
display: "flex", display: 'flex',
flexDirection: "column", flexDirection: 'column',
justifyContent: "centre", justifyContent: 'centre',
alignItems: "center", alignItems: 'center',
}} }}
> >
<a className="Link" href="NotFound"> <a className="Link" href="NotFound">
<RocketLaunchIcon sx={{ width: "3.5rem", height: "3.5rem" }} /> <RocketLaunchIcon sx={{ width: '3.5rem', height: '3.5rem' }} />
<h4>ROBUST API</h4> <h4>ROBUST API</h4>
</a> </a>
</Box> </Box>
</Box> </Box>
</Box> </Box>
); )
} }

View File

@ -1,4 +1,4 @@
import styled from "styled-components"; import styled from 'styled-components'
export default styled.section` export default styled.section`
display: flex; display: flex;
@ -11,4 +11,4 @@ export default styled.section`
align-items: center; align-items: center;
flex-direction: column; flex-direction: column;
} }
`; `

View File

@ -1,94 +1,91 @@
import React, {useState} from "react"; import React, { useState } from 'react'
import HomeSectionStyle from "./HomeSection.style"; import HomeSectionStyle from './HomeSection.style'
import Link from "next/link"; import Link from 'next/link'
import Image from 'next/image' import Image from 'next/image'
import Axios from "helpers/Axios"; import Axios from 'helpers/Axios'
import {Alert, Button, Collapse, IconButton} from "@mui/material"; import { Alert, Button, Collapse, IconButton } from '@mui/material'
import CloseIcon from '@mui/icons-material/Close'; import CloseIcon from '@mui/icons-material/Close'
import ContentCopyIcon from '@mui/icons-material/ContentCopy'; import ContentCopyIcon from '@mui/icons-material/ContentCopy'
import QRCode from 'qrcode' import QRCode from 'qrcode'
import NotFound from "@pages/404"; import NotFound from '@pages/404'
const QR = { const QR = {
marginTop: '1.8em' marginTop: '1.8em',
} }
const head = { const head = {
fontSize: "5.5rem", fontSize: '5.5rem',
fontWeight: "bold", fontWeight: 'bold',
color:"white", color: 'white',
marginBottom: "30px", marginBottom: '30px',
}; }
const box = { const box = {
fontSize: "1.5em", fontSize: '1.5em',
borderRadius: "50px", borderRadius: '50px',
padding: "1em", padding: '1em',
width: "500px", width: '500px',
height: "50px", height: '50px',
outline:"none !important", outline: 'none !important',
border:"none !important", border: 'none !important',
marginBottom:"15px" marginBottom: '15px',
}; }
const btn = { const btn = {
fontWeight: "bold", fontWeight: 'bold',
position: "absolute", position: 'absolute',
alignItems: "center", alignItems: 'center',
right: "0px", right: '0px',
marginRight: "5px", marginRight: '5px',
marginTop: "4.5px", marginTop: '4.5px',
marginBottom: "3px", marginBottom: '3px',
height: "40px", height: '40px',
width: "100px", width: '100px',
borderRadius: "50px", borderRadius: '50px',
}; }
const searchBox = { const searchBox = {
position: "relative", position: 'relative',
}; }
function HomeSection(props) { function HomeSection(props) {
var qrCode; var qrCode
var minifiedUrl; var minifiedUrl
const [disabled, setDisabled] = useState(false) const [disabled, setDisabled] = useState(false)
const [open, setOpen] = React.useState(false); const [open, setOpen] = React.useState(false)
const setMinfy = async () => { const setMinfy = async () => {
setOpen(false) setOpen(false)
setDisabled(true); setDisabled(true)
let res; let res
try { try {
res = await Axios.post(`/minify/add`, { res = await Axios.post(`/minify/add`, {
originalUrl: props.longUrl, originalUrl: props.longUrl,
}); })
} catch (err) { } catch (err) {
console.error(err); console.error(err)
return; return
} }
const data = await res.data; const data = await res.data
props.setShortUrl(data.minifiedUrl); props.setShortUrl(data.minifiedUrl)
minifiedUrl = data.minifiedUrl; minifiedUrl = data.minifiedUrl
navigator.clipboard.writeText(props.shortUrl); navigator.clipboard.writeText(props.shortUrl)
if (minifiedUrl) { if (minifiedUrl) {
generateQR(); generateQR()
} }
await navigator.clipboard.writeText(data.minifiedUrl); await navigator.clipboard.writeText(data.minifiedUrl)
setOpen(true) setOpen(true)
setDisabled(false) setDisabled(false)
}; }
// Generate QRCODE for the generated link // Generate QRCODE for the generated link
const generateQR = async () => { const generateQR = async () => {
try { try {
qrCode = await QRCode.toDataURL(minifiedUrl); qrCode = await QRCode.toDataURL(minifiedUrl)
props.setQrData(qrCode); props.setQrData(qrCode)
props.setShowQrCode(true); props.setShowQrCode(true)
} catch (err) { } catch (err) {
console.error(err) console.error(err)
} }
} }
return ( return (
<HomeSectionStyle> <HomeSectionStyle>
<div className="content"> <div className="content">
<h1 style={head} className="title"> <h1 style={head} className="title">
@ -101,27 +98,46 @@ function HomeSection(props) {
placeholder="Enter the url to be minified......" placeholder="Enter the url to be minified......"
value={props.longUrl} value={props.longUrl}
onChange={(e) => { onChange={(e) => {
props.setLongUrl(e.target.value); props.setLongUrl(e.target.value)
}} }}
/> />
<a href="NotFound"> <a href="NotFound">
<Button variant={"contained"} disabled={disabled} style={btn} id="minify" onClick={setMinfy}> <Button
variant={'contained'}
disabled={disabled}
style={btn}
id="minify"
onClick={setMinfy}
>
MINIFY MINIFY
</Button> </Button>
</a> </a>
</div> </div>
<div style={{marginBottom:"40px",color:"#fff"}}> <div style={{ marginBottom: '40px', color: '#fff' }}>
<h3> <h3>
Need more advanced features? |{" "} Need more advanced features? |{' '}
<Link href="/signup"><span style={{textDecoration:"underline"}}>Create an account</span></Link> <Link href="/signup">
<span style={{ textDecoration: 'underline' }}>
Create an account
</span>
</Link>
</h3> </h3>
</div> </div>
{ // show QR code if a url is generated {
props.showQrCode ? // show QR code if a url is generated
props.showQrCode ? (
<div style={QR}> <div style={QR}>
<Image src={props.qrData} placeholder="blur" blurDataURL width={150} height={150}/> <Image
src={props.qrData}
placeholder="blur"
blurDataURL
width={150}
height={150}
/>
</div> </div>
: "" ) : (
''
)
} }
</div> </div>
<Collapse in={open}> <Collapse in={open}>
@ -132,7 +148,7 @@ function HomeSection(props) {
color="inherit" color="inherit"
size="small" size="small"
onClick={() => { onClick={() => {
setOpen(false); setOpen(false)
}} }}
> >
<CloseIcon fontSize="inherit" /> <CloseIcon fontSize="inherit" />
@ -140,11 +156,17 @@ function HomeSection(props) {
} }
sx={{ mb: 2 }} sx={{ mb: 2 }}
> >
Your Shortened URL: {props.shortUrl} <IconButton onClick={() => navigator.clipboard.writeText(props.shortUrl)} style={{marginLeft:"15px",padding:0}}><ContentCopyIcon /></IconButton> Your Shortened URL: {props.shortUrl}{' '}
<IconButton
onClick={() => navigator.clipboard.writeText(props.shortUrl)}
style={{ marginLeft: '15px', padding: 0 }}
>
<ContentCopyIcon />
</IconButton>
</Alert> </Alert>
</Collapse> </Collapse>
</HomeSectionStyle> </HomeSectionStyle>
); )
} }
export default HomeSection; export default HomeSection

View File

@ -1,4 +1,4 @@
import styled from "styled-components" import styled from 'styled-components'
export default styled.section` export default styled.section`
display: flex; display: flex;

View File

@ -1,4 +1,4 @@
import React from "react"; import React from 'react'
export default function Logo() { export default function Logo() {
return ( return (
@ -22,5 +22,5 @@ export default function Logo() {
</svg> </svg>
<p className="logo-text">URL MINIFY</p> <p className="logo-text">URL MINIFY</p>
</div> </div>
); )
} }

View File

@ -1,4 +1,4 @@
import styled from "styled-components"; import styled from 'styled-components'
import { AppBar } from "@mui/material"; import { AppBar } from '@mui/material'
export default styled(AppBar)``; export default styled(AppBar)``

View File

@ -141,7 +141,11 @@ function Index(props) {
<a href="NotFound"> <a href="NotFound">
<Button <Button
onClick={handleCloseNavMenu} onClick={handleCloseNavMenu}
sx={{ color: 'white', display: 'block', fontSize: 'h5.fontSize' }} sx={{
color: 'white',
display: 'block',
fontSize: 'h5.fontSize',
}}
> >
CREDITS CREDITS
</Button> </Button>

View File

@ -1,4 +1,4 @@
import styled from "styled-components"; import styled from 'styled-components'
export default styled.section` export default styled.section`
display: flex; display: flex;
@ -10,4 +10,4 @@ export default styled.section`
align-items: center; align-items: center;
flex-direction: column; flex-direction: column;
} }
`; `

View File

@ -1,4 +1,4 @@
@import url("https://fonts.googleapis.com/css2?family=Montserrat:wght@100;400;500;700&display=swap"); @import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@100;400;500;700&display=swap');
.reg-label { .reg-label {
font-size: 24px; font-size: 24px;
@ -7,7 +7,7 @@
position: relative; position: relative;
} }
.reg-title { .reg-title {
font-family: "Montserrat", sans-serif; font-family: 'Montserrat', sans-serif;
font-weight: 700; font-weight: 700;
font-size: 36px; font-size: 36px;
text-align: center; text-align: center;
@ -24,7 +24,7 @@
margin-left: 10px; margin-left: 10px;
height: 35px; height: 35px;
width: 340px; width: 340px;
font-family: "Montserrat", sans-serif; font-family: 'Montserrat', sans-serif;
font-weight: 400; font-weight: 400;
font-size: 16px; font-size: 16px;
border-radius: 20px; border-radius: 20px;
@ -63,7 +63,7 @@
.submit-button { .submit-button {
width: 100px; width: 100px;
height: 40px; height: 40px;
font-family: "Montserrat", sans-serif; font-family: 'Montserrat', sans-serif;
font-weight: 400; font-weight: 400;
font-size: 18px; font-size: 18px;
border-radius: 10px; border-radius: 10px;
@ -88,7 +88,7 @@
} }
.foot-text { .foot-text {
font-family: "Montserrat", sans-serif; font-family: 'Montserrat', sans-serif;
font-weight: 400; font-weight: 400;
font-size: 18px; font-size: 18px;
margin-top: 50px; margin-top: 50px;

View File

@ -1,11 +1,11 @@
import axios from "axios"; import axios from 'axios'
var API_URL = process.env.NEXT_PUBLIC_API_URL; var API_URL = process.env.NEXT_PUBLIC_API_URL
export default axios.create({ export default axios.create({
baseURL: API_URL, baseURL: API_URL,
headers: { headers: {
"Content-Type": "application/json", 'Content-Type': 'application/json',
"Access-Control-Allow-Origin": "*", 'Access-Control-Allow-Origin': '*',
}, },
}); })

View File

@ -1,24 +1,24 @@
import { createContext } from "react"; import { createContext } from 'react'
import { useState } from "react"; import { useState } from 'react'
const UserAuth = createContext({ const UserAuth = createContext({
user: null, user: null,
login: () => {}, login: () => {},
logout: () => {}, logout: () => {},
}); })
export const UserAuthProvider = ({ children }) => { export const UserAuthProvider = ({ children }) => {
const [user, setUser] = useState(null); const [user, setUser] = useState(null)
const login = () => { const login = () => {
setUser("default"); setUser('default')
}; }
const logout = () => { const logout = () => {
setUser(null); setUser(null)
}; }
const context = { user, login, logout }; const context = { user, login, logout }
return <UserAuth.Provider value={context}>{children}</UserAuth.Provider>; return <UserAuth.Provider value={context}>{children}</UserAuth.Provider>
}; }
export default UserAuth; export default UserAuth

View File

@ -1,3 +1,3 @@
module.exports = { module.exports = {
reactStrictMode: true, reactStrictMode: true,
}; }

View File

@ -1,16 +1,20 @@
import { urlAlphabet } from 'nanoid'; import { urlAlphabet } from 'nanoid'
import React from 'react'; import React from 'react'
const NotFound = () => { const NotFound = () => {
return ( return (
<div className='Box'> <div className="Box">
<div className='Box2'> <div className="Box2">
<p className='P1'>404 Not Found</p> <p className="P1">404 Not Found</p>
<p className='P2'>The page you are looking for is not available</p> <p className="P2">The page you are looking for is not available</p>
<button className='Button'><a className='Take-me-back' href = "/">Take me back!</a></button> <button className="Button">
<a className="Take-me-back" href="/">
Take me back!
</a>
</button>
</div> </div>
</div> </div>
) )
} }
export default NotFound; export default NotFound

View File

@ -1,105 +1,59 @@
import { useEffect, useState } from "react"; import { useEffect, useState } from 'react'
import Head from "next/head"; import Head from 'next/head'
import HomeSection from "components/HomeSection/homeSection"; import HomeSection from 'components/HomeSection/homeSection'
import NavBar from "components/NavBar"; import NavBar from 'components/NavBar'
import Features from "components/Features"; import Features from 'components/Features'
import { useRouter } from "next/router"; import { useRouter } from 'next/router'
var axios = require("axios"); import axios from 'helpers/Axios'
function Redirector(props) { function Redirector(props) {
const router = useRouter(); const router = useRouter()
// const { id } = router.query;
// useEffect(() => {
// if (id) {
// var config = {
// method: 'get',
// url: `http://localhost:5000/minify/alias/${id}`
// };
// axios(config)
// .then(function (response) {
// if(!response.data.success){
// router.replace('/404')
// }
// else{
// router.replace(response.data.data.originalUrl)
// }
// })
// .catch(function (error) {
// console.log(error);
// });
// }
// },[id])
useEffect(() => { useEffect(() => {
if (!props?.resData.success) { if (!props?.resData.success) {
// router.push('/404') // router.push('/404')
} else { } else {
// router.replace(`${props.resData.data.originalUrl}`) // router.replace(`${props.resData.data.originalUrl}`)
} }
}, []); }, [])
return ( return (
<div className={""}> <div className={''}>
<Head> <Head>
<title>URL MiniFy</title> <title>URL MiniFy</title>
<link rel="icon" href="/favicon.ico" /> <link rel="icon" href="/favicon.ico" />
</Head> </Head>
<main className={"main-bg"}>Not Found</main> <main className={'main-bg'}>Not Found</main>
</div> </div>
); )
} }
Redirector.getInitialProps = async (context) => { Redirector.getInitialProps = async (context) => {
const { id } = context.query; const { id } = context.query
let resData = {}; let resData = {}
if (id) { if (id) {
var config = { axios.get(`/minify/${id}/views`).catch((err) => {
method: "get", console.error(err)
url: `http://localhost:5000/minify/alias/${id}`, })
}; await axios
await axios(config) .get(`/minify/alias/${id}`)
.then(function (response) { .then(function (response) {
resData = response.data; resData = response.data
}) })
.catch(function (error) { .catch(function (error) {
resData = error; resData = error
}); })
} }
if (context?.res) { if (context?.res) {
const go = resData?.data?.originalUrl ? resData?.data?.originalUrl : "/404"; const go = resData?.data?.originalUrl ? resData?.data?.originalUrl : '/404'
console.log(go); console.log(go)
context?.res.writeHead(302, { context?.res.writeHead(302, {
Location: go, Location: go,
}); })
context?.res.end(); context?.res.end()
} }
return {}; return {}
}; }
// export async function getServerSideProps(context){ export default Redirector
// const { id } = context.query;
// let resData = {};
// if (id) {
// var config = {
// method: 'get',
// url: `http://localhost:5000/minify/alias/${id}`
// };
// await axios(config)
// .then(function (response) {
// resData = response.data;
// })
// .catch(function (error) {
// resData = error;
// });
// }
// return {
// props: {
// resData : resData
// }
// }
// }
export default Redirector;

View File

@ -1,19 +1,19 @@
import Document from "next/document"; import Document from 'next/document'
import { ServerStyleSheet } from "styled-components"; import { ServerStyleSheet } from 'styled-components'
export default class MyDocument extends Document { export default class MyDocument extends Document {
static async getInitialProps(ctx) { static async getInitialProps(ctx) {
const sheet = new ServerStyleSheet(); const sheet = new ServerStyleSheet()
const originalRenderPage = ctx.renderPage; const originalRenderPage = ctx.renderPage
try { try {
ctx.renderPage = () => ctx.renderPage = () =>
originalRenderPage({ originalRenderPage({
enhanceApp: (App) => (props) => enhanceApp: (App) => (props) =>
sheet.collectStyles(<App {...props} />), sheet.collectStyles(<App {...props} />),
}); })
const initialProps = await Document.getInitialProps(ctx); const initialProps = await Document.getInitialProps(ctx)
return { return {
...initialProps, ...initialProps,
styles: ( styles: (
@ -22,9 +22,9 @@ export default class MyDocument extends Document {
{sheet.getStyleElement()} {sheet.getStyleElement()}
</> </>
), ),
}; }
} finally { } finally {
sheet.seal(); sheet.seal()
} }
} }
} }

View File

@ -1,5 +1,5 @@
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction // Next.js API route support: https://nextjs.org/docs/api-routes/introduction
export default function handler(req, res) { export default function handler(req, res) {
res.status(200).json({ name: "John Doe" }); res.status(200).json({ name: 'John Doe' })
} }

View File

@ -1,11 +1,11 @@
import React from 'react'; import React from 'react'
import Head from "next/head"; import Head from 'next/head'
import NavBar from "../../components/NavBar"; import NavBar from '../../components/NavBar'
import Dashboard from "components/Dashboard/Dashboard" import Dashboard from 'components/Dashboard/Dashboard'
function Index() { function Index() {
return ( return (
<div className={""}> <div className={''}>
<Head> <Head>
<title>Dashboard</title> <title>Dashboard</title>
<link rel="icon" href="/favicon.ico" /> <link rel="icon" href="/favicon.ico" />
@ -16,7 +16,7 @@ function Index() {
<Dashboard /> <Dashboard />
</main> </main>
</div> </div>
); )
} }
export default Index; export default Index

View File

@ -1,8 +1,8 @@
import { useState } from "react"; import { useState } from 'react'
import Head from "next/head"; import Head from 'next/head'
import NavBar from "components/NavBar"; import NavBar from 'components/NavBar'
import Features from "components/Features"; import Features from 'components/Features'
import Login from "components/Login/Login"; import Login from 'components/Login/Login'
export default function signup() { export default function signup() {
return ( return (
@ -10,5 +10,5 @@ export default function signup() {
<NavBar /> <NavBar />
<Login /> <Login />
</div> </div>
); )
} }

View File

@ -1,8 +1,8 @@
import { useState } from "react"; import { useState } from 'react'
import Head from "next/head"; import Head from 'next/head'
import NavBar from "components/NavBar"; import NavBar from 'components/NavBar'
import Features from "components/Features"; import Features from 'components/Features'
import Reg from "components/Reg/Reg"; import Reg from 'components/Reg/Reg'
export default function signup() { export default function signup() {
return ( return (
@ -10,5 +10,5 @@ export default function signup() {
<NavBar /> <NavBar />
<Reg /> <Reg />
</div> </div>
); )
} }

File diff suppressed because it is too large Load Diff

View File

@ -26,8 +26,8 @@ section {
.flex-column { .flex-column {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
background-image: url("./../assets/bg/main-bg.png"); background-image: url('./../assets/bg/main-bg.png');
} }
.main-bg { .main-bg {
background-image: url("./../assets/bg/main-bg.png"); background-image: url('./../assets/bg/main-bg.png');
} }

View File

@ -1,5 +1,5 @@
.Link { .Link {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center align-items: center;
} }

View File

@ -1,4 +1,4 @@
@import url("https://fonts.googleapis.com/css2?family=Montserrat:wght@100;400;500;700&display=swap"); @import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@100;400;500;700&display=swap');
.reg-label { .reg-label {
font-size: 24px; font-size: 24px;
@ -7,7 +7,7 @@
position: relative; position: relative;
} }
.reg-title { .reg-title {
font-family: "Montserrat", sans-serif; font-family: 'Montserrat', sans-serif;
font-weight: 700; font-weight: 700;
font-size: 36px; font-size: 36px;
text-align: center; text-align: center;
@ -24,7 +24,7 @@
margin-left: 10px; margin-left: 10px;
height: 35px; height: 35px;
width: 340px; width: 340px;
font-family: "Montserrat", sans-serif; font-family: 'Montserrat', sans-serif;
font-weight: 400; font-weight: 400;
font-size: 16px; font-size: 16px;
border-radius: 20px; border-radius: 20px;
@ -63,7 +63,7 @@
.submit-button { .submit-button {
width: 100px; width: 100px;
height: 40px; height: 40px;
font-family: "Montserrat", sans-serif; font-family: 'Montserrat', sans-serif;
font-weight: 400; font-weight: 400;
font-size: 18px; font-size: 18px;
border-radius: 10px; border-radius: 10px;
@ -88,7 +88,7 @@
} }
.foot-text { .foot-text {
font-family: "Montserrat", sans-serif; font-family: 'Montserrat', sans-serif;
font-weight: 400; font-weight: 400;
font-size: 18px; font-size: 18px;
margin-top: 50px; margin-top: 50px;

File diff suppressed because it is too large Load Diff