Extract shared types to src/types/dashboard.ts
Consolidate duplicated type definitions (User, Settings, Widget, CalendarEvent, CalendarSource, NoteBoardItem, etc.) into a single shared types file. Removes ~100 lines of duplicated type code across page.tsx, settings/page.tsx, NoteWidget.tsx, and CalendarWidget.tsx. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+1
-89
@@ -6,6 +6,7 @@ import { FormEvent, useEffect, useMemo, useRef, useState } from "react";
|
|||||||
import type { DashboardGridProps } from "@/components/DashboardGrid";
|
import type { DashboardGridProps } from "@/components/DashboardGrid";
|
||||||
import type { DashboardGridWidget, DashboardLayoutItem } from "@/lib/dashboard-layout";
|
import type { DashboardGridWidget, DashboardLayoutItem } from "@/lib/dashboard-layout";
|
||||||
import { sortLayoutForPosition } from "@/lib/dashboard-layout";
|
import { sortLayoutForPosition } from "@/lib/dashboard-layout";
|
||||||
|
import type { User, Settings, DashboardTab, WidgetType, Widget, SearchProvider, CalendarEvent, CalendarSource, CalendarWidgetCalendarConfig, NoteBoardItem } from "@/types/dashboard";
|
||||||
import CalculatorWidget from "@/components/CalculatorWidget";
|
import CalculatorWidget from "@/components/CalculatorWidget";
|
||||||
import CalendarWidget from "@/components/CalendarWidget";
|
import CalendarWidget from "@/components/CalendarWidget";
|
||||||
import ClockWidget from "@/components/ClockWidget";
|
import ClockWidget from "@/components/ClockWidget";
|
||||||
@@ -25,95 +26,6 @@ const DashboardGrid = dynamic<DashboardGridProps>(() => import("@/components/Das
|
|||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
type User = {
|
|
||||||
id: string;
|
|
||||||
email: string;
|
|
||||||
displayName: string | null;
|
|
||||||
role: "ADMIN" | "USER";
|
|
||||||
};
|
|
||||||
|
|
||||||
type Settings = {
|
|
||||||
id: string;
|
|
||||||
userId: string;
|
|
||||||
darkMode: boolean;
|
|
||||||
calendarIcsUrl: string | null;
|
|
||||||
calendarMaxEvents: number;
|
|
||||||
calendarLookaheadDays: number;
|
|
||||||
dashboardTitle: string;
|
|
||||||
dashboardSubtitle: string | null;
|
|
||||||
logoUrl: string | null;
|
|
||||||
backgroundImageUrl: string | null;
|
|
||||||
backgroundImageOpacity: number;
|
|
||||||
primaryColor: string;
|
|
||||||
secondaryColor: string;
|
|
||||||
customCss: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
type DashboardTab = {
|
|
||||||
id: string;
|
|
||||||
userId: string;
|
|
||||||
title: string;
|
|
||||||
position: number;
|
|
||||||
};
|
|
||||||
|
|
||||||
type WidgetType = "favorites" | "note" | "search" | "calendar" | "calculator" | "clock" | "domain-check";
|
|
||||||
|
|
||||||
type Widget = DashboardGridWidget & {
|
|
||||||
userId: string;
|
|
||||||
viewMode?: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
type SearchProvider = {
|
|
||||||
id: string;
|
|
||||||
label: string;
|
|
||||||
urlTemplate: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
type CalendarEvent = {
|
|
||||||
id: string;
|
|
||||||
title: string;
|
|
||||||
start: string;
|
|
||||||
end: string | null;
|
|
||||||
location: string | null;
|
|
||||||
};
|
|
||||||
|
|
||||||
type CalendarSourceType = "ICS" | "EXCHANGE_EWS";
|
|
||||||
|
|
||||||
type CalendarSource = {
|
|
||||||
id: string;
|
|
||||||
userId: string;
|
|
||||||
type: CalendarSourceType;
|
|
||||||
name: string;
|
|
||||||
color: string;
|
|
||||||
nextEventsCount: number;
|
|
||||||
icsUrl: string | null;
|
|
||||||
exchangeEwsUrl: string | null;
|
|
||||||
exchangeMailbox: string | null;
|
|
||||||
exchangeUsername: string | null;
|
|
||||||
exchangeDomain: string | null;
|
|
||||||
passwordConfigured: boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
type CalendarWidgetCalendarConfig = {
|
|
||||||
sources: CalendarSource[];
|
|
||||||
selectedSourceIds: string[];
|
|
||||||
nextEventsCount: number;
|
|
||||||
};
|
|
||||||
|
|
||||||
type NoteBoardItem = {
|
|
||||||
id: string;
|
|
||||||
userId: string;
|
|
||||||
type: "note" | string;
|
|
||||||
title: string;
|
|
||||||
content: string;
|
|
||||||
x: number;
|
|
||||||
y: number;
|
|
||||||
w: number;
|
|
||||||
h: number;
|
|
||||||
createdAt: string;
|
|
||||||
updatedAt: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
const searchProviders: SearchProvider[] = [
|
const searchProviders: SearchProvider[] = [
|
||||||
{
|
{
|
||||||
id: "google",
|
id: "google",
|
||||||
|
|||||||
@@ -1,41 +1,7 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { FormEvent, useEffect, useState } from "react";
|
import { FormEvent, useEffect, useState } from "react";
|
||||||
|
import type { Settings, CalendarSource, CalendarSourceType } from "@/types/dashboard";
|
||||||
type Settings = {
|
|
||||||
id: string;
|
|
||||||
userId: string;
|
|
||||||
darkMode: boolean;
|
|
||||||
calendarIcsUrl: string | null;
|
|
||||||
calendarMaxEvents: number;
|
|
||||||
calendarLookaheadDays: number;
|
|
||||||
dashboardTitle: string;
|
|
||||||
dashboardSubtitle: string | null;
|
|
||||||
logoUrl: string | null;
|
|
||||||
faviconUrl: string | null;
|
|
||||||
backgroundImageUrl: string | null;
|
|
||||||
backgroundImageOpacity: number;
|
|
||||||
primaryColor: string;
|
|
||||||
secondaryColor: string;
|
|
||||||
customCss: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
type CalendarSourceType = "ICS" | "EXCHANGE_EWS";
|
|
||||||
|
|
||||||
type CalendarSource = {
|
|
||||||
id: string;
|
|
||||||
userId: string;
|
|
||||||
type: CalendarSourceType;
|
|
||||||
name: string;
|
|
||||||
color: string;
|
|
||||||
nextEventsCount: number;
|
|
||||||
icsUrl: string | null;
|
|
||||||
exchangeEwsUrl: string | null;
|
|
||||||
exchangeMailbox: string | null;
|
|
||||||
exchangeUsername: string | null;
|
|
||||||
exchangeDomain: string | null;
|
|
||||||
passwordConfigured: boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
type CalendarSourceDraft = {
|
type CalendarSourceDraft = {
|
||||||
sourceId: string | null;
|
sourceId: string | null;
|
||||||
|
|||||||
@@ -1,22 +1,7 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useMemo, useState } from "react";
|
import { useMemo, useState } from "react";
|
||||||
|
import type { CalendarEvent, CalendarSource } from "@/types/dashboard";
|
||||||
type CalendarEvent = {
|
|
||||||
id: string;
|
|
||||||
title: string;
|
|
||||||
start: string;
|
|
||||||
end: string | null;
|
|
||||||
location: string | null;
|
|
||||||
};
|
|
||||||
|
|
||||||
type CalendarSource = {
|
|
||||||
id: string;
|
|
||||||
name: string;
|
|
||||||
color: string;
|
|
||||||
type: string;
|
|
||||||
passwordConfigured: boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
type CalendarWidgetProps = {
|
type CalendarWidgetProps = {
|
||||||
widgetId: string;
|
widgetId: string;
|
||||||
|
|||||||
@@ -2,20 +2,7 @@
|
|||||||
|
|
||||||
import type { ReactNode } from "react";
|
import type { ReactNode } from "react";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
|
import type { NoteBoardItem } from "@/types/dashboard";
|
||||||
type NoteBoardItem = {
|
|
||||||
id: string;
|
|
||||||
userId: string;
|
|
||||||
type: "note" | string;
|
|
||||||
title: string;
|
|
||||||
content: string;
|
|
||||||
x: number;
|
|
||||||
y: number;
|
|
||||||
w: number;
|
|
||||||
h: number;
|
|
||||||
createdAt: string;
|
|
||||||
updatedAt: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
type NoteWidgetProps = {
|
type NoteWidgetProps = {
|
||||||
note: NoteBoardItem | null;
|
note: NoteBoardItem | null;
|
||||||
|
|||||||
@@ -0,0 +1,91 @@
|
|||||||
|
import type { DashboardGridWidget } from "@/lib/dashboard-layout";
|
||||||
|
|
||||||
|
export type User = {
|
||||||
|
id: string;
|
||||||
|
email: string;
|
||||||
|
displayName: string | null;
|
||||||
|
role: "ADMIN" | "USER";
|
||||||
|
};
|
||||||
|
|
||||||
|
export type Settings = {
|
||||||
|
id: string;
|
||||||
|
userId: string;
|
||||||
|
darkMode: boolean;
|
||||||
|
calendarIcsUrl: string | null;
|
||||||
|
calendarMaxEvents: number;
|
||||||
|
calendarLookaheadDays: number;
|
||||||
|
dashboardTitle: string;
|
||||||
|
dashboardSubtitle: string | null;
|
||||||
|
logoUrl: string | null;
|
||||||
|
faviconUrl: string | null;
|
||||||
|
backgroundImageUrl: string | null;
|
||||||
|
backgroundImageOpacity: number;
|
||||||
|
primaryColor: string;
|
||||||
|
secondaryColor: string;
|
||||||
|
customCss: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type DashboardTab = {
|
||||||
|
id: string;
|
||||||
|
userId: string;
|
||||||
|
title: string;
|
||||||
|
position: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type WidgetType = "favorites" | "note" | "search" | "calendar" | "calculator" | "clock" | "domain-check";
|
||||||
|
|
||||||
|
export type Widget = DashboardGridWidget & {
|
||||||
|
userId: string;
|
||||||
|
viewMode?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type SearchProvider = {
|
||||||
|
id: string;
|
||||||
|
label: string;
|
||||||
|
urlTemplate: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type CalendarEvent = {
|
||||||
|
id: string;
|
||||||
|
title: string;
|
||||||
|
start: string;
|
||||||
|
end: string | null;
|
||||||
|
location: string | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type CalendarSourceType = "ICS" | "EXCHANGE_EWS";
|
||||||
|
|
||||||
|
export type CalendarSource = {
|
||||||
|
id: string;
|
||||||
|
userId: string;
|
||||||
|
type: CalendarSourceType;
|
||||||
|
name: string;
|
||||||
|
color: string;
|
||||||
|
nextEventsCount: number;
|
||||||
|
icsUrl: string | null;
|
||||||
|
exchangeEwsUrl: string | null;
|
||||||
|
exchangeMailbox: string | null;
|
||||||
|
exchangeUsername: string | null;
|
||||||
|
exchangeDomain: string | null;
|
||||||
|
passwordConfigured: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type CalendarWidgetCalendarConfig = {
|
||||||
|
sources: CalendarSource[];
|
||||||
|
selectedSourceIds: string[];
|
||||||
|
nextEventsCount: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type NoteBoardItem = {
|
||||||
|
id: string;
|
||||||
|
userId: string;
|
||||||
|
type: "note" | string;
|
||||||
|
title: string;
|
||||||
|
content: string;
|
||||||
|
x: number;
|
||||||
|
y: number;
|
||||||
|
w: number;
|
||||||
|
h: number;
|
||||||
|
createdAt: string;
|
||||||
|
updatedAt: string;
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user