Skip to content

Commit

Permalink
made all the server urls
Browse files Browse the repository at this point in the history
  • Loading branch information
faisal-kn committed Dec 25, 2021
1 parent 4dfb61e commit 56bcb4b
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 40 deletions.
5 changes: 4 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@ import Direct from './direct';

const App = () => {
const [logState, setLogState] = React.useState(false);
const [id,setId]=React.useState("");

const logHandler = (state) => {
const logHandler = (state,id) => {
setLogState(state);
setId(id);
};

return (
<AuthContext.Provider
value={{
isLoggedIn: logState,
id,
}}
>
<Switch>
Expand Down
3 changes: 2 additions & 1 deletion src/UI/Button.module.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.btn {
margin: 0px 50px;
margin: 15px 50px;
text-decoration: none;
border: 3px solid yellow;
color: transparent;
Expand All @@ -9,6 +9,7 @@
letter-spacing: 5px;
transition: all 0.5s;
position: relative;
cursor: pointer;
}
.btn:before {
content: "Submit";
Expand Down
1 change: 1 addition & 0 deletions src/context/auth-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from "react";

const AuthContext = React.createContext({
token: "",
id:"",
});

export default AuthContext;
4 changes: 2 additions & 2 deletions src/direct.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const Direct = () => {

const getURL = async () => {
const options = {
url: `http://127.0.0.1:3001/api/v2/shorturl/${shortenedURL}`,
url: `https://urlshortdev.herokuapp.com/api/v2/shorturl/${shortenedURL}`,
method: "GET",
withCredentials: true,
};
Expand All @@ -20,7 +20,7 @@ const Direct = () => {
getURL();
getURL().then((res) => (window.location.href = res));
}, [shortenedURL]);
return <div>Redirecting</div>;
return <div>Please wait we are redirecting</div>;
};

export default Direct;
2 changes: 1 addition & 1 deletion src/pages/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const Home = (props) => {

const logoutHandler = async () => {
const options = {
url: "http://127.0.0.1:3001/api/v2/users/logout",
url: "https://urlshortdev.herokuapp.com/api/v2/users/logout",
method: "GET",
withCredentials: true,
};
Expand Down
1 change: 1 addition & 0 deletions src/pages/Home.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ p {
letter-spacing: 5px;
transition: all 0.5s;
position: relative;
cursor: pointer;
}
.btn:before {
content: "Logout";
Expand Down
6 changes: 3 additions & 3 deletions src/pages/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const Login = (props) => {
const submitHandler = async (e) => {
e.preventDefault();
const options = {
url: "http://127.0.0.1:3001/api/v2/users/login",
url: "https://urlshortdev.herokuapp.com/api/v2/users/login",
method: "POST",
withCredentials: true,
data: {
Expand All @@ -29,9 +29,9 @@ const Login = (props) => {
},
};
const res = await axios(options);
console.log(res.data);

if (res.data.status === "success") {
props.logStateHandler(true);
props.logStateHandler(true, res.data.data.user._id);
history.replace("/");
}
};
Expand Down
8 changes: 4 additions & 4 deletions src/pages/Login.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
margin-top: 5rem;
max-width: 500px;
border: 5px ridge rgb(99, 99, 158);
transition: all 0.3s ease-in;
/* transition: all 0.3s ease-in; */
}

.form {
Expand All @@ -26,12 +26,12 @@
border-color: rgb(230, 230, 70);
text-align: center;
font-weight: bold;
transition: all 0.3s ease-in;
/* transition: all 0.3s ease-in; */
color: rgb(219, 123, 33);
}

.form input:hover {
/* .form input:hover {
background-color: rgb(122, 128, 214);
margin-top: 1rem;
}
} */

5 changes: 3 additions & 2 deletions src/pages/Signup.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const Signup = (props) => {
const submitHandler = async (e) => {
e.preventDefault();
const options = {
url: "http://127.0.0.1:3001/api/v2/users/signup",
url: "https://urlshortdev.herokuapp.com/api/v2/users/signup",
method: "POST",
withCredentials: true,
data: {
Expand All @@ -39,8 +39,9 @@ const Signup = (props) => {
},
};
const res = await axios(options);
console.log(res);
if (res.data.status === "success") {
props.logStateHandler(true);
props.logStateHandler(true, res.data.data.newUser._id);
history.replace("/");
}
};
Expand Down
6 changes: 1 addition & 5 deletions src/pages/Signup.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,11 @@
margin-left: 12%;
margin-top: 0;
text-align: center;
transition: all 0.3s ease-in;
/* transition: all 0.3s ease-in; */
font-weight: bold;
color: rgb(214, 82, 20);
}

/* form input:hover {
background-color: rgb(122, 128, 214);
margin-top: 1rem;
} */

.link {
text-decoration: none;
Expand Down
33 changes: 19 additions & 14 deletions src/pages/UrlForm.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import React from "react";
import { useContext, useState } from "react";
import axios from "axios";
import { NavLink } from "react-router-dom";

import AuthContext from "../context/auth-context";
import classes from "./UrlForm.module.css";
import Button from "../UI/Button";

const UrlForm = () => {
const [fullUrl, setFullUrl] = React.useState("");
const [shortUrl, setShortUrl] = React.useState("");
const [showLink, setShowLink] = React.useState(false);
const [fullUrl, setFullUrl] = useState("");
const [shortUrl, setShortUrl] = useState("");
const [showLink, setShowLink] = useState(false);

const ctx = useContext(AuthContext);
const fullurlChangeHandler = (e) => {
setFullUrl(e.target.value);
};
Expand All @@ -21,11 +23,12 @@ const UrlForm = () => {
const submitHandler = async (e) => {
e.preventDefault();
const options = {
url: "http://127.0.0.1:3001/api/v2/shorturl",
url: "https://urlshortdev.herokuapp.com/api/v2/shorturl",
method: "POST",
withCredentials: true,
data: {
fullUrl,
author: ctx.id,
},
};
if (shortUrl.trim().length !== 0) options.data.shortUrl = shortUrl;
Expand All @@ -41,7 +44,9 @@ const UrlForm = () => {
return (
<div className={classes.container}>
<form className={classes.form} onSubmit={submitHandler}>
<label htmlFor="full">Full Url</label>
<label htmlFor="full" className={classes.full}>
Full Url
</label>
<input
type="text"
id="full"
Expand All @@ -57,15 +62,15 @@ const UrlForm = () => {
value={shortUrl}
/>
<Button type="submit" text="Submit"></Button>
{showLink && (
<div>
<p>Here is your short Url</p>
<NavLink to={`${shortUrl}`} className={classes.small}>
{`http://localhost:3000/${shortUrl}`}
</NavLink>
</div>
)}
</form>
{showLink && (
<div>
<p>Here is your short Url</p>
<NavLink to={`${shortUrl}`} className={classes.small}>
{`http://localhost:3000/${shortUrl}`}
</NavLink>
</div>
)}
</div>
);
};
Expand Down
14 changes: 7 additions & 7 deletions src/pages/UrlForm.module.css
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
.container {
margin: auto;
height: 70vh;
max-width: 70%;
border: 5px ridge rgb(99, 99, 158);
transition: all 0.3s ease-in;
}

.form {
display: flex;
flex-direction: column;
padding-left: 0.75rem;
justify-content: flex-start;
}

.full {
padding-top: 0.5rem;
padding-bottom:0.5rem;
}

.form input {
width: 70%;
outline: none;
Expand All @@ -25,15 +32,9 @@
}

.form label {
padding: 1rem;
padding-bottom: 0;
}

form input:hover {
background-color: rgb(122, 128, 214);
margin-top: 1rem;
}

.link {
text-decoration: none;
transition: all 0.3s ease-in;
Expand All @@ -42,4 +43,3 @@ form input:hover {
.link:hover {
text-decoration: underline;
}

0 comments on commit 56bcb4b

Please sign in to comment.