Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

const handleClick = async () => {
if (typeof callback !== 'function') return;
if (disabled) return;

if (blockingClick) isSubmitting = true;
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { goto } from '$app/navigation';
import { beforeNavigate, goto } from '$app/navigation';
import { SettingsTile, UploadedPostView } from '$lib/fragments';
import { audience, uploadedImages } from '$lib/store/store.svelte';
import { createPost } from '$lib/stores/posts';
Expand All @@ -12,9 +12,10 @@

let caption: string = $state('');
let error: string = $state('');
let isLeavingPostRoute = false;

$effect(() => {
if (!uploadedImages.value || uploadedImages.value.length === 0) {
if (!isLeavingPostRoute && (!uploadedImages.value || uploadedImages.value.length === 0)) {
window.history.back();
}
});
Expand Down Expand Up @@ -57,11 +58,22 @@
input.value = '';
};

beforeNavigate(({ to }) => {
if (!to?.url.pathname.startsWith('/post')) {
isLeavingPostRoute = true;
if (uploadedImages.value) {
revokeImageUrls(uploadedImages.value);
uploadedImages.value = null;
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}
});

const postSubmissionHandler = async () => {
if (!uploadedImages.value) return;
const images = uploadedImages.value.map((img) => img.url);
try {
await createPost(caption, images);
goto('/home');
} catch (error) {
console.error('Failed to create post:', error);
}
Expand Down
Loading