Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

issueSavedViews.ts

39 lines1.3 KB

1import * as Schema from "effect/Schema";
2import { msg } from "gt-react";
3import { SavedViewIdentity } from "@t3tools/client-runtime/saved-views";
4​
5import type { SavedView, SavedViewsKind } from "../SavedViewsMenu";
6import {
7 issueListPreferences,
8 IssueListPreferencesSchema,
9 type IssueListPreferences,
10} from "./issueListPreferences";
11​
12export function issueViewMatches(
13 view: SavedView<typeof IssueListPreferencesSchema.Type>,
14 preferences: IssueListPreferences,
15): boolean {
16 const key = (value: IssueListPreferences) => {
17 const normalized = issueListPreferences(value);
18 return JSON.stringify({ ...normalized, label: normalized.label?.toSorted() });
19 };
20 return key(issueListPreferences(view.preferences)) === key(preferences);
22​
23export const ISSUE_SAVED_VIEWS = {
24 storageKey: "t3.issues.savedViews",
25 schema: Schema.Array(
26 Schema.Struct({ ...SavedViewIdentity.fields, preferences: IssueListPreferencesSchema }),
27 ),
28 empty: [],
29 list: "issue",
30 placeholder: msg("Issues Assigned to Me"),
31 suggestedName: (preferences) =>
32 preferences.who === "assigned" ? msg("Issues Assigned to Me") : "",
33 normalize: issueListPreferences,
34 matches: issueViewMatches,
35} as const satisfies SavedViewsKind<
36 IssueListPreferences,
37 typeof IssueListPreferencesSchema.Type,
38 unknown
39>;