-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added channels, members in schema and in workspace sidebar, added sid…
…ebar-item
- Loading branch information
Showing
13 changed files
with
241 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { getAuthUserId } from "@convex-dev/auth/server"; | ||
import { query } from "./_generated/server"; | ||
import { v } from "convex/values"; | ||
|
||
export const get = query({ | ||
args: { | ||
workspaceId: v.id("workspaces"), | ||
}, | ||
handler: async (ctx, args) => { | ||
const userId = await getAuthUserId(ctx); | ||
if (!userId) return []; | ||
|
||
const member = await ctx.db | ||
.query("members") | ||
.withIndex("by_workspace_id_user_id", (q) => | ||
q.eq("workspaceId", args.workspaceId).eq("userId", userId) | ||
) | ||
.unique(); | ||
|
||
if (!member) return []; | ||
|
||
const channels = await ctx.db | ||
.query("channels") | ||
.withIndex("by_workspace_id", (q) => | ||
q.eq("workspaceId", args.workspaceId) | ||
) | ||
.collect(); | ||
|
||
return channels; | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import Link from "next/link"; | ||
import { cva, type VariantProps } from "class-variance-authority"; | ||
import { useWorkspaceId } from "@/hooks/use-workspace-id"; | ||
|
||
import { Button } from "@/components/ui/button"; | ||
import { LucideIcon } from "lucide-react"; | ||
import { IconType } from "react-icons/lib"; | ||
import { cn } from "@/lib/utils"; | ||
|
||
const SidebarItemVariants = cva( | ||
"flex items-center gap-1.5 justify-start font-normal h-7 px-[18px] text-sm overflow-hidden", | ||
{ | ||
variants: { | ||
variant: { | ||
default: "text-[#f9edffcc]", | ||
active: "text-[#481349] bg-white/90", | ||
}, | ||
}, | ||
defaultVariants: { | ||
variant: "default", | ||
}, | ||
} | ||
); | ||
|
||
interface SidebarItemProps { | ||
label: string; | ||
id: string; | ||
icon: LucideIcon | IconType; | ||
variant?: VariantProps<typeof SidebarItemVariants>["variant"]; | ||
} | ||
|
||
export const SidebarItem = ({ | ||
label, | ||
id, | ||
icon: Icon, | ||
variant, | ||
}: SidebarItemProps) => { | ||
const workspaceId = useWorkspaceId(); | ||
return ( | ||
<Button | ||
variant="transparent" | ||
size="sm" | ||
asChild | ||
className={cn(SidebarItemVariants({ variant }))} | ||
> | ||
<Link href={`/workspace/${workspaceId}/channel/${id}`}> | ||
<Icon className="size-3.5 mr-1 shrink-0" /> | ||
<span className="text-sm truncate">{label}</span> | ||
</Link> | ||
</Button> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { Hint } from "@/components/hint"; | ||
import { Button } from "@/components/ui/button"; | ||
import { cn } from "@/lib/utils"; | ||
import { PlusIcon } from "lucide-react"; | ||
import { FaCaretDown } from "react-icons/fa"; | ||
import { useToggle } from "react-use"; | ||
interface WorkspaceSectionProps { | ||
children: React.ReactNode; | ||
label: string; | ||
hint: string; | ||
onNew?: () => void; | ||
} | ||
|
||
export const WorkspaceSection = ({ | ||
children, | ||
label, | ||
hint, | ||
onNew, | ||
}: WorkspaceSectionProps) => { | ||
const [on, toggle] = useToggle(true); | ||
return ( | ||
<div className="flex flex-col mt-3 px-2"> | ||
<div className="flex items-center px-3.5 group"> | ||
<Button | ||
variant="transparent" | ||
className="p-0.5 text-sm text-[#f9edffcc] shrink-0 size-6" | ||
onClick={toggle} | ||
> | ||
<FaCaretDown | ||
className={cn("size-4 transition-transform", on && "-rotate-90")} | ||
/> | ||
</Button> | ||
<Button | ||
variant="transparent" | ||
size="sm" | ||
className="group px-1.5 text-[#f9edffcc] h-[28px] justify-start items-center overflow-hidden" | ||
> | ||
<span className="truncate">{label}</span> | ||
</Button> | ||
{onNew && ( | ||
<Hint label={hint} side="top" align="center"> | ||
<Button | ||
onClick={onNew} | ||
variant="transparent" | ||
size="iconSm" | ||
className="opacity-0 group-hover:opacity-100 transition-opacity ml-auto p-0.5 text-sm text-[#f9edffcc] size-6 shrink-0" | ||
> | ||
<PlusIcon className="size-5" /> | ||
</Button> | ||
</Hint> | ||
)} | ||
</div> | ||
{on && children} | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { useQuery } from "convex/react"; | ||
import { api } from "../../../../convex/_generated/api"; | ||
import { Id } from "../../../../convex/_generated/dataModel"; | ||
import workSpaceId from "@/app/workspace/[workspaceId]/page"; | ||
|
||
interface UseGetChannelsProps { | ||
workspaceId: Id<"workspaces">; | ||
} | ||
|
||
export const useGetChannels = ({ workspaceId }: UseGetChannelsProps) => { | ||
const data = useQuery(api.channels.get, { workspaceId }); | ||
const isLoading = data === undefined; | ||
|
||
return { data, isLoading }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// interface UseGetMemberProps = {} |