Skip to content

Commit

Permalink
Add BASE_URL and apply on all other pages
Browse files Browse the repository at this point in the history
  • Loading branch information
Bret Petersen committed Feb 27, 2024
1 parent 7cfe819 commit 6ed086a
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 21 deletions.
5 changes: 3 additions & 2 deletions src/components/Affirmation.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import "dotenv";
import BorderColorSharpIcon from "@mui/icons-material/BorderColorSharp";
import { useNavigate } from "react-router-dom";

const Affirmation = ({ affirmation, id, currentGroup, affirmationsData }) => {
const navigate = useNavigate();

const BASE_URL = import.meta.env.BASE_URL;
const handleEditAffirmationClick = (e) => {
let editEl = e.target.closest("li");
let editId = editEl.getAttribute("id");
navigate("/edit", {
navigate(`${BASE_URL}edit`, {
state: {
affirmationId: editId,
},
Expand Down
11 changes: 7 additions & 4 deletions src/components/AffirmationParams.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useEffect, useState } from "react";
import { useNavigate } from "react-router-dom";
import "dotenv";
import { toast } from "react-toastify";
import ShortUniqueId from "short-unique-id";
import { motion, easeInOut } from "framer-motion";
Expand All @@ -24,7 +25,9 @@ const uid = new ShortUniqueId();

const AffirmationParams = () => {
const navigate = useNavigate();

const BASE_URL = import.meta.env.BASE_URL;
const PUBLIC_URL = `https://bretpeters3n.github.io/affirmations-vite/`;
// console.log(PUBLIC_URL);
const [affirmationsData, setAffirmationsData] = useState(
requestAndSaveAffirmationsData()
);
Expand Down Expand Up @@ -71,7 +74,7 @@ const AffirmationParams = () => {
});
setCurrentGroup(affirmationsData[0].groups[0].group);
postAffirmationsData(affirmationsData);
navigate("/current");
navigate(`${BASE_URL}current`);
console.log("this is after the 'navigate' that is being skipped");
};

Expand Down Expand Up @@ -110,11 +113,11 @@ const AffirmationParams = () => {

const handleShareAffirmationsClick = () => {
const groupKey = requestCurrentGroupKey(affirmationsData, currentGroup);
const PAGE_PATH = `/affirmations-vite/shared?query=`;
const PAGE_PATH = `shared?query=`;
let affParams = affirmationsData[0].groups[groupKey];
const affParamArray = [affParams].flat();
const affParamArrayString = JSON.stringify(affParamArray);
setUrlFormatted(`${BASE_URL}${PAGE_PATH}${affParamArrayString}`);
setUrlFormatted(`${PUBLIC_URL}${PAGE_PATH}${affParamArrayString}`);
setShowShareModal(true);
};

Expand Down
5 changes: 3 additions & 2 deletions src/components/AffirmationResults.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useNavigate } from "react-router-dom";
import "dotenv";
import SouthIcon from "@mui/icons-material/South";
import MyButton from "./MyButton";
import AffGroupListResults from "./AffGroupListResults";
Expand All @@ -9,10 +10,10 @@ const AffirmationResults = ({
affirmations,
}) => {
const navigate = useNavigate();

const BASE_URL = import.meta.env.BASE_URL;
const handleAddAffirmationClick = () => {
// console.log("add");
navigate("/add", {
navigate(`${BASE_URL}add`, {
state: {
currentGroup: currentGroup,
affirmationsData: affirmationsData,
Expand Down
7 changes: 4 additions & 3 deletions src/pages/AddAffirmation.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useState } from "react";
import { useNavigate, useLocation } from "react-router-dom";
import "dotenv";
import MyButton from "../components/MyButton";
import { toast } from "react-toastify";
import "react-toastify/dist/ReactToastify.css";
Expand All @@ -13,7 +14,7 @@ import ShortUniqueId from "short-unique-id";

const AddAffirmation = () => {
const navigate = useNavigate();

const BASE_URL = import.meta.env.BASE_URL;
const location = useLocation();

const uid = new ShortUniqueId();
Expand Down Expand Up @@ -44,12 +45,12 @@ const AddAffirmation = () => {
toast.success(`Affirmation '${newAffirmation.affirmation}' added!`, {
position: "bottom-center",
});
navigate("/current");
navigate(`${BASE_URL}current`);
}
};

const handleCancelAddAffirmationClick = () => {
navigate("/current");
navigate(`${BASE_URL}current`);
};

return (
Expand Down
5 changes: 3 additions & 2 deletions src/pages/DisplayAffirmations.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import "dotenv";
import { Splide, SplideSlide, SplideTrack } from "@splidejs/react-splide";
import { useNavigate } from "react-router-dom";
import {
Expand All @@ -8,14 +9,14 @@ import MyButton from "../components/MyButton";

const DisplayAffirmations = () => {
const navigate = useNavigate();

const BASE_URL = import.meta.env.BASE_URL;
const affirmationsData = requestAndSaveAffirmationsData();
const currentGroup = affirmationsData[0].currentGroup;
const affirmations = requestGroupAffirmations(affirmationsData, currentGroup);

const handleAddAffirmationClick = () => {
// console.log("add");
navigate("/add", {
navigate(`${BASE_URL}`, {
state: {
currentGroup: currentGroup,
affirmationsData: affirmationsData,
Expand Down
11 changes: 6 additions & 5 deletions src/pages/EditAffirmation.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useState } from "react";
import { useLocation, useNavigate, useParams } from "react-router-dom";
import "dotenv";
import MyButton from "../components/MyButton";
import Modal from "../components/Modal";
import { toast } from "react-toastify";
Expand All @@ -12,7 +13,7 @@ import {

const EditAffirmation = () => {
const navigate = useNavigate();

const BASE_URL = import.meta.env.BASE_URL;
const location = useLocation();

const [showModal, setShowModal] = useState(false);
Expand Down Expand Up @@ -43,7 +44,7 @@ const EditAffirmation = () => {
position: "bottom-center",
});
postAffirmationsData(affirmationsData);
navigate("/current");
navigate(`${BASE_URL}current`);
};

function handleConfirmEditAffirmationClick() {
Expand All @@ -55,21 +56,21 @@ const EditAffirmation = () => {
toast.info(`No changes were made 🧐 Try again?`, {
position: "bottom-center",
});
navigate("/current");
navigate(`${BASE_URL}current`);
} else {
affirmationsData[0].groups[groupKey].affirmations[id].affirmation =
updatedAffirmation;
postAffirmationsData(affirmationsData);
toast.success(`Update to '${updatedAffirmation}', success!`, {
position: "bottom-center",
});
navigate("/current");
navigate(`${BASE_URL}current`);
}
}

function handleCancelEditAffirmationClick() {
// this one is done until you add MODAL or TOAST
navigate("/current");
navigate(`${BASE_URL}current`);
}

return (
Expand Down
7 changes: 4 additions & 3 deletions src/pages/SharedAffirmations.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useState } from "react";
import { useNavigate } from "react-router-dom";
import "dotenv";
import Modal from "../components/Modal";
import MyButton from "../components/MyButton";
import { toast } from "react-toastify";
Expand All @@ -17,7 +18,7 @@ const uid = new ShortUniqueId();

const SharedAffirmations = (props) => {
const navigate = useNavigate();

const BASE_URL = import.meta.env.BASE_URL;
const [showImportedGroupModal, setShowImportedGroupModal] = useState(false);
const [showRenameGroupModal, setShowRenameGroupModal] = useState(false);

Expand Down Expand Up @@ -46,7 +47,7 @@ const SharedAffirmations = (props) => {
};

const handleAboutThisSiteClick = () => {
navigate("/about");
navigate(`${BASE_URL}about`);
};

const handleCreateNewGroup = () => {
Expand All @@ -66,7 +67,7 @@ const SharedAffirmations = (props) => {
affirmationsData[0].groups.push(sharedAffirmationsOBJ[0]);
affirmationsData[0].groups[id].id = uid.rnd();
postAffirmationsData(affirmationsData);
navigate("/");
navigate(`${BASE_URL}`);
toast.success(`Group '${newGroupName}' added. Enjoy!`, {
position: "bottom-center",
});
Expand Down

0 comments on commit 6ed086a

Please sign in to comment.