Add new styles for home and landing pages
- Created home.css with comprehensive styles for the home page layout, including typography, buttons, and responsive design adjustments. - Created landing.css to style the landing page, focusing on typography, layout, and responsive behavior for various screen sizes.
This commit is contained in:
48
src/lib/dashboard.ts
Normal file
48
src/lib/dashboard.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import type { HabitService } from "../habits/service";
|
||||
import type { Schedule } from "../habits/contracts";
|
||||
|
||||
export type TodayHabit = ReturnType<HabitService["day"]>;
|
||||
export type TodayResponse = {
|
||||
date: string;
|
||||
timezone: string;
|
||||
habits: TodayHabit[];
|
||||
due: number;
|
||||
completed: number;
|
||||
};
|
||||
|
||||
export async function habitRequest<T>(
|
||||
path: string,
|
||||
options?: RequestInit,
|
||||
): Promise<T> {
|
||||
const response = await fetch(`/api${path}`, options);
|
||||
if (!response.ok) {
|
||||
if (response.status === 401)
|
||||
throw new Error("Your session has expired. Sign in again to continue.");
|
||||
const body = await response.json().catch(() => null);
|
||||
throw new Error(
|
||||
body?.error || "Could not reach your workspace. Please try again.",
|
||||
);
|
||||
}
|
||||
return response.status === 204
|
||||
? (undefined as T)
|
||||
: (response.json() as Promise<T>);
|
||||
}
|
||||
|
||||
export function scheduleLabel(schedule?: Schedule) {
|
||||
if (!schedule || schedule.type === "daily") return "Every day";
|
||||
if (schedule.type === "weekdays")
|
||||
return schedule.days
|
||||
.map((day) => ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"][day])
|
||||
.join(", ");
|
||||
if (schedule.type === "interval") return `Every ${schedule.every} days`;
|
||||
return `Every ${schedule.every === 1 ? "week" : `${schedule.every} weeks`} · ${["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"][schedule.weekday]}`;
|
||||
}
|
||||
|
||||
export function formatTrackingDate(date: string) {
|
||||
return new Date(`${date}T12:00:00Z`).toLocaleDateString("en", {
|
||||
weekday: "long",
|
||||
month: "long",
|
||||
day: "numeric",
|
||||
timeZone: "UTC",
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user