Skip to content

Commit

Permalink
org picker fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sphinxrave committed Oct 16, 2023
1 parent 771daee commit efeaa20
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 33 deletions.
57 changes: 32 additions & 25 deletions packages/react/src/components/org/OrgPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@ import {
CommandGroup,
CommandInput,
CommandItem,
CommandList,
} from "@/shadcn/ui/command";
import { Popover, PopoverTrigger, PopoverContent } from "@/shadcn/ui/popover";
import { useTranslation } from "react-i18next";
import { currentOrgAtom } from "@/store/org";
import { useAtom } from "jotai/react";

export function OrgSelectorCombobox() {
const { t } = useTranslation();
const [open, setOpen] = React.useState(false);
const [value, setValue] = React.useState("");
const [currentOrg, setCurrentOrg] = useAtom(currentOrgAtom);
// const [currentOrg, setOrg] = useAtom(orgAtom)

// Use the useOrgs API service to fetch organizations
Expand All @@ -39,38 +43,41 @@ export function OrgSelectorCombobox() {
<Button
variant="outline"
role="combobox"
size="lg"
aria-expanded={open}
className="w-[200px] justify-between"
className="px-4 justify-between w-full"
>
{value
? orgs.find((org) => org.name === value)?.name
: t("Select organization...")}
{orgs.find((org) => org.name === currentOrg.name)?.name
|| t("Select organization...")}
<ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />
</Button>
</PopoverTrigger>
<PopoverContent className="w-[200px] p-0">
<PopoverContent className="max-w-[80vw] p-0">
<Command>
<CommandInput placeholder={t("Search organization...")} />
<CommandEmpty>{t("No organization found.")}</CommandEmpty>
<CommandGroup>
{orgs.map((org) => (
<CommandItem
key={org.name}
onSelect={(currentValue) => {
setValue(currentValue === value ? "" : currentValue);
setOpen(false);
}}
>
<Check
className={cn(
"mr-2 h-4 w-4",
value === org.name ? "opacity-100" : "opacity-0",
)}
/>
{org.name}
</CommandItem>
))}
</CommandGroup>
<CommandList>
<CommandEmpty>{t("No organization found.")}</CommandEmpty>
<CommandGroup>
{orgs.map((org) => (
<CommandItem
key={org.name}
onSelect={(currentValue) => {
setValue(currentValue === value ? "" : currentValue);
setCurrentOrg(org);
setOpen(false);
}}
>
<Check
className={cn(
"mr-2 h-4 w-4",
value === org.name ? "opacity-100" : "opacity-0",
)}
/>
{org.name}
</CommandItem>
))}
</CommandGroup>
</CommandList>
</Command>
</PopoverContent>
</Popover>
Expand Down
5 changes: 3 additions & 2 deletions packages/react/src/components/sidebar/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ export function Sidebar({ className, id, onClose }: SidebarProps) {
/>
</div>
<div className="px-3 py-2">
<OrgSelectorCombobox />
<h2 className="mb-2 px-4 font-semibold tracking-tight">Hololive</h2>
<div class="mb-2">
<OrgSelectorCombobox /></div>
{/* <h2 className="mb-2 px-4 font-semibold tracking-tight">Hololive</h2> */}
<div className="space-y-1">
<SidebarItem
onClose={onClose}
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/routes/router.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Kitchensink from "@/Kitchensink";
import { Navigate, createBrowserRouter } from "react-router-dom";
import { Home } from "@/routes/home";
import { ChannelsOrg } from "./channelsOrg";
Expand All @@ -17,6 +16,7 @@ const Login = React.lazy(() => import("./login"));
const Settings = React.lazy(() => import("./settings"));
const About = React.lazy(() => import("./about"));
const Channel = React.lazy(() => import("./channel"));
const Kitchensink = React.lazy(() => import("@/Kitchensink"));

const store = getDefaultStore();

Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/shadcn/ui/command.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const Command = React.forwardRef<
))
Command.displayName = CommandPrimitive.displayName

interface CommandDialogProps extends DialogProps {}
interface CommandDialogProps extends DialogProps { }

const CommandDialog = ({ children, ...props }: CommandDialogProps) => {
return (
Expand All @@ -39,7 +39,7 @@ const CommandInput = React.forwardRef<
React.ElementRef<typeof CommandPrimitive.Input>,
React.ComponentPropsWithoutRef<typeof CommandPrimitive.Input>
>(({ className, ...props }, ref) => (
<div className="flex items-center border-b px-3" cmdk-input-wrapper="">
<div className="flex items-center border-b border-base px-3" cmdk-input-wrapper="">
<MagnifyingGlassIcon className="mr-2 h-4 w-4 shrink-0 opacity-50" />
<CommandPrimitive.Input
ref={ref}
Expand Down
6 changes: 3 additions & 3 deletions packages/react/src/store/org.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export const defaultOrgs = [
{ name: "Independents", short: "Indie" },
];

export const orgRankingAtom = atomWithStorage('orgRanking', defaultOrgs)
export const orgRankingAtom = atomWithStorage<Org[]>('orgRanking', defaultOrgs)

export const coreOrgAtom = atomWithStorage('org', { name: "Hololive", short: "Holo" });
export const currentOrgAtom = atomWithStorage<Org>('org', { name: "Hololive", short: "Holo" });

export const orgAtom = atom((get) => get(coreOrgAtom).name);
export const orgAtom = atom((get) => get(currentOrgAtom).name);

0 comments on commit efeaa20

Please sign in to comment.