diff --git a/src/App.tsx b/src/App.tsx index cd1d8b2..969b1af 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -4,6 +4,7 @@ import Navbar from './components/Navbar'; import TopBar from './components/TopBar'; import SplashScreen from './components/SplashScreen'; import {BrowserRouter, Route, Routes, useLocation} from 'react-router-dom'; +import {formatDateSimple} from './utils/DateUtils'; import Feed from "./pages/Feed.tsx"; import DreamPage from "./pages/DreamPage.tsx"; import ProfilePage from "./pages/ProfilePage.tsx"; @@ -89,7 +90,7 @@ function Archive() { Dream #{item} - {new Date().toLocaleDateString()} + {formatDateSimple(new Date())}

diff --git a/src/components/DreamCard.tsx b/src/components/DreamCard.tsx index e3310b1..7b2bb31 100644 --- a/src/components/DreamCard.tsx +++ b/src/components/DreamCard.tsx @@ -3,6 +3,8 @@ import Dream from '../types/Dream'; import type User from "../types/User.ts"; import {NavLink} from "react-router-dom"; import {useEffect, useState} from "react"; +import {getAccentStyle, getTextStyle} from '../styles/StyleUtils'; +import {formatDateWithTime} from '../utils/DateUtils'; interface DreamCardProps { dream: Dream; @@ -32,28 +34,26 @@ export default function DreamCard({dream, user, animationDelay = 0}: DreamCardPr style={{borderColor: 'var(--accent-soft)'}} />

+ style={getAccentStyle()}> {user?.name} hat geträumt:

{dream.title}

-

+

{(dream.input.inputType === 'text' && dream.input.input) || (dream.input.inputType === 'audio' && dream.input.transcript) || (dream.input.inputType === 'image' && dream.input.description)}

-

- {dream.date.toLocaleDateString('de-DE', { - day: '2-digit', month: '2-digit', year: 'numeric', hour: '2-digit', minute: '2-digit', - })} +

+ {formatDateWithTime(dream.date)}

{/* Display dream type as a tag */} + style={getAccentStyle(true)}> {dream.input.inputType}
diff --git a/src/components/TopBar.tsx b/src/components/TopBar.tsx index ca73118..010f828 100644 --- a/src/components/TopBar.tsx +++ b/src/components/TopBar.tsx @@ -1,6 +1,7 @@ import {useEffect, useState} from 'react'; import logotext from "../assets/logotext.svg"; import {NavLink} from "react-router-dom"; +import {getBackgroundStyle, getTextStyle} from '../styles/StyleUtils'; export default function TopBar() { const [visible, setVisible] = useState(true); @@ -56,9 +57,7 @@ export default function TopBar() { return (
@@ -74,16 +73,14 @@ export default function TopBar() { onClick={toggleTheme} className="p-2 rounded-full focus:outline-none transition-transform hover:scale-110" aria-label="Toggle theme" - style={{ - backgroundColor: 'var(--card)', boxShadow: '0 2px 8px var(--shadow)' - }} + style={getBackgroundStyle('card')} > {darkMode ? ( + viewBox="0 0 24 24" stroke="currentColor" style={getTextStyle('accent')}> ) : ( + viewBox="0 0 24 24" stroke="currentColor" style={getTextStyle('accent')}> )} diff --git a/src/pages/DreamPage.tsx b/src/pages/DreamPage.tsx index a6b1ede..9e0cc11 100644 --- a/src/pages/DreamPage.tsx +++ b/src/pages/DreamPage.tsx @@ -5,6 +5,7 @@ import {mockDreams} from '../data/MockDreams'; import MockUsers from '../data/MockUsers'; import User from '../types/User'; import type Dream from "../types/Dream.ts"; +import {formatDateNumeric, formatDateWithTime} from '../utils/DateUtils'; export default function DreamPage() { const {id} = useParams<{ id: string }>(); @@ -48,13 +49,7 @@ export default function DreamPage() { {user && (

{user.name} •{' '} - {dream.date.toLocaleDateString('de-DE', { - day: '2-digit', - month: '2-digit', - year: 'numeric', - hour: '2-digit', - minute: '2-digit', - })} + {formatDateWithTime(dream.date)}

)}
@@ -150,9 +145,7 @@ export default function DreamPage() {
Datum - {dream.date.toLocaleDateString('de-DE', { - day: '2-digit', month: '2-digit', year: 'numeric', - })} + {formatDateNumeric(dream.date)}
diff --git a/src/pages/Home.tsx b/src/pages/Home.tsx index 55a40ef..b495d5f 100644 --- a/src/pages/Home.tsx +++ b/src/pages/Home.tsx @@ -3,17 +3,14 @@ import {mockDreams} from '../data/MockDreams'; import {MockUserMap} from '../data/MockUsers'; import {getSortedDreamsByDate} from '../data/DreamUtils'; import {primaryMoodCategories, topDreamTopics} from '../data/MockDailyHighlights'; +import {getAccentStyle, getBackgroundStyle, getCardStyle, getTextStyle} from '../styles/StyleUtils'; +import {formatDateFull, formatDateSimple} from '../utils/DateUtils'; export default function Home() { const [inputMode, setInputMode] = useState<'text' | 'drawing'>('text'); const currentUser = MockUserMap.get(4); // Neo Quantum const currentDate = new Date(); - const formattedDate = currentDate.toLocaleDateString('de-DE', { - weekday: 'long', - year: 'numeric', - month: 'long', - day: 'numeric' - }); + const formattedDate = formatDateFull(currentDate); // Get personal dreams (latest 3 for user ID 4) const personalDreams = getSortedDreamsByDate( @@ -29,21 +26,17 @@ export default function Home() {
{/* Welcome Card */} -
+

Hallo Neo!

-

{formattedDate}

-

Willkommen zurück in deiner Traumwelt.

+

{formattedDate}

+

Willkommen zurück in deiner Traumwelt.

{/* Streak Notification */}
+ className={getCardStyle(true).className} + style={getBackgroundStyle('accent-gradient')}>
{/* Input Card */} -
+

Neuer Traum

@@ -94,8 +81,8 @@ export default function Home() { rows={4} placeholder="Beschreibe deinen Traum..." style={{ - backgroundColor: 'var(--bg)', - color: 'var(--text)', + ...getBackgroundStyle('normal'), + ...getTextStyle(), border: '1px solid var(--accent-soft)' }} > @@ -103,17 +90,17 @@ export default function Home() {
-

Zeichne deinen Traum hier (Canvas-Platzhalter)

+

Zeichne deinen Traum hier (Canvas-Platzhalter)

)}
{/* Personal Feed */} -
+

Deine letzten Träume

{personalDreams.length > 0 ? (
@@ -146,27 +133,26 @@ export default function Home() {
-

{dream.title}

-

- {dream.date.toLocaleDateString('de-DE')} +

{dream.title}

+

+ {formatDateSimple(dream.date)}

))}
) : ( -

+

Du hast noch keine Träume aufgezeichnet. Starte jetzt!

)}
{/* Friends Feed */} -
+

Träume von Freunden

{friendsDreams.map((dream, index) => { @@ -175,8 +161,7 @@ export default function Home() {
@@ -191,15 +176,15 @@ export default function Home() { alt={dreamUser.name} className="w-full h-full object-cover"/> ) : ( {dreamUser?.name.charAt(0)} + style={getTextStyle()}>{dreamUser?.name.charAt(0)} )}
{dreamUser?.name} + style={getTextStyle()}>{dreamUser?.name}
-

{dream.title}

-

- {dream.date.toLocaleDateString('de-DE')} +

{dream.title}

+

+ {formatDateSimple(dream.date)}

); @@ -208,19 +193,19 @@ export default function Home() {
{/* Daily Highlights */} -
+

Tägliche Highlights

-

Top Traumthemen

+ style={getBackgroundStyle('card')}> +

Top Traumthemen

    {topDreamTopics.map((topic, index) => (
  • + style={getTextStyle()}> {topic.label}: {topic.percentage}%
  • ))} @@ -228,13 +213,13 @@ export default function Home() {
-

Stimmungskategorien

+ style={getBackgroundStyle('card')}> +

Stimmungskategorien

    {primaryMoodCategories.map((mood, index) => (
  • + style={getTextStyle()}> {mood.label}: {mood.percentage}%
  • ))} @@ -245,12 +230,8 @@ export default function Home() { {/* Ad Banner */}
    + className={getCardStyle(true).className} + style={getBackgroundStyle('gradient')}>
    { + return { + backgroundColor: 'var(--card)', + color: 'var(--text)', + className: `dreamy-card p-4 mb-4 transition-all duration-300 hover:transform hover:scale-[1.01] ${floating ? 'floating' : ''}` + }; +}; + +/** + * Returns the style for accent-colored elements + * @param soft - Whether to use the soft accent color + * @param isActive - Whether the element is in active state + * @returns Object with style properties + */ +export const getAccentStyle = (soft: boolean = false, isActive: boolean = true) => { + if (!isActive) { + return { + backgroundColor: 'transparent', + color: 'var(--text)' + }; + } + + return { + backgroundColor: soft ? 'var(--accent-soft)' : 'var(--accent)', + color: soft ? 'var(--text)' : 'white' + }; +}; + +/** + * Returns the style for text elements + * @param type - The type of text (normal, muted, accent) + * @returns Object with style properties + */ +export const getTextStyle = (type: 'normal' | 'muted' | 'accent' = 'normal') => { + switch (type) { + case 'muted': + return {color: 'var(--text-muted)'}; + case 'accent': + return {color: 'var(--accent)'}; + default: + return {color: 'var(--text)'}; + } +}; + +/** + * Returns the style for background elements + * @param type - The type of background (normal, card, gradient) + * @returns Object with style properties + */ +export const getBackgroundStyle = (type: 'normal' | 'card' | 'gradient' | 'accent-gradient' | 'topbar' = 'normal') => { + switch (type) { + case 'card': + return {backgroundColor: 'var(--bg)', boxShadow: '0 4px 15px var(--shadow)'}; + case 'gradient': + return { + background: 'linear-gradient(135deg, var(--accent), var(--accent-dark))', + color: 'white', + boxShadow: '0 10px 30px var(--shadow), inset 0 0 15px rgba(166, 77, 255, 0.3)' + }; + case 'accent-gradient': + return { + background: 'var(--accent-gradient)', + color: 'white', + boxShadow: '0 10px 30px var(--shadow), inset 0 0 15px rgba(166, 77, 255, 0.3)' + }; + case 'topbar': + return { + background: 'var(--accent-gradient)', + boxShadow: '0 2px 10px var(--shadow)' + }; + default: + return {backgroundColor: 'var(--bg)'}; + } +}; diff --git a/src/utils/DateUtils.ts b/src/utils/DateUtils.ts new file mode 100644 index 0000000..74a7943 --- /dev/null +++ b/src/utils/DateUtils.ts @@ -0,0 +1,54 @@ +/** + * Utility functions for date formatting + */ + +/** + * Formats a date with full details including weekday and month names + * @param date - The date to format + * @returns Formatted date string (e.g., "Montag, 1. Januar 2023") + */ +export const formatDateFull = (date: Date): string => { + return date.toLocaleDateString('de-DE', { + weekday: 'long', + year: 'numeric', + month: 'long', + day: 'numeric' + }); +}; + +/** + * Formats a date in a simple format + * @param date - The date to format + * @returns Formatted date string (e.g., "01.01.2023") + */ +export const formatDateSimple = (date: Date): string => { + return date.toLocaleDateString('de-DE'); +}; + +/** + * Formats a date with time + * @param date - The date to format + * @returns Formatted date and time string (e.g., "01.01.2023, 14:30") + */ +export const formatDateWithTime = (date: Date): string => { + return date.toLocaleDateString('de-DE', { + day: '2-digit', + month: '2-digit', + year: 'numeric', + hour: '2-digit', + minute: '2-digit', + }); +}; + +/** + * Formats a date in a numeric format without time + * @param date - The date to format + * @returns Formatted date string (e.g., "01.01.2023") + */ +export const formatDateNumeric = (date: Date): string => { + return date.toLocaleDateString('de-DE', { + day: '2-digit', + month: '2-digit', + year: 'numeric', + }); +}; \ No newline at end of file