2023-11-21 10:16:41 +00:00
|
|
|
import React, { FC, useEffect, useState } from "react";
|
2023-04-20 08:11:24 +00:00
|
|
|
import { Command } from "cmdk";
|
2024-04-29 06:42:33 +00:00
|
|
|
import { observer } from "mobx-react";
|
2023-04-20 08:11:24 +00:00
|
|
|
import { useTheme } from "next-themes";
|
2024-04-29 06:42:33 +00:00
|
|
|
// icons
|
2023-10-16 14:57:22 +00:00
|
|
|
import { Settings } from "lucide-react";
|
2023-11-02 11:41:33 +00:00
|
|
|
// constants
|
2024-04-29 06:42:33 +00:00
|
|
|
import { THEME_OPTIONS } from "@/constants/themes";
|
2023-04-20 08:11:24 +00:00
|
|
|
|
|
|
|
type Props = {
|
2023-11-21 10:16:41 +00:00
|
|
|
closePalette: () => void;
|
2023-04-20 08:11:24 +00:00
|
|
|
};
|
|
|
|
|
2023-11-21 10:16:41 +00:00
|
|
|
export const CommandPaletteThemeActions: FC<Props> = observer((props) => {
|
|
|
|
const { closePalette } = props;
|
2023-11-01 11:41:29 +00:00
|
|
|
// states
|
2023-04-20 08:11:24 +00:00
|
|
|
const [mounted, setMounted] = useState(false);
|
2023-11-01 11:41:29 +00:00
|
|
|
// hooks
|
2023-04-20 08:11:24 +00:00
|
|
|
const { setTheme } = useTheme();
|
2023-08-03 09:31:31 +00:00
|
|
|
|
2023-11-21 10:16:41 +00:00
|
|
|
const updateUserTheme = async (newTheme: string) => {
|
2023-08-03 09:31:31 +00:00
|
|
|
setTheme(newTheme);
|
2023-11-21 10:16:41 +00:00
|
|
|
|
2024-04-29 06:42:33 +00:00
|
|
|
// return updateUserProfile({ theme: newTheme }).catch(() => {
|
|
|
|
// setToast({
|
|
|
|
// type: TOAST_TYPE.ERROR,
|
|
|
|
// title: "Failed to save user theme settings!",
|
|
|
|
// });
|
|
|
|
// });
|
2023-08-03 09:31:31 +00:00
|
|
|
};
|
|
|
|
|
2023-04-20 08:11:24 +00:00
|
|
|
// useEffect only runs on the client, so now we can safely show the UI
|
|
|
|
useEffect(() => {
|
|
|
|
setMounted(true);
|
|
|
|
}, []);
|
|
|
|
|
2023-08-03 09:31:31 +00:00
|
|
|
if (!mounted) return null;
|
2023-04-20 08:11:24 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2023-10-17 07:16:38 +00:00
|
|
|
{THEME_OPTIONS.filter((t) => t.value !== "custom").map((theme) => (
|
2023-04-20 08:11:24 +00:00
|
|
|
<Command.Item
|
|
|
|
key={theme.value}
|
|
|
|
onSelect={() => {
|
2023-08-03 09:31:31 +00:00
|
|
|
updateUserTheme(theme.value);
|
2023-11-21 10:16:41 +00:00
|
|
|
closePalette();
|
2023-04-20 08:11:24 +00:00
|
|
|
}}
|
|
|
|
className="focus:outline-none"
|
|
|
|
>
|
2023-07-10 07:17:00 +00:00
|
|
|
<div className="flex items-center gap-2 text-custom-text-200">
|
2023-10-16 14:57:22 +00:00
|
|
|
<Settings className="h-4 w-4 text-custom-text-200" />
|
2023-04-20 08:11:24 +00:00
|
|
|
{theme.label}
|
|
|
|
</div>
|
|
|
|
</Command.Item>
|
|
|
|
))}
|
|
|
|
</>
|
|
|
|
);
|
2023-08-16 12:56:36 +00:00
|
|
|
});
|