Skip to content

Commit

Permalink
fix bugs with posts
Browse files Browse the repository at this point in the history
  • Loading branch information
SupertigerDev committed Oct 10, 2024
1 parent 4d9c787 commit 2ab1948
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 29 deletions.
10 changes: 2 additions & 8 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,10 @@ export default [
"brace-style": ["error", "stroustrup"],
quotes: ["error", "double"],

indent: [
"error",
2,
{
SwitchCase: 1,
},
],
indent: "off",

semi: ["error", "always"],
"comma-dangle": ["error", "always-multiline"],
"comma-dangle": "off",
},
},
solid,
Expand Down
14 changes: 11 additions & 3 deletions src/components/PostsArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,11 @@ function PostNotification(props: { notification: RawPostNotification }) {
>
<strong
class={notificationUsernameStyles}
style="display: inline-block; max-width: 200px; vertical-align: bottom;"
style={{
display: "inline-block",
"max-width": "200px",
"vertical-align": "bottom",
}}
>
{"username"}
</strong>
Expand Down Expand Up @@ -782,7 +786,11 @@ function PostNotification(props: { notification: RawPostNotification }) {
>
<strong
class={notificationUsernameStyles}
style="display: inline-block; max-width: 200px; vertical-align: bottom;"
style={{
display: "inline-block",
"max-width": "200px",
"vertical-align": "bottom",
}}
>
{"username"}
</strong>
Expand Down Expand Up @@ -912,7 +920,7 @@ export function ViewPostModal(props: { close(): void }) {
<Show when={post()}>
<FlexColumn gap={6}>
<For each={commentToList()}>
{(post) => <PostItem showFullDate disableClick post={post!} />}
{(post) => <PostItem showFullDate post={post!} />}
</For>
</FlexColumn>
<FlexRow
Expand Down
4 changes: 3 additions & 1 deletion src/components/post-area/PostItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function PostItem(props: {
post: Post;
}) {
const { posts } = useStore();
const [, setSearchParams] = useSearchParams<{ postId: string }>();
const [search, setSearchParams] = useSearchParams<{ postId: string }>();
const [hovered, setHovered] = createSignal(false);

const replyingTo = createMemo(() => {
Expand All @@ -61,6 +61,8 @@ export function PostItem(props: {
};

const onClick = (event: any) => {
const alreadyOpened = search.postId === props.post.id;
if (alreadyOpened) return;
if (props.disableClick) return;
if (props.post.deleted) return;
if (event.target.closest(".button")) return;
Expand Down
49 changes: 32 additions & 17 deletions src/components/ui/legacy-modal/LegacyModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,35 +25,50 @@ interface Props {

export default function LegacyModal(props: Props) {
const { isMobileWidth } = useWindowProperties();
let mouseDownTarget: HTMLDivElement | null = null;

const modalContainerStyle = () =>
({
...(props.maxWidth
? {
"max-width": `${props.maxWidth}px`,
}
: {}),
const modalContainerStyle = () => {
const s = {} as JSX.CSSProperties;
if (props.maxWidth) {
s["max-width"] = `${props.maxWidth}px`;
}

...(props.maxHeight
? {
"max-height": `${props.maxHeight}px`,
height: `${isMobileWidth() ? "calc(100% - 20px)" : "100%"}`,
}
: {}),
} as JSX.CSSProperties);
if (props.maxHeight) {
s["max-height"] = `${props.maxHeight}px`;
s.height = `${isMobileWidth() ? "calc(100% - 20px)" : "100%"}`;
}

return s;
};
let startClick = { x: 0, y: 0 };
let textSelected = false;
const onBackgroundClick = (event: MouseEvent) => {
if (props.ignoreBackgroundClick) return;
if (mouseDownTarget?.closest(".modal")) return;
if (event.target !== event.currentTarget) return;

const xDistance = Math.abs(startClick.x - event.clientX);
const yDistance = Math.abs(startClick.y - event.clientY);

const clickedPos = xDistance > 3 || yDistance > 3;
if (clickedPos || textSelected) {
return;
}

props.close?.();
};

const onMouseDown = (event: MouseEvent) => {
startClick = {
x: event.clientX,
y: event.clientY,
};
textSelected = !!window.getSelection()?.toString();
};
return (
<Portal>
<div
class={classNames(styles.backgroundContainer, "modal-bg")}
onClick={onBackgroundClick}
onMouseDown={(e) => (mouseDownTarget = e.target as HTMLDivElement)}
onMouseDown={onMouseDown}
>
<div
style={modalContainerStyle()}
Expand Down

0 comments on commit 2ab1948

Please sign in to comment.