Skip to content

Commit

Permalink
fix: enhance ScrollArea component and update attachment router
Browse files Browse the repository at this point in the history
- Added media query support to conditionally hide scrollbars in the ScrollArea component for better UI on mobile devices.
- Introduced dynamic styling for scrollbar visibility based on screen width.
- Updated attachment router to allow `id` to be either a number or null, improving flexibility in handling attachment deletions.
  • Loading branch information
blinko-space committed Dec 21, 2024
1 parent 267960b commit 2b34bfa
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
21 changes: 20 additions & 1 deletion src/components/Common/ScrollArea/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { _ } from "@/lib/lodash";
import { observer } from "mobx-react-lite";
import { forwardRef, useEffect, useImperativeHandle, useRef, useState } from "react";
import { motion, useAnimation } from "motion/react";
import { useMediaQuery } from "usehooks-ts";

type IProps = {
style?: any;
Expand All @@ -19,6 +20,7 @@ export const ScrollArea = observer(forwardRef<ScrollAreaHandles, IProps>(({ styl
const [isAtTop, setIsAtTop] = useState(false);
const [isAtBottom, setIsAtBottom] = useState(false);
const controls = useAnimation();
const isPc = useMediaQuery('(min-width: 768px)');
let debounceBottom
if (onBottom) {
debounceBottom = _.debounce(onBottom!, 500, { leading: true, trailing: false });
Expand Down Expand Up @@ -67,10 +69,27 @@ export const ScrollArea = observer(forwardRef<ScrollAreaHandles, IProps>(({ styl
<motion.div
ref={scrollRef}
style={style}
className={`${className} overflow-y-scroll overflow-x-hidden`}
className={`${className} overflow-y-scroll overflow-x-hidden ${isPc ? '' : 'scrollbar-hide'}`}
animate={controls}
>
{children}
</motion.div>
);
}))

const styles = `
.scrollbar-hide {
-ms-overflow-style: none; /* IE and Edge */
scrollbar-width: none; /* Firefox */
}
.scrollbar-hide::-webkit-scrollbar {
display: none; /* Chrome, Safari and Opera */
}
`;

if (typeof document !== 'undefined') {
const styleSheet = document.createElement('style');
styleSheet.textContent = styles;
document.head.appendChild(styleSheet);
}
4 changes: 2 additions & 2 deletions src/server/routers/attachment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ export const attachmentsRouter = router({

delete: authProcedure
.input(z.object({
id: z.number().optional(),
id: z.union([z.number(),z.null()]).optional(),
isFolder: z.boolean().optional(),
folderPath: z.string().optional(),
}))
Expand Down Expand Up @@ -385,7 +385,7 @@ export const attachmentsRouter = router({

const attachment = await tx.attachments.findFirst({
where: {
id,
id: id!,
note: {
accountId: Number(ctx.id)
}
Expand Down

0 comments on commit 2b34bfa

Please sign in to comment.