Initial commit

This commit is contained in:
Doh
2024-12-30 13:20:12 -05:00
committed by dohsimpson
commit c4f0db329b
71 changed files with 11302 additions and 0 deletions

140
app/actions/data.ts Normal file
View File

@@ -0,0 +1,140 @@
'use server'
import fs from 'fs/promises'
import path from 'path'
import { HabitsData, CoinsData, CoinTransaction, TransactionType, WishlistItemType } from '@/lib/types'
type DataType = 'wishlist' | 'habits' | 'coins'
async function ensureDataDir() {
const dataDir = path.join(process.cwd(), 'data')
try {
await fs.access(dataDir)
} catch {
await fs.mkdir(dataDir, { recursive: true })
}
}
async function loadData<T>(type: DataType): Promise<T> {
try {
await ensureDataDir()
const filePath = path.join(process.cwd(), 'data', `${type}.json`)
try {
await fs.access(filePath)
} catch {
// File doesn't exist, create it with initial data
const initialData = type === 'wishlist'
? { items: [] }
: type === 'habits'
? { habits: [] }
: { balance: 0, transactions: [] }
await fs.writeFile(filePath, JSON.stringify(initialData, null, 2))
return initialData as T
}
// File exists, read and return its contents
const data = await fs.readFile(filePath, 'utf8')
const jsonData = JSON.parse(data)
return type === 'wishlist' ? jsonData.items : jsonData
} catch (error) {
console.error(`Error loading ${type} data:`, error)
if (type === 'wishlist') return [] as T
if (type === 'habits') return { habits: [] } as T
if (type === 'coins') return { balance: 0, transactions: [] } as T
return {} as T
}
}
async function saveData<T>(type: DataType, data: T): Promise<void> {
try {
await ensureDataDir()
const filePath = path.join(process.cwd(), 'data', `${type}.json`)
const saveData = type === 'wishlist' ? { items: data } : data
await fs.writeFile(filePath, JSON.stringify(saveData, null, 2))
} catch (error) {
console.error(`Error saving ${type} data:`, error)
}
}
// Wishlist specific functions
export async function loadWishlistItems(): Promise<WishlistItemType[]> {
return loadData<WishlistItemType[]>('wishlist')
}
export async function saveWishlistItems(items: WishlistItemType[]): Promise<void> {
return saveData('wishlist', items)
}
// Habits specific functions
export async function loadHabitsData(): Promise<HabitsData> {
return loadData<HabitsData>('habits')
}
export async function saveHabitsData(data: HabitsData): Promise<void> {
return saveData('habits', data)
}
// Coins specific functions
export async function loadCoinsData(): Promise<CoinsData> {
try {
return await loadData<CoinsData>('coins')
} catch {
return { balance: 0, transactions: [] }
}
}
export async function saveCoinsData(data: CoinsData): Promise<void> {
return saveData('coins', data)
}
export async function addCoins(
amount: number,
description: string,
type: TransactionType = 'MANUAL_ADJUSTMENT',
relatedItemId?: string
): Promise<CoinsData> {
const data = await loadCoinsData()
const newTransaction: CoinTransaction = {
id: crypto.randomUUID(),
amount,
type,
description,
timestamp: new Date().toISOString(),
...(relatedItemId && { relatedItemId })
}
const newData: CoinsData = {
balance: data.balance + amount,
transactions: [newTransaction, ...data.transactions]
}
await saveCoinsData(newData)
return newData
}
export async function removeCoins(
amount: number,
description: string,
type: TransactionType = 'MANUAL_ADJUSTMENT',
relatedItemId?: string
): Promise<CoinsData> {
const data = await loadCoinsData()
const newTransaction: CoinTransaction = {
id: crypto.randomUUID(),
amount: -amount,
type,
description,
timestamp: new Date().toISOString(),
...(relatedItemId && { relatedItemId })
}
const newData: CoinsData = {
balance: Math.max(0, data.balance - amount),
transactions: [newTransaction, ...data.transactions]
}
await saveCoinsData(newData)
return newData
}

11
app/calendar/page.tsx Normal file
View File

@@ -0,0 +1,11 @@
import Layout from '@/components/Layout'
import HabitCalendar from '@/components/HabitCalendar'
export default function CalendarPage() {
return (
<Layout>
<HabitCalendar />
</Layout>
)
}

