-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Settings page 5/5 (there is still something to do)
- Loading branch information
Showing
9 changed files
with
287 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { useState, useEffect } from "react"; | ||
import { ChevronsUpDown } from "lucide-react"; | ||
import { Button } from "@/shadcn/ui/button"; | ||
import { | ||
Command, | ||
CommandEmpty, | ||
CommandGroup, | ||
CommandInput, | ||
CommandItem, | ||
CommandList, | ||
} from "@/shadcn/ui/command"; | ||
import { Popover, PopoverTrigger, PopoverContent } from "@/shadcn/ui/popover"; | ||
import { useTranslation } from "react-i18next"; | ||
import { useAtom, useAtomValue } from "jotai/react"; | ||
import { useSearchAutoCompleteMutation } from "@/services/search.service"; | ||
import atomWithDebounce from "@/lib/atomWithDebounce"; | ||
|
||
const { debouncedValueAtom, currentValueAtom } = atomWithDebounce("", 300); | ||
|
||
interface TopicPickerProps { | ||
onSelect: (topicId: string) => void; | ||
} | ||
|
||
export function TopicPicker({ onSelect }: TopicPickerProps) { | ||
const [deboundcedValue, setDebouncedValue] = useAtom(debouncedValueAtom); | ||
const currentValue = useAtomValue(currentValueAtom); | ||
const { t } = useTranslation(); | ||
const [open, setOpen] = useState(false); | ||
|
||
const { data, isPending, mutate } = useSearchAutoCompleteMutation(); | ||
|
||
useEffect(() => { | ||
mutate({ | ||
q: deboundcedValue, | ||
t: "topic", | ||
n: 10, | ||
}); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [deboundcedValue]); | ||
|
||
return ( | ||
<Popover open={open} onOpenChange={setOpen}> | ||
<PopoverTrigger asChild> | ||
<Button | ||
variant="outline" | ||
role="combobox" | ||
size="lg" | ||
aria-expanded={open} | ||
className="w-full justify-between px-4" | ||
> | ||
{t("component.topicPicker.pickLabel")} | ||
<ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50" /> | ||
</Button> | ||
</PopoverTrigger> | ||
<PopoverContent className="max-w-[80vw] p-0"> | ||
<Command> | ||
<CommandInput | ||
value={currentValue} | ||
onValueChange={setDebouncedValue} | ||
placeholder={t("component.topicPicker.searchLabel")} | ||
/> | ||
<CommandList> | ||
<CommandEmpty>{t("component.topicPicker.notFound")}</CommandEmpty> | ||
<CommandGroup> | ||
{data?.topic?.map(({ id }) => ( | ||
<CommandItem | ||
key={id} | ||
onSelect={(topicId) => { | ||
onSelect(topicId); | ||
setOpen(false); | ||
}} | ||
> | ||
{id} | ||
</CommandItem> | ||
))} | ||
{isPending && ( | ||
<CommandItem className="flex justify-center py-2" disabled> | ||
<div className="i-lucide:loader-2 animate-spin" /> | ||
</CommandItem> | ||
)} | ||
</CommandGroup> | ||
</CommandList> | ||
</Command> | ||
</PopoverContent> | ||
</Popover> | ||
); | ||
} |
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,8 @@ | ||
import { blockedChannelsAtom } from "@/store/settings"; | ||
import { useAtom } from "jotai"; | ||
|
||
export default function SettingsBlocked() { | ||
const [blockedChannels, setBlockedChannels] = useAtom(blockedChannelsAtom); | ||
|
||
return <div className="flex flex-col gap-2"></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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
import { SettingsItem } from "@/components/settings/SettingsItem"; | ||
import { TopicPicker } from "@/components/topic/TopicPicker"; | ||
import { cn } from "@/lib/utils"; | ||
import { Badge } from "@/shadcn/ui/badge"; | ||
import { Label } from "@/shadcn/ui/label"; | ||
import { RadioGroup, RadioGroupItem } from "@/shadcn/ui/radio-group"; | ||
import { Switch } from "@/shadcn/ui/switch"; | ||
import { | ||
defaultOpenAtom, | ||
hideCollabStreamsAtom, | ||
hidePlaceholderAtom, | ||
hideThumbnailAtom, | ||
homeViewModeAtom, | ||
ignoredTopicsAtom, | ||
} from "@/store/settings"; | ||
import { useAtom } from "jotai"; | ||
import { useTranslation } from "react-i18next"; | ||
|
||
export default function SettingsHomepage() { | ||
const { t } = useTranslation(); | ||
const [defaultOpen, setDefaultOpen] = useAtom(defaultOpenAtom); | ||
const [homeViewMode, setHomeViewMode] = useAtom(homeViewModeAtom); | ||
const [ignoredTopics, setIgnoredTopics] = useAtom(ignoredTopicsAtom); | ||
const [hideThumbnail, setHideThumbnail] = useAtom(hideThumbnailAtom); | ||
const [hideCollab, setHideCollab] = useAtom(hideCollabStreamsAtom); | ||
const [hidePlaceholder, setHidePlaceholder] = useAtom(hidePlaceholderAtom); | ||
|
||
const defaultPages = [ | ||
{ | ||
value: "Home", | ||
label: t("views.settings.defaultHomepage.lastVisitedOrgHome"), | ||
}, | ||
{ | ||
value: "Favorites", | ||
label: t("views.settings.defaultHomepage.favoritesWhenLoggedIn"), | ||
}, | ||
]; | ||
|
||
const gridSizes = [ | ||
{ | ||
value: "grid", | ||
label: t("views.settings.gridSize.0"), | ||
}, | ||
{ | ||
value: "list", | ||
label: t("views.settings.gridSize.1"), | ||
}, | ||
{ | ||
value: "denseList", | ||
label: t("views.settings.gridSize.2"), | ||
}, | ||
]; | ||
|
||
const hideFeatures = [ | ||
{ | ||
label: t("views.settings.hideVideoThumbnailsLabel"), | ||
value: hideThumbnail, | ||
onChange: () => setHideThumbnail(!hideThumbnail), | ||
}, | ||
{ | ||
label: t("views.settings.hideCollabStreamsLabel"), | ||
value: hideCollab, | ||
onChange: () => setHideCollab(!hideCollab), | ||
}, | ||
{ | ||
label: t("views.settings.hidePlaceholderStreams"), | ||
value: hidePlaceholder, | ||
onChange: () => setHidePlaceholder(!hidePlaceholder), | ||
}, | ||
]; | ||
|
||
return ( | ||
<div className="flex flex-col p-2 md:p-4"> | ||
<SettingsItem label={t("views.settings.defaultPage")}> | ||
<RadioGroup | ||
className="flex w-full flex-col gap-0 rounded-lg border border-base" | ||
value={defaultOpen} | ||
onValueChange={(val: "Home" | "Favorites") => setDefaultOpen(val)} | ||
> | ||
{defaultPages.map(({ label, value }, index) => ( | ||
<Label | ||
className={cn( | ||
"flex w-full min-w-[18rem] items-center justify-between gap-4 p-4 hover:cursor-pointer", | ||
{ "bg-base-4": index % 2 }, | ||
)} | ||
> | ||
{label} | ||
<RadioGroupItem value={value} /> | ||
</Label> | ||
))} | ||
</RadioGroup> | ||
</SettingsItem> | ||
<SettingsItem label={t("views.settings.gridSizeLabel")}> | ||
<RadioGroup | ||
className="ml-auto flex gap-0 rounded-lg" | ||
onValueChange={(val: "grid" | "list" | "denseList") => | ||
setHomeViewMode(val) | ||
} | ||
> | ||
{gridSizes.map(({ label, value }) => ( | ||
<Label | ||
className={cn( | ||
"bg-base-4 border-base border-r-2 px-4 py-2 text-lg first:rounded-l-lg last:rounded-r-lg last:border-r-0 hover:cursor-pointer", | ||
{ "bg-secondary-9": value === homeViewMode }, | ||
)} | ||
> | ||
{label} | ||
<RadioGroupItem value={value} className="sr-only" /> | ||
</Label> | ||
))} | ||
</RadioGroup> | ||
</SettingsItem> | ||
<SettingsItem label={t("views.settings.ignoredTopicsLabel")}> | ||
<div className="flex w-full flex-col gap-2"> | ||
<TopicPicker | ||
onSelect={(topic) => | ||
setIgnoredTopics((currentTopics) => [...currentTopics, topic]) | ||
} | ||
/> | ||
<div className="flex flex-wrap gap-2"> | ||
{ignoredTopics.map((topic) => ( | ||
<Badge | ||
onClick={() => | ||
setIgnoredTopics((currentTopics) => | ||
currentTopics.filter((t) => t !== topic), | ||
) | ||
} | ||
> | ||
{topic} | ||
<div className="i-heroicons:x-mark ml-1" /> | ||
</Badge> | ||
))} | ||
</div> | ||
</div> | ||
</SettingsItem> | ||
<SettingsItem label={t("views.settings.hideFeaturesLabel")}> | ||
<div className="flex w-full flex-col rounded-lg border border-base"> | ||
{hideFeatures.map(({ label, value, onChange }, index) => ( | ||
<Label | ||
className={cn( | ||
"flex min-w-[18rem] w-full justify-between items-center gap-4 px-4 py-4 hover:cursor-pointer", | ||
{ | ||
"bg-base-4": index % 2, | ||
}, | ||
)} | ||
htmlFor={`hidefeature-${label}`} | ||
> | ||
{label} | ||
<Switch | ||
id={`hidefeature-${label}`} | ||
checked={value} | ||
onCheckedChange={onChange} | ||
/> | ||
</Label> | ||
))} | ||
</div> | ||
</SettingsItem> | ||
</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
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