Skip to content

Commit

Permalink
TLChat / websocket utils WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
P-man2976 committed Nov 4, 2023
1 parent 4e3d863 commit 94ecdec
Show file tree
Hide file tree
Showing 20 changed files with 846 additions and 38 deletions.
97 changes: 94 additions & 3 deletions packages/react/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@
"react-router-dom": "^6.17.0",
"react-use": "^17.4.0",
"react-virtuoso": "^4.6.2",
"socket.io-client": "^4.7.2",
"sorted-array-functions": "^1.3.0",
"tailwind-merge": "^1.14.0",
"tailwindcss-animate": "^1.0.7",
"use-seconds": "^1.7.0",
Expand All @@ -85,6 +87,7 @@
"@types/react": "^18.2.31",
"@types/react-dom": "^18.2.14",
"@types/react-grid-layout": "^1.3.4",
"@types/sorted-array-functions": "^1.3.1",
"@typescript-eslint/eslint-plugin": "^6.8.0",
"@typescript-eslint/parser": "^6.8.0",
"@unocss/eslint-config": "^0.56.5",
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/components/chat/LiveChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function LiveChat({

if (needExtension)
return (
<div className="flex items-center justify-center p-4">
<div className="flex h-full items-center justify-center p-4">
<span className="text-center text-sm">
{t("views.watch.chat.archiveNeedExtension", {
0: (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import { CLIPPER_LANGS } from "@/lib/consts";
import { currentLangAtom } from "@/store/i18n";
import { clipLangAtom } from "@/store/i18n";
import {
Command,
CommandInput,
Expand All @@ -18,10 +18,10 @@ import { t } from "i18next";
import { cn } from "@/lib/utils";

export const LanguageSelector = () => {
const [currentLang, setCurrentLang] = useAtom(currentLangAtom);
const [currentLang, setCurrentLang] = useAtom(clipLangAtom);
const [open, setOpen] = React.useState(false);
const [value, setValue] = React.useState("");
console.log(currentLang);

return (
<Popover open={open} onOpenChange={setOpen}>
<PopoverTrigger asChild>
Expand Down
8 changes: 2 additions & 6 deletions packages/react/src/components/player/PlayerDescription.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function PlayerDescription({
const [isExpanded, setIsExpanded] = useState(defaultExpanded);

return (
<div className="flex flex-col gap-2 rounded-lg bg-base-3 p-4">
<div className="align-start flex flex-col gap-2 rounded-lg bg-base-3 p-4">
<div
className={cn("whitespace-pre-wrap text-sm", {
"line-clamp-3": !isExpanded,
Expand All @@ -23,11 +23,7 @@ export function PlayerDescription({
{description}
</div>
{description.split(/\r\n|\r|\n/).length > lines && (
<Button
className="w-full"
variant="outline"
onClick={() => setIsExpanded(!isExpanded)}
>
<Button variant="ghost" onClick={() => setIsExpanded(!isExpanded)}>
{isExpanded ? "Show Less" : "Show More"}
</Button>
)}
Expand Down
66 changes: 64 additions & 2 deletions packages/react/src/components/tldex/TLChat.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,65 @@
export function TLChat() {
return <></>;
import { useSocket } from "@/hooks/useSocket";
import { formatDuration } from "@/lib/time";
import { cn } from "@/lib/utils";
import { roomsAtom } from "@/store/chat";
import { tldexStateAtom } from "@/store/tldex";
import { useAtomValue } from "jotai";
import {
DetailedHTMLProps,
HTMLAttributes,
forwardRef,
useEffect,
} from "react";
import { Virtuoso } from "react-virtuoso";

interface TLChatProps {
videoId: string;
isArchive: boolean;
}

export function TLChat({ videoId, isArchive }: TLChatProps) {
const tldexState = useAtomValue(tldexStateAtom);
const roomID: RoomIDString = `${videoId}/${tldexState.liveTlLang}`;
const { chatDB } = useSocket(roomID);
const { messages } = useAtomValue(roomsAtom(roomID));

useEffect(() => {
chatDB.loadMessages(isArchive ? 0 : 30);
}, []);

return (
<Virtuoso
components={{ Item: TLChatItem }}
className="h-full w-full py-2"
initialTopMostItemIndex={{ index: "LAST", align: "end" }}
alignToBottom
followOutput
startReached={() => chatDB.loadMessages(30)}
data={messages}
itemContent={(_, { message, name, video_offset }) => (
<div className="flex flex-col p-1 px-2">
<span className="line-clamp-1 whitespace-nowrap text-sm text-base-11">
{name}
</span>
<div>
<span className="mr-2 whitespace-nowrap text-xs text-base-11">
{formatDuration(video_offset * 1000)}
</span>
{message}
</div>
</div>
)}
/>
);
}

const TLChatItem = forwardRef<
HTMLDivElement,
DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>
>((props, ref) => (
<div
{...props}
className={cn(props.className, "border-base-4 border-b-2 last:border-b-0")}
ref={ref}
/>
));
Loading

0 comments on commit 94ecdec

Please sign in to comment.