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

issueSavedViews.ts

43 lines1.4 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({
19 ...normalized,
20 label: normalized.label?.toSorted(),
21 hideProjects: normalized.hideProjects?.map((pair) => JSON.stringify(pair)).toSorted(),
22 });
23 };
24 return key(issueListPreferences(view.preferences)) === key(preferences);
26​
27export const ISSUE_SAVED_VIEWS = {
28 storageKey: "t3.issues.savedViews",
29 schema: Schema.Array(
30 Schema.Struct({ ...SavedViewIdentity.fields, preferences: IssueListPreferencesSchema }),
31 ),
32 empty: [],
33 list: "issue",
34 placeholder: msg("Issues Assigned to Me"),
35 suggestedName: (preferences) =>
36 preferences.who === "assigned" ? msg("Issues Assigned to Me") : "",
37 normalize: issueListPreferences,
38 matches: issueViewMatches,
39} as const satisfies SavedViewsKind<
40 IssueListPreferences,
41 typeof IssueListPreferencesSchema.Type,
42 unknown
43>;