Skip to content

Commit

Permalink
chore: clean console logs
Browse files Browse the repository at this point in the history
  • Loading branch information
clement2026 committed Sep 22, 2023
1 parent 9a3d842 commit 82855cf
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/api/sse/sse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const SSE = () => {
console.info("[SSE] connected to server, response: ", response);
},
onmessage: (msg) => {
console.debug("received an msg from SSE server", msg.event, msg.data.slice(0, 500))
// console.debug("received a msg from SSE server", msg.event, msg.data.slice(0, 500))
const data = JSON.parse(msg.data)
if (msg.event === EventSystemAbility) {
const sa = data as ServerAbility
Expand Down Expand Up @@ -116,11 +116,11 @@ export const SSE = () => {
console.error("[SSE] error:", err)
},
onclose: () => {
console.debug("[SSE] closed")
console.info("[SSE] closed")
}
})
return () => {
console.debug("[SSE] trying to abort")
console.info("[SSE] trying to abort")
ctrl.abort()
}
}, [passwordHash])
Expand Down
34 changes: 30 additions & 4 deletions src/home/chat-window/message-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const MessageList: React.FC<MLProps> = ({chatProxy}) => {
const [hasUpdate, setHasUpdate] = useState(0)
const [hasNewAudio, setHasNewAudio] = useState("")

const [isOverflow, setIsOverflow] = useState(false);
const [isAtBottom, setIsAtBottom] = useState(false);
const containerRef = useRef<HTMLDivElement>(null);

Expand All @@ -50,14 +51,37 @@ export const MessageList: React.FC<MLProps> = ({chatProxy}) => {
scrollToBottom()
}, [id, scrollToBottom]);

const onScroll = useCallback(() => {
}, []);


useEffect(() => {
const observer = new MutationObserver(() => {
if (containerRef.current) {
// console.debug("containerRef.current.scrollHeight > containerRef.current.clientHeight",containerRef.current.scrollHeight > containerRef.current.clientHeight)
setIsOverflow(containerRef.current.scrollHeight > containerRef.current.clientHeight);
}
});

if (containerRef.current) {
observer.observe(containerRef.current, {
attributes: true,
childList: true,
subtree: true,
attributeOldValue: true,
attributeFilter: ['style', 'class'],
});
}
return () => observer.disconnect();
}, []);

useEffect(() => {
const container = containerRef.current;

const handleScroll = () => {
if (container) {
const {scrollTop, scrollHeight, clientHeight} = container;
const isBottom = scrollTop + clientHeight + 50 >= scrollHeight;
console.debug("isBottom", isBottom)
const isBottom = scrollTop + clientHeight >= scrollHeight - 200;
setIsAtBottom(isBottom);
}
};
Expand Down Expand Up @@ -156,7 +180,9 @@ export const MessageList: React.FC<MLProps> = ({chatProxy}) => {
return (
<div ref={containerRef}
className="w-full overflow-y-auto pr-1 scrollbar-hidden hover:scrollbar-visible">
<div className="flex w-full select-text flex-col justify-end gap-3 rounded-2xl">
<div className="flex w-full select-text flex-col justify-end gap-3 rounded-2xl"
onResize={onScroll}
>
{/*crucial; don't merge the 2 divs above*/}
{messages.map((msg, index) =>
msg.status !== 'deleted' &&
Expand All @@ -175,7 +201,7 @@ export const MessageList: React.FC<MLProps> = ({chatProxy}) => {
<div className="sticky bottom-1 flex justify-end pr-3 z-40">
<HiOutlineChevronDown
className={cx("h-8 w-8 p-1.5 bg-neutral-100 rounded-full",
isAtBottom ? "hidden" : "")}
isOverflow && !isAtBottom ? "" : "hidden")}
onClick={() => scrollToBottom("smooth")}
/>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/state/app-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ subscribe(appState, () => {
return
}
const as = snapshot(appState)
console.debug("saving appState:", as)
// console.debug("saving appState:", as)
appDb.setItem(appStateKey, as).then(() => {
console.debug("saved")
})
Expand Down
8 changes: 4 additions & 4 deletions src/state/control-state.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {proxy, ref, subscribe} from "valtio";
import {proxy, ref} from "valtio";
import {EnhancedRecorder} from "../util/enhanced-recorder.ts";
import {popularMimeTypes, RecordingMimeType} from "../config.ts";
import {chooseAudioMimeType} from "../util/util.tsx";
Expand Down Expand Up @@ -58,9 +58,9 @@ export const controlState = proxy<ControlState>({
audioDurationUpdateSignal: 0
})

subscribe(controlState.player, () => {
console.debug("player status:", controlState.player)
})
// subscribe(controlState.player, () => {
// console.debug("player status:", controlState.player)
// })

export const playerState = controlState.player

Expand Down

0 comments on commit 82855cf

Please sign in to comment.