matt HOFFNER commited on
Commit
292de4b
β€’
1 Parent(s): 63c6de8

change bg based on time of day

Browse files
Files changed (3) hide show
  1. app/page.module.css +0 -4
  2. app/page.tsx +9 -2
  3. app/util.ts +55 -0
app/page.module.css CHANGED
@@ -11,10 +11,6 @@
11
  .background {
12
  position: absolute;
13
  top: 0; right: 0; bottom: 0; left: 0;
14
- background-color: #1E90FF; /* Solid color fallback */
15
- background-image:
16
- radial-gradient(circle at 20% 20%, rgba(255, 255, 255, 0.3), transparent 70%),
17
- radial-gradient(circle at 80% 80%, rgba(255, 255, 255, 0.3), transparent 70%);
18
  background-blend-mode: screen;
19
  background-size: cover;
20
  background-position: center;
 
11
  .background {
12
  position: absolute;
13
  top: 0; right: 0; bottom: 0; left: 0;
 
 
 
 
14
  background-blend-mode: screen;
15
  background-size: cover;
16
  background-position: center;
app/page.tsx CHANGED
@@ -1,15 +1,22 @@
1
  "use client";
2
 
3
  import styles from './page.module.css';
4
- import { useState } from 'react';
5
  import { useChat } from 'ai/react';
6
  import { FunctionCallHandler, Message, nanoid } from 'ai';
7
  import ReactMarkdown from "react-markdown";
8
  import { Bot, User } from "lucide-react";
9
  import { toast } from 'sonner';
10
  import { FunctionIcon } from './icons';
 
11
 
12
  const Page: React.FC = () => {
 
 
 
 
 
 
13
  const functionCallHandler: FunctionCallHandler = async (
14
  chatMessages,
15
  functionCall,
@@ -120,7 +127,7 @@ const Page: React.FC = () => {
120
 
121
  return (
122
  <main className={styles.main}>
123
- <div className={styles.background}></div>
124
  <div className={styles.messages}>
125
  {messages.length > 0 ? (
126
  messages.map((message, i) => {
 
1
  "use client";
2
 
3
  import styles from './page.module.css';
4
+ import { useEffect, useState } from 'react';
5
  import { useChat } from 'ai/react';
6
  import { FunctionCallHandler, Message, nanoid } from 'ai';
7
  import ReactMarkdown from "react-markdown";
8
  import { Bot, User } from "lucide-react";
9
  import { toast } from 'sonner';
10
  import { FunctionIcon } from './icons';
11
+ import { updateBackground } from './util';
12
 
13
  const Page: React.FC = () => {
14
+ useEffect(() => {
15
+ updateBackground();
16
+ const interval = setInterval(updateBackground, 6000);
17
+
18
+ return () => clearInterval(interval);
19
+ }, []);
20
  const functionCallHandler: FunctionCallHandler = async (
21
  chatMessages,
22
  functionCall,
 
127
 
128
  return (
129
  <main className={styles.main}>
130
+ <div id="bg" className={styles.background}></div>
131
  <div className={styles.messages}>
132
  {messages.length > 0 ? (
133
  messages.map((message, i) => {
app/util.ts ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ export function updateBackground(): void {
2
+ const hour = new Date().getHours();
3
+ const background = document.getElementById('bg') as HTMLElement | null;
4
+
5
+ if (!background) {
6
+ console.warn("Background element not found, will retry later.");
7
+ setTimeout(updateBackground, 500); // Retry after a delay
8
+ return;
9
+ }
10
+
11
+ let color1, color2, color3; // Colors for the radial gradients and background
12
+
13
+ if (hour >= 6 && hour < 8) {
14
+ // Early morning
15
+ color1 = 'rgba(173, 216, 230, 0.3)';
16
+ color2 = 'rgba(135, 206, 250, 0.3)';
17
+ color3 = '#B0E0E6'; // Powder blue
18
+ } else if (hour >= 8 && hour < 10) {
19
+ // Mid-morning
20
+ color1 = 'rgba(240, 230, 140, 0.3)';
21
+ color2 = 'rgba(238, 232, 170, 0.3)';
22
+ color3 = '#F0E68C'; // Khaki
23
+ } else if (hour >= 10 && hour < 12) {
24
+ // Late morning
25
+ color1 = 'rgba(250, 250, 210, 0.3)';
26
+ color2 = 'rgba(255, 255, 224, 0.3)';
27
+ color3 = '#FFFACD'; // Lemon chiffon
28
+ } else if (hour >= 12 && hour < 14) {
29
+ // Early afternoon
30
+ color1 = 'rgba(255, 182, 193, 0.3)';
31
+ color2 = 'rgba(255, 192, 203, 0.3)';
32
+ color3 = '#FFB6C1'; // Light pink
33
+ } else if (hour >= 14 && hour < 16) {
34
+ // Mid-afternoon
35
+ color1 = 'rgba(255, 160, 122, 0.3)';
36
+ color2 = 'rgba(255, 127, 80, 0.3)';
37
+ color3 = '#FFA07A'; // Light salmon
38
+ } else if (hour >= 16 && hour < 18) {
39
+ // Late afternoon to early evening
40
+ color1 = 'rgba(255, 99, 71, 0.3)';
41
+ color2 = 'rgba(255, 69, 0, 0.3)';
42
+ color3 = '#FF4500'; // Orange red
43
+ } else {
44
+ // Night
45
+ color1 = 'black';
46
+ color2 = 'black';
47
+ color3 = '#000080'; // Navy blue for a slightly softer night effect
48
+ }
49
+
50
+ // Set the background image and color
51
+ background.style.backgroundImage =
52
+ `radial-gradient(circle at 20% 20%, ${color1}, transparent 70%),
53
+ radial-gradient(circle at 80% 80%, ${color2}, transparent 70%)`;
54
+ background.style.backgroundColor = color3;
55
+ }