10
app/coins/page.tsx Normal file
View File

@@ -0,0 +1,10 @@
import Layout from '@/components/Layout'
import CoinsManager from '@/components/CoinsManager'
export default function CoinsPage() {
return (
<Layout>
<CoinsManager />
</Layout>
)
}

BIN
app/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

73
app/globals.css Normal file
View File

@@ -0,0 +1,73 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
body {
font-family: Arial, Helvetica, sans-serif;
}
@layer base {
:root {
--background: 0 0% 100%;
--foreground: 0 0% 3.9%;
--card: 0 0% 100%;
--card-foreground: 0 0% 3.9%;
--popover: 0 0% 100%;
--popover-foreground: 0 0% 3.9%;
--primary: 0 0% 9%;
--primary-foreground: 0 0% 98%;
--secondary: 0 0% 96.1%;
--secondary-foreground: 0 0% 9%;
--muted: 0 0% 96.1%;
--muted-foreground: 0 0% 45.1%;
--accent: 0 0% 96.1%;
--accent-foreground: 0 0% 9%;
--destructive: 0 84.2% 60.2%;
--destructive-foreground: 0 0% 98%;
--border: 0 0% 89.8%;
--input: 0 0% 89.8%;
--ring: 0 0% 3.9%;
--chart-1: 12 76% 61%;
--chart-2: 173 58% 39%;
--chart-3: 197 37% 24%;
--chart-4: 43 74% 66%;
--chart-5: 27 87% 67%;
--radius: 0.5rem;
}
.dark {
--background: 0 0% 3.9%;
--foreground: 0 0% 98%;
--card: 0 0% 3.9%;
--card-foreground: 0 0% 98%;
--popover: 0 0% 3.9%;
--popover-foreground: 0 0% 98%;
--primary: 0 0% 98%;
--primary-foreground: 0 0% 9%;
--secondary: 0 0% 14.9%;
--secondary-foreground: 0 0% 98%;
--muted: 0 0% 14.9%;
--muted-foreground: 0 0% 63.9%;
--accent: 0 0% 14.9%;
--accent-foreground: 0 0% 98%;
--destructive: 0 62.8% 30.6%;
--destructive-foreground: 0 0% 98%;
--border: 0 0% 14.9%;
--input: 0 0% 14.9%;
--ring: 0 0% 83.1%;
--chart-1: 220 70% 50%;
--chart-2: 160 60% 45%;
--chart-3: 30 80% 55%;
--chart-4: 280 65% 60%;
--chart-5: 340 75% 55%;
}
}
@layer base {
* {
border-color: hsl(var(--border));
}
body {
background-color: hsl(var(--background));
color: hsl(var(--foreground));
}
}

11
app/habits/page.tsx Normal file
View File

@@ -0,0 +1,11 @@
import Layout from '@/components/Layout'
import HabitList from '@/components/HabitList'
export default function HabitsPage() {
return (
<Layout>
<HabitList />
</Layout>
)
}

38
app/layout.tsx Normal file
View File

@@ -0,0 +1,38 @@
import './globals.css'
import { Inter } from 'next/font/google'
import { DM_Sans } from 'next/font/google'
import { Toaster } from '@/components/ui/toaster'
// Inter (clean, modern, excellent readability)
const inter = Inter({
subsets: ['latin'],
weight: ['400', '500', '600', '700']
})
//
// Clean and contemporary
const dmSans = DM_Sans({
subsets: ['latin'],
weight: ['400', '500', '600', '700']
})
const activeFont = dmSans
export const metadata = {
title: 'HabitTrove',
description: 'Track your habits and get rewarded',
}
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html lang="en">
<body className={activeFont.className}>
{children}
<Toaster />
</body>
</html>
)
}

11
app/page.tsx Normal file
View File

@@ -0,0 +1,11 @@
import Layout from '@/components/Layout'
import Dashboard from '@/components/Dashboard'
export default function Home() {
return (
<Layout>
<Dashboard />
</Layout>
)
}

11
app/wishlist/page.tsx Normal file
View File

@@ -0,0 +1,11 @@
import Layout from '@/components/Layout'
import WishlistManager from '@/components/WishlistManager'
export default function WishlistPage() {
return (
<Layout>
<WishlistManager />
</Layout>
)
}