Fixed glitch with back button
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 2m33s

This commit is contained in:
Asher 2025-06-15 21:32:11 +01:00
parent f1ff991010
commit e6f99ba87b
8 changed files with 37 additions and 9 deletions

2
.dockerignore Normal file
View File

@ -0,0 +1,2 @@
.env
buikd-push.sh

View File

@ -12,10 +12,10 @@ fi
echo "$GITEA_PAT" | docker login $GITEA_SERVER -u $GITEA_USER --password-stdin
# Build and tag the Docker image
docker build -t $GITEA_SERVER/$GITEA_USER/$GITEA_REPO:$IMAGE_TAG .
docker build --output=type=docker -t $GITEA_SERVER/$GITEA_USER/$GITEA_REPO:$IMAGE_TAG .
# Push the image
DOCKER_CLI_EXPERIMENTAL=enabled docker --log-level debug push $GITEA_SERVER/$GITEA_USER/$GITEA_REPO:$IMAGE_TAG
docker --log-level debug push $GITEA_SERVER/$GITEA_USER/$GITEA_REPO:$IMAGE_TAG
# Logout to prevent credential storage
docker logout $GITEA_SERVER

View File

@ -54,7 +54,7 @@ export default async function BlogPage() {
<div>
<div style={{paddingTop: "50px"}} className="relative flex justify-center items-center h-[50px]">
<div className="absolute left-0 flex items-center h-full ml-6">
<BackButton />
<BackButton defaultPath="/" />
</div>
<span className="text-xl">Posts</span>
</div>

View File

@ -18,7 +18,7 @@ export default function ExamplePost() {
<PageTransition>
<div style={{paddingTop: "50px"}} className="relative flex justify-center items-center h-[50px]">
<div className="absolute left-0 flex items-center h-full ml-6">
<BackButton />
<BackButton defaultPath="/blog" />
</div>
<span className="text-xl">{title}</span>
</div>

View File

@ -47,7 +47,7 @@ export default function ExamplePost() {
<div className='pb-[20px]'>
<div style={{paddingTop: "50px"}} className="relative flex justify-center items-center h-[50px]">
<div className="absolute left-0 flex items-center h-full ml-6">
<BackButton />
<BackButton defaultPath="/blog" />
</div>
<span className="text-xl">{title}</span>
</div>

View File

@ -48,7 +48,7 @@ export default function ExamplePost() {
<div className='pb-[20px]'>
<div style={{paddingTop: "50px"}} className="relative flex justify-center items-center h-[50px]">
<div className="absolute left-0 flex items-center h-full ml-6">
<BackButton />
<BackButton defaultPath="/blog" />
</div>
<span className="text-sm sm:text-base md:text-xl lg:text-2xl truncate max-w-[80%]">{title}</span>
</div>

View File

@ -42,7 +42,7 @@ export default function ContactPage() {
<div>
<div style={{ paddingTop: "50px" }} className="relative flex justify-center items-center h-[50px]">
<div className="absolute left-0 flex items-center h-full ml-6">
<BackButton />
<BackButton defaultPath="/" />
</div>
<span className="text-xl">Get in touch</span>
</div>

View File

@ -2,12 +2,38 @@
import { IoMdArrowBack } from "react-icons/io";
import { useRouter } from "next/navigation";
import { useEffect, useState } from "react";
export default function BackButton() {
interface BackButtonProps {
defaultPath?: string;
}
export default function BackButton({ defaultPath = "/" }: BackButtonProps) {
const router = useRouter();
const [shouldUseDefault, setShouldUseDefault] = useState(false);
useEffect(() => {
// Check if we should use default path
const hasNoValidHistory = window.history.length <= 1;
const hasNoReferrer = !document.referrer || document.referrer === '';
const referrerIsExternal = document.referrer && !document.referrer.includes(window.location.hostname);
const referrerIsEmpty = document.referrer === 'about:blank' || document.referrer.startsWith('data:');
setShouldUseDefault(hasNoValidHistory || hasNoReferrer || referrerIsExternal || referrerIsEmpty);
}, []);
const handleBack = () => {
if (shouldUseDefault) {
router.push(defaultPath);
} else {
// Try to go back, but fallback to default if it fails
try {
router.back();
} catch (error: unknown) {
console.error("Error going back:", error);
router.push(defaultPath);
}
}
};
return (