Skip to content

Commit

Permalink
fix: prevent unload if content exists
Browse files Browse the repository at this point in the history
  • Loading branch information
mary-ext committed Jan 4, 2024
1 parent 7e1b05a commit 8fbc43e
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions app/desktop/components/composer/ComposerPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { type JSX, For, Show, batch, createEffect, createMemo, createSignal, unt
import { unwrap } from 'solid-js/store';

import { createQuery, useQueryClient } from '@pkg/solid-query';
import { makeEventListener } from '@solid-primitives/event-listener';

import type { DID, Records, RefOf, UnionOf } from '~/api/atp-schema.ts';
import { multiagent } from '~/api/globals/agent.ts';
Expand Down Expand Up @@ -151,6 +152,18 @@ const ComposerPane = () => {
};
});

const hasContents = createMemo(() => {
for (let i = 0, il = posts.length; i < il; i++) {
const draft = posts[i];

if (draft.images.length > 0 || getRtLength(draft.rt) > 0) {
return true;
}
}

return false;
});

const isSubmitDisabled = createMemo(() => {
if (log().t === LogType.PENDING || (state.reply && !replying.data)) {
return true;
Expand Down Expand Up @@ -592,6 +605,14 @@ const ComposerPane = () => {
}
});

createEffect(() => {
if (hasContents()) {
makeEventListener(window, 'beforeunload', (ev) => {
ev.preventDefault();
});
}
});

return (
<div class="flex w-96 shrink-0 flex-col border-r border-divider">
<div class="flex h-13 shrink-0 items-center gap-2 border-b border-divider px-4">
Expand Down

0 comments on commit 8fbc43e

Please sign in to comment.