/playlists is the new page of every public playlist, newest first (GET /api/playlists), and /playlists/<slug> a playlist category's, with a menu of the categories, linked from the user menu as "All playlists"; `playlists` is reserved as a dump category's slug, and one that had it is renamed. A profile's Playlists tab narrows to a playlist category with the same menu as its Dumps tab (?category=), and so do the Dumps and Playlists tabs of /search, each with its own kind (category and playlistCategory for GET /api/search), another tab dropping it. The category service takes the kind throughout, so a dump can't be filed under a playlist category nor the other way round, and categoryJoin is the one filter join the dump, follow and playlist services share. useCategories(kind) gives one kind's set from the one fetch, CategoryChips replaces the chips the dump card and page each drew, useCategoryFilter keeps a list to its category as the socket brings more, and useCategorySelection holds a form's picked categories. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
277 lines
7.9 KiB
TypeScript
277 lines
7.9 KiB
TypeScript
/**
|
||
* Renders the editor of the site's categories of one kind, dump or playlist,
|
||
* on `/manage` for a user with the `category:manage` permission.
|
||
*
|
||
* @module
|
||
*/
|
||
|
||
import { useState } from "react";
|
||
import { t } from "@lingui/core/macro";
|
||
import { Trans } from "@lingui/react/macro";
|
||
|
||
import { API_URL } from "../../config/api.ts";
|
||
import { VALIDATION } from "../../../shared/validation.ts";
|
||
import type {
|
||
Category,
|
||
CategoryKind,
|
||
CreateCategoryRequest,
|
||
UpdateCategoryRequest,
|
||
} from "../../../shared/category.ts";
|
||
import type { Wire } from "../../../shared/api.ts";
|
||
import { useAuth } from "../../hooks/auth/useAuth.ts";
|
||
import { useCategories } from "../../hooks/category/useCategories.ts";
|
||
import { ConfirmModal } from "../shared/ConfirmModal.tsx";
|
||
import { expectOk } from "../../utils/shared/api.ts";
|
||
import { FormError } from "../form/FormError.tsx";
|
||
import { FormProvider } from "react-hook-form";
|
||
import { SubmitButton } from "../form/SubmitButton.tsx";
|
||
import { useApiForm } from "../../hooks/form/useApiForm.ts";
|
||
|
||
interface CategoryFields {
|
||
name: string;
|
||
slug: string;
|
||
}
|
||
|
||
/**
|
||
* The value of `editing` while a new category is being created. Its leading
|
||
* space keeps it from matching a category id.
|
||
*/
|
||
const NEW = " |