refactor tags store

This commit is contained in:
daniel31x13
2024-08-01 17:23:51 -04:00
parent e889509697
commit da8dc83b8f
8 changed files with 108 additions and 107 deletions
+3 -3
View File
@@ -1,8 +1,8 @@
import useTagStore from "@/store/tags";
import { useEffect, useState } from "react";
import CreatableSelect from "react-select/creatable";
import { styles } from "./styles";
import { Options } from "./types";
import { useTags } from "@/hooks/store/tags";
type Props = {
onChange: any;
@@ -13,12 +13,12 @@ type Props = {
};
export default function TagSelection({ onChange, defaultValue }: Props) {
const { tags } = useTagStore();
const { data: tags = [] } = useTags();
const [options, setOptions] = useState<Options[]>([]);
useEffect(() => {
const formatedCollections = tags.map((e) => {
const formatedCollections = tags.map((e: any) => {
return { value: e.id, label: e.name };
});
+4 -4
View File
@@ -1,4 +1,3 @@
import useTagStore from "@/store/tags";
import Link from "next/link";
import { useRouter } from "next/router";
import { useEffect, useState } from "react";
@@ -7,6 +6,7 @@ import SidebarHighlightLink from "@/components/SidebarHighlightLink";
import CollectionListing from "@/components/CollectionListing";
import { useTranslation } from "next-i18next";
import { useCollections } from "@/hooks/store/collections";
import { useTags } from "@/hooks/store/tags";
export default function Sidebar({ className }: { className?: string }) {
const { t } = useTranslation();
@@ -24,7 +24,7 @@ export default function Sidebar({ className }: { className?: string }) {
const { data: collections = [] } = useCollections();
const { tags } = useTagStore();
const { data: tags = [] } = useTags();
const [active, setActive] = useState("");
const router = useRouter();
@@ -130,8 +130,8 @@ export default function Sidebar({ className }: { className?: string }) {
<Disclosure.Panel className="flex flex-col gap-1">
{tags[0] ? (
tags
.sort((a, b) => a.name.localeCompare(b.name))
.map((e, i) => {
.sort((a: any, b: any) => a.name.localeCompare(b.name))
.map((e: any, i: any) => {
return (
<Link key={i} href={`/tags/${e.id}`}>
<div