Skip to content

Commit

Permalink
fold grouping into standard sort
Browse files Browse the repository at this point in the history
  • Loading branch information
sphinxrave committed Jul 6, 2024
1 parent bb2332b commit 31e4b08
Showing 1 changed file with 2 additions and 40 deletions.
42 changes: 2 additions & 40 deletions packages/react/src/routes/orgChannels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { cn } from "@/lib/utils";
// Types
type DisplayStyle = "grid" | "list";
type SortOption = "suborg" | "subscriber_count" | "view_count";
type GroupOption = "none" | "group";

// Atoms and constants
const orgChannelDisplayStyleAtom = atomWithStorage<DisplayStyle>(
Expand All @@ -33,10 +32,6 @@ const orgChannelSortByAtom = atomWithStorage<SortOption>(
"orgChannelSortBy",
"suborg",
);
const orgChannelGroupByAtom = atomWithStorage<GroupOption>(
"orgChannelGroupBy",
"none",
);

const sortOptions: { value: SortOption; label: string; icon: string }[] = [
{ value: "suborg", label: "Standard Sort", icon: "i-lucide:arrow-down-a-z" },
Expand All @@ -52,15 +47,6 @@ const sortOptions: { value: SortOption; label: string; icon: string }[] = [
},
];

const groupOptions: {
value: GroupOption;
label: string;
icon: string;
}[] = [
{ value: "none", label: "No Grouping", icon: "i-lucide:user" },
{ value: "group", label: "Group", icon: "i-lucide:users" },
];

// Channel component
const ChannelComponent: React.FC<{
channel: Channel;
Expand Down Expand Up @@ -115,7 +101,6 @@ export default function ChannelsOrg() {

const [displayStyle, setDisplayStyle] = useAtom(orgChannelDisplayStyleAtom);
const [sortBy, setSortBy] = useAtom(orgChannelSortByAtom);
const [groupBy, setGroupBy] = useAtom(orgChannelGroupByAtom);

const {
data: channels,
Expand All @@ -132,8 +117,7 @@ export default function ChannelsOrg() {
const sortedAndGroupedChannels = useMemo(() => {
const processedChannels = channels?.pages.flat() ?? [];

// Group channels
if (groupBy === "group" && sortBy === "suborg") {
if (sortBy === "suborg") {
const groupedChannels: Record<string, Channel[]> = {};
processedChannels.forEach((channel) => {
const group = channel.group || "Other";
Expand All @@ -154,7 +138,7 @@ export default function ChannelsOrg() {
}

return { "": processedChannels };
}, [channels, sortBy, groupBy]);
}, [channels, sortBy]);

return (
<>
Expand Down Expand Up @@ -189,9 +173,6 @@ export default function ChannelsOrg() {
value={sortBy}
onValueChange={(value: SortOption) => {
setSortBy(value);
if (value !== "suborg") {
setGroupBy("none");
}
}}
>
<SelectTrigger className="w-full sm:w-[200px]">
Expand All @@ -208,25 +189,6 @@ export default function ChannelsOrg() {
))}
</SelectContent>
</Select>
<Select
value={groupBy}
onValueChange={(value: GroupOption) => setGroupBy(value)}
disabled={sortBy !== "suborg"}
>
<SelectTrigger className="w-full sm:w-[200px]">
<SelectValue placeholder="Group by" />
</SelectTrigger>
<SelectContent>
{groupOptions.map((option) => (
<SelectItem key={option.value} value={option.value}>
<div className="flex items-center gap-2">
<span className={cn(option.icon, "text-base")} />
{option.label}
</div>
</SelectItem>
))}
</SelectContent>
</Select>
</div>

<div>
Expand Down

0 comments on commit 31e4b08

Please sign in to comment.