Compare commits
	
		
			38 Commits
		
	
	
		
			d089f1545b
			...
			feature/ex
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | 45e16313ba | ||
|  | 64c737c023 | ||
|  | 75d9149c76 | ||
|  | 28b3946e86 | ||
|  | 6a01a75cce | ||
|  | 189dd32f8c | ||
|  | 7461e8b123 | ||
|  | f88c238b0a | ||
|  | 8caa1f45ae | ||
|  | 289284a532 | ||
|  | 089f4ce105 | ||
|  | 235dcf8e1d | ||
|  | 8dd60a8ec1 | ||
|  | 20679b6b53 | ||
|  | 53c4a99697 | ||
|  | 5ea33b7d0a | ||
|  | 13a752a69c | ||
|  | 0609a99839 | ||
|  | dce82d5f7d | ||
|  | 1e8a8ce5f2 | ||
|  | c0bdd3d8c2 | ||
|  | 2b98c4d229 | ||
|  | ceae654a39 | ||
|  | fb28fa95c9 | ||
|  | 419cb3d790 | ||
|  | 53a62fb05e | ||
|  | 322c88612a | ||
|  | 4aa53d79e7 | ||
|  | 3464754489 | ||
|  | e56253b9c2 | ||
|  | cb8cc7258c | ||
|  | b576cd8c4a | ||
|  | a773159016 | ||
|  | a9521ad536 | ||
|  | 5456d7140c | ||
|  | 62cc910e1a | ||
|  | 6ec7bb5422 | ||
|  | ce74750d85 | 
| @@ -18,17 +18,18 @@ jobs: | |||||||
|       - name: Login to Docker Registry |       - name: Login to Docker Registry | ||||||
|         uses: docker/login-action@v3 |         uses: docker/login-action@v3 | ||||||
|         with: |         with: | ||||||
|           registry: ${{ secrets.DOCKER_REGISTRY }} |           registry: ${{ vars.REGISTRY }} | ||||||
|           username: ${{ secrets.DOCKER_USERNAME }} |           username: ${{ vars.USERNAME }} | ||||||
|           password: ${{ secrets.DOCKER_PASSWORD }} |           password: ${{ secrets.DOCKER_PASSWORD }} | ||||||
|  |  | ||||||
|       - name: Build and push |       - name: Build and push | ||||||
|         uses: docker/build-push-action@v5 |         uses: docker/build-push-action@v5 | ||||||
|         with: |         with: | ||||||
|           context: . |           context: . | ||||||
|  |           file: ./backend/Dockerfile | ||||||
|           push: true |           push: true | ||||||
|           tags: | |           tags: | | ||||||
|             ${{ secrets.DOCKER_REGISTRY }}/connor/calendar:latest |             ${{ vars.REGISTRY }}/connor/calendar:latest | ||||||
|             ${{ secrets.DOCKER_REGISTRY }}/connor/calendar:${{ github.sha }} |             ${{ vars.REGISTRY }}/connor/calendar:${{ github.sha }} | ||||||
|           cache-from: type=gha |           cache-from: type=gha | ||||||
|           cache-to: type=gha,mode=max |           cache-to: type=gha,mode=max | ||||||
|   | |||||||
| @@ -5,6 +5,11 @@ | |||||||
| } | } | ||||||
|  |  | ||||||
| :80, :443 { | :80, :443 { | ||||||
|  |     @backend { | ||||||
|  |         path /api /api/* | ||||||
|  |     } | ||||||
|  |     reverse_proxy @backend calendar-backend:3000 | ||||||
|  |     try_files {path} /index.html | ||||||
|     root * /srv/www |     root * /srv/www | ||||||
|     file_server |     file_server | ||||||
| } | } | ||||||
|   | |||||||
							
								
								
									
										109
									
								
								Dockerfile
									
									
									
									
									
								
							
							
						
						
									
										109
									
								
								Dockerfile
									
									
									
									
									
								
							| @@ -1,109 +0,0 @@ | |||||||
| # Build stage |  | ||||||
| # ----------------------------------------------------------- |  | ||||||
| FROM rust:alpine AS builder |  | ||||||
|  |  | ||||||
| RUN apk add --no-cache musl-dev pkgconfig openssl-dev openssl-libs-static nodejs npm |  | ||||||
|  |  | ||||||
| # Install trunk ahead of the compilation. This may break and then you'll have to update the version. |  | ||||||
| RUN cargo install trunk@0.21.14 wasm-pack@0.13.1 wasm-bindgen-cli@0.2.100 |  | ||||||
|  |  | ||||||
| RUN rustup target add wasm32-unknown-unknown |  | ||||||
| WORKDIR /app |  | ||||||
|  |  | ||||||
| # Copy workspace files to maintain workspace structure |  | ||||||
| COPY Cargo.toml Cargo.lock ./ |  | ||||||
| COPY calendar-models ./calendar-models |  | ||||||
| COPY frontend/Cargo.toml ./frontend/ |  | ||||||
| COPY frontend/Trunk.toml ./frontend/ |  | ||||||
| COPY frontend/index.html ./frontend/ |  | ||||||
| COPY frontend/styles.css ./frontend/ |  | ||||||
|  |  | ||||||
| # Create empty backend directory to satisfy workspace |  | ||||||
| RUN mkdir -p backend/src && \ |  | ||||||
|     printf '[package]\nname = "calendar-backend"\nversion = "0.1.0"\nedition = "2021"\n\n[dependencies]\n' > backend/Cargo.toml && \ |  | ||||||
|     echo 'fn main() {}' > backend/src/main.rs |  | ||||||
|  |  | ||||||
| # Create dummy source files to build dependencies first |  | ||||||
| RUN mkdir -p frontend/src && \ |  | ||||||
|     echo "use web_sys::*; fn main() {}" > frontend/src/main.rs && \ |  | ||||||
|     echo "pub fn add(a: usize, b: usize) -> usize { a + b }" > calendar-models/src/lib.rs |  | ||||||
|  |  | ||||||
| # Build dependencies (this layer will be cached unless dependencies change) |  | ||||||
| RUN cargo build --release --target wasm32-unknown-unknown --bin runway |  | ||||||
|  |  | ||||||
| # Copy actual source code and build the frontend application |  | ||||||
| RUN rm -rf frontend |  | ||||||
| COPY frontend ./frontend |  | ||||||
| RUN trunk build --release --config ./frontend/Trunk.toml |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| # Backend build stage |  | ||||||
| # ----------------------------------------------------------- |  | ||||||
| FROM rust:alpine AS backend-builder |  | ||||||
|  |  | ||||||
| # Install build dependencies for backend |  | ||||||
| WORKDIR /app |  | ||||||
| RUN apk add --no-cache musl-dev pkgconfig openssl-dev openssl-libs-static |  | ||||||
|  |  | ||||||
| # Install sqlx-cli for migrations |  | ||||||
| RUN cargo install sqlx-cli --no-default-features --features sqlite |  | ||||||
|  |  | ||||||
| # Copy shared models |  | ||||||
| COPY calendar-models ./calendar-models |  | ||||||
|  |  | ||||||
| # Create empty frontend directory to satisfy workspace |  | ||||||
| RUN mkdir -p frontend/src && \ |  | ||||||
|     printf '[package]\nname = "runway"\nversion = "0.1.0"\nedition = "2021"\n\n[dependencies]\n' > frontend/Cargo.toml && \ |  | ||||||
|     echo 'fn main() {}' > frontend/src/main.rs |  | ||||||
|  |  | ||||||
| # Create dummy backend source to build dependencies first |  | ||||||
| RUN mkdir -p backend/src && \ |  | ||||||
|     echo "fn main() {}" > backend/src/main.rs |  | ||||||
|  |  | ||||||
| # Build dependencies (this layer will be cached unless dependencies change) |  | ||||||
| COPY Cargo.toml Cargo.lock ./ |  | ||||||
| COPY backend/Cargo.toml ./backend/ |  | ||||||
| RUN cargo build --release |  | ||||||
|  |  | ||||||
| # Build the backend |  | ||||||
| COPY backend ./backend |  | ||||||
| RUN cargo build --release --bin backend |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| # Runtime stage |  | ||||||
| # ----------------------------------------------------------- |  | ||||||
| FROM alpine:latest |  | ||||||
|  |  | ||||||
| # Install runtime dependencies |  | ||||||
| RUN apk add --no-cache ca-certificates tzdata sqlite |  | ||||||
|  |  | ||||||
| # Copy frontend files to temporary location |  | ||||||
| COPY --from=builder /app/frontend/dist /app/frontend-dist |  | ||||||
|  |  | ||||||
| # Copy backend binary and sqlx-cli |  | ||||||
| COPY --from=backend-builder /app/target/release/backend /usr/local/bin/backend |  | ||||||
| COPY --from=backend-builder /usr/local/cargo/bin/sqlx /usr/local/bin/sqlx |  | ||||||
|  |  | ||||||
| # Copy migrations for database setup |  | ||||||
| COPY --from=backend-builder /app/backend/migrations /migrations |  | ||||||
|  |  | ||||||
| # Create startup script to copy frontend files, run migrations, and start backend |  | ||||||
| RUN mkdir -p /srv/www /db |  | ||||||
| RUN echo '#!/bin/sh' > /usr/local/bin/start.sh && \ |  | ||||||
|     echo 'echo "Copying frontend files..."' >> /usr/local/bin/start.sh && \ |  | ||||||
|     echo 'cp -r /app/frontend-dist/* /srv/www/' >> /usr/local/bin/start.sh && \ |  | ||||||
|     echo 'echo "Ensuring database directory exists..."' >> /usr/local/bin/start.sh && \ |  | ||||||
|     echo 'mkdir -p /db && chmod 755 /db' >> /usr/local/bin/start.sh && \ |  | ||||||
|     echo 'echo "Running database migrations..."' >> /usr/local/bin/start.sh && \ |  | ||||||
|     echo 'sqlx migrate run --database-url "sqlite:///db/calendar.db" --source /migrations || echo "Migration failed but continuing..."' >> /usr/local/bin/start.sh && \ |  | ||||||
|     echo 'echo "Starting backend server..."' >> /usr/local/bin/start.sh && \ |  | ||||||
|     echo 'export DATABASE_URL="sqlite:///db/calendar.db"' >> /usr/local/bin/start.sh && \ |  | ||||||
|     echo '/usr/local/bin/backend' >> /usr/local/bin/start.sh && \ |  | ||||||
|     chmod +x /usr/local/bin/start.sh |  | ||||||
|  |  | ||||||
| # Start with script that copies frontend files then starts backend |  | ||||||
| CMD ["/usr/local/bin/start.sh"] |  | ||||||
| @@ -22,6 +22,7 @@ hyper = { version = "1.0", features = ["full"] } | |||||||
| serde = { version = "1.0", features = ["derive"] } | serde = { version = "1.0", features = ["derive"] } | ||||||
| serde_json = "1.0" | serde_json = "1.0" | ||||||
| chrono = { version = "0.4", features = ["serde"] } | chrono = { version = "0.4", features = ["serde"] } | ||||||
|  | chrono-tz = "0.8" | ||||||
| uuid = { version = "1.0", features = ["v4", "serde"] } | uuid = { version = "1.0", features = ["v4", "serde"] } | ||||||
| anyhow = "1.0" | anyhow = "1.0" | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										64
									
								
								backend/Dockerfile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										64
									
								
								backend/Dockerfile
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,64 @@ | |||||||
|  | # Build stage | ||||||
|  | # ----------------------------------------------------------- | ||||||
|  | FROM rust:alpine AS builder | ||||||
|  |  | ||||||
|  | # Install build dependencies for backend | ||||||
|  | WORKDIR /app | ||||||
|  | RUN apk add --no-cache musl-dev pkgconfig openssl-dev openssl-libs-static | ||||||
|  |  | ||||||
|  | # Install sqlx-cli for migrations | ||||||
|  | RUN cargo install sqlx-cli --no-default-features --features sqlite | ||||||
|  |  | ||||||
|  | # Copy workspace files to maintain workspace structure | ||||||
|  | COPY ./Cargo.toml ./ | ||||||
|  | COPY ./calendar-models ./calendar-models | ||||||
|  |  | ||||||
|  | # Create empty frontend directory to satisfy workspace | ||||||
|  | RUN mkdir -p frontend/src && \ | ||||||
|  |     printf '[package]\nname = "runway"\nversion = "0.1.0"\nedition = "2021"\n\n[dependencies]\n' > frontend/Cargo.toml && \ | ||||||
|  |     echo 'fn main() {}' > frontend/src/main.rs | ||||||
|  |  | ||||||
|  | # Copy backend files | ||||||
|  | COPY backend/Cargo.toml ./backend/ | ||||||
|  |  | ||||||
|  | # Create dummy backend source to build dependencies first | ||||||
|  | RUN mkdir -p backend/src && \ | ||||||
|  |     echo "fn main() {}" > backend/src/main.rs | ||||||
|  |  | ||||||
|  | # Build dependencies (this layer will be cached unless dependencies change) | ||||||
|  | RUN cargo build --release | ||||||
|  |  | ||||||
|  | # Copy actual backend source and build | ||||||
|  | COPY backend/src ./backend/src | ||||||
|  | COPY backend/migrations ./backend/migrations | ||||||
|  | RUN cargo build --release --bin backend | ||||||
|  |  | ||||||
|  | # Runtime stage | ||||||
|  | # ----------------------------------------------------------- | ||||||
|  | FROM alpine:latest | ||||||
|  |  | ||||||
|  | # Install runtime dependencies | ||||||
|  | RUN apk add --no-cache ca-certificates tzdata sqlite | ||||||
|  |  | ||||||
|  | # Copy backend binary and sqlx-cli | ||||||
|  | COPY --from=builder /app/target/release/backend /usr/local/bin/backend | ||||||
|  | COPY --from=builder /usr/local/cargo/bin/sqlx /usr/local/bin/sqlx | ||||||
|  |  | ||||||
|  | # Copy migrations for database setup | ||||||
|  | COPY backend/migrations /migrations | ||||||
|  |  | ||||||
|  | # Create startup script to run migrations and start backend | ||||||
|  | RUN mkdir -p /db | ||||||
|  | RUN echo '#!/bin/sh' > /usr/local/bin/start.sh && \ | ||||||
|  |     echo 'echo "Ensuring database directory exists..."' >> /usr/local/bin/start.sh && \ | ||||||
|  |     echo 'mkdir -p /db && chmod 755 /db' >> /usr/local/bin/start.sh && \ | ||||||
|  |     echo 'touch /db/calendar.db' >> /usr/local/bin/start.sh && \ | ||||||
|  |     echo 'echo "Running database migrations..."' >> /usr/local/bin/start.sh && \ | ||||||
|  |     echo 'sqlx migrate run --database-url "sqlite:///db/calendar.db" --source /migrations || echo "Migration failed but continuing..."' >> /usr/local/bin/start.sh && \ | ||||||
|  |     echo 'echo "Starting backend server..."' >> /usr/local/bin/start.sh && \ | ||||||
|  |     echo 'export DATABASE_URL="sqlite:///db/calendar.db"' >> /usr/local/bin/start.sh && \ | ||||||
|  |     echo '/usr/local/bin/backend' >> /usr/local/bin/start.sh && \ | ||||||
|  |     chmod +x /usr/local/bin/start.sh | ||||||
|  |  | ||||||
|  | # Start with script that runs migrations then starts backend | ||||||
|  | CMD ["/usr/local/bin/start.sh"] | ||||||
							
								
								
									
										2
									
								
								backend/migrations/005_add_last_used_calendar.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								backend/migrations/005_add_last_used_calendar.sql
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,2 @@ | |||||||
|  | -- Add last used calendar preference to user preferences | ||||||
|  | ALTER TABLE user_preferences ADD COLUMN last_used_calendar TEXT; | ||||||
							
								
								
									
										16
									
								
								backend/migrations/006_create_external_calendars_table.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								backend/migrations/006_create_external_calendars_table.sql
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,16 @@ | |||||||
|  | -- Create external_calendars table | ||||||
|  | CREATE TABLE external_calendars ( | ||||||
|  |     id INTEGER PRIMARY KEY AUTOINCREMENT, | ||||||
|  |     user_id INTEGER NOT NULL, | ||||||
|  |     name TEXT NOT NULL, | ||||||
|  |     url TEXT NOT NULL, | ||||||
|  |     color TEXT NOT NULL DEFAULT '#4285f4', | ||||||
|  |     is_visible BOOLEAN NOT NULL DEFAULT 1, | ||||||
|  |     created_at DATETIME DEFAULT CURRENT_TIMESTAMP, | ||||||
|  |     updated_at DATETIME DEFAULT CURRENT_TIMESTAMP, | ||||||
|  |     last_fetched DATETIME, | ||||||
|  |     FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE | ||||||
|  | ); | ||||||
|  |  | ||||||
|  | -- Create index for performance | ||||||
|  | CREATE INDEX idx_external_calendars_user_id ON external_calendars(user_id); | ||||||
| @@ -0,0 +1,14 @@ | |||||||
|  | -- Create external calendar cache table for storing ICS data | ||||||
|  | CREATE TABLE external_calendar_cache ( | ||||||
|  |     id INTEGER PRIMARY KEY AUTOINCREMENT, | ||||||
|  |     external_calendar_id INTEGER NOT NULL, | ||||||
|  |     ics_data TEXT NOT NULL, | ||||||
|  |     cached_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||||||
|  |     etag TEXT, | ||||||
|  |     FOREIGN KEY (external_calendar_id) REFERENCES external_calendars(id) ON DELETE CASCADE, | ||||||
|  |     UNIQUE(external_calendar_id) | ||||||
|  | ); | ||||||
|  |  | ||||||
|  | -- Index for faster lookups | ||||||
|  | CREATE INDEX idx_external_calendar_cache_calendar_id ON external_calendar_cache(external_calendar_id); | ||||||
|  | CREATE INDEX idx_external_calendar_cache_cached_at ON external_calendar_cache(cached_at); | ||||||
| @@ -93,6 +93,7 @@ impl AuthService { | |||||||
|                         calendar_theme: preferences.calendar_theme, |                         calendar_theme: preferences.calendar_theme, | ||||||
|                         calendar_style: preferences.calendar_style, |                         calendar_style: preferences.calendar_style, | ||||||
|                         calendar_colors: preferences.calendar_colors, |                         calendar_colors: preferences.calendar_colors, | ||||||
|  |                         last_used_calendar: preferences.last_used_calendar, | ||||||
|                     }, |                     }, | ||||||
|                 }) |                 }) | ||||||
|             } |             } | ||||||
| @@ -111,6 +112,17 @@ impl AuthService { | |||||||
|         self.decode_token(token) |         self.decode_token(token) | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /// Get user from token | ||||||
|  |     pub async fn get_user_from_token(&self, token: &str) -> Result<crate::db::User, ApiError> { | ||||||
|  |         let claims = self.verify_token(token)?; | ||||||
|  |          | ||||||
|  |         let user_repo = UserRepository::new(&self.db); | ||||||
|  |         user_repo | ||||||
|  |             .find_or_create(&claims.username, &claims.server_url) | ||||||
|  |             .await | ||||||
|  |             .map_err(|e| ApiError::Database(format!("Failed to get user: {}", e))) | ||||||
|  |     } | ||||||
|  |  | ||||||
|     /// Create CalDAV config from token |     /// Create CalDAV config from token | ||||||
|     pub fn caldav_config_from_token( |     pub fn caldav_config_from_token( | ||||||
|         &self, |         &self, | ||||||
|   | |||||||
| @@ -361,11 +361,10 @@ impl CalDAVClient { | |||||||
|             None |             None | ||||||
|         }; |         }; | ||||||
|  |  | ||||||
|         // Determine if it's an all-day event |         // Determine if it's an all-day event by checking for VALUE=DATE parameter | ||||||
|         let all_day = properties |         let empty_string = String::new(); | ||||||
|             .get("DTSTART") |         let dtstart_raw = properties.get("DTSTART").unwrap_or(&empty_string); | ||||||
|             .map(|s| !s.contains("T")) |         let all_day = dtstart_raw.contains("VALUE=DATE") || (!dtstart_raw.contains("T") && dtstart_raw.len() == 8); | ||||||
|             .unwrap_or(false); |  | ||||||
|  |  | ||||||
|         // Parse status |         // Parse status | ||||||
|         let status = properties |         let status = properties | ||||||
|   | |||||||
| @@ -1,4 +1,4 @@ | |||||||
| use chrono::{DateTime, Utc}; | use chrono::{DateTime, Duration, Utc}; | ||||||
| use serde::{Deserialize, Serialize}; | use serde::{Deserialize, Serialize}; | ||||||
| use sqlx::sqlite::{SqlitePool, SqlitePoolOptions}; | use sqlx::sqlite::{SqlitePool, SqlitePoolOptions}; | ||||||
| use sqlx::{FromRow, Result}; | use sqlx::{FromRow, Result}; | ||||||
| @@ -95,9 +95,42 @@ pub struct UserPreferences { | |||||||
|     pub calendar_theme: Option<String>, |     pub calendar_theme: Option<String>, | ||||||
|     pub calendar_style: Option<String>, |     pub calendar_style: Option<String>, | ||||||
|     pub calendar_colors: Option<String>, // JSON string |     pub calendar_colors: Option<String>, // JSON string | ||||||
|  |     pub last_used_calendar: Option<String>, | ||||||
|     pub updated_at: DateTime<Utc>, |     pub updated_at: DateTime<Utc>, | ||||||
| } | } | ||||||
|  |  | ||||||
|  | /// External calendar model | ||||||
|  | #[derive(Debug, Clone, Serialize, Deserialize, FromRow)] | ||||||
|  | pub struct ExternalCalendar { | ||||||
|  |     pub id: i32, | ||||||
|  |     pub user_id: String, | ||||||
|  |     pub name: String, | ||||||
|  |     pub url: String, | ||||||
|  |     pub color: String, | ||||||
|  |     pub is_visible: bool, | ||||||
|  |     pub created_at: DateTime<Utc>, | ||||||
|  |     pub updated_at: DateTime<Utc>, | ||||||
|  |     pub last_fetched: Option<DateTime<Utc>>, | ||||||
|  | } | ||||||
|  |  | ||||||
|  | impl ExternalCalendar { | ||||||
|  |     /// Create a new external calendar | ||||||
|  |     pub fn new(user_id: String, name: String, url: String, color: String) -> Self { | ||||||
|  |         let now = Utc::now(); | ||||||
|  |         Self { | ||||||
|  |             id: 0, // Will be set by database | ||||||
|  |             user_id, | ||||||
|  |             name, | ||||||
|  |             url, | ||||||
|  |             color, | ||||||
|  |             is_visible: true, | ||||||
|  |             created_at: now, | ||||||
|  |             updated_at: now, | ||||||
|  |             last_fetched: None, | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
| impl UserPreferences { | impl UserPreferences { | ||||||
|     /// Create default preferences for a new user |     /// Create default preferences for a new user | ||||||
|     pub fn default_for_user(user_id: String) -> Self { |     pub fn default_for_user(user_id: String) -> Self { | ||||||
| @@ -109,6 +142,7 @@ impl UserPreferences { | |||||||
|             calendar_theme: Some("light".to_string()), |             calendar_theme: Some("light".to_string()), | ||||||
|             calendar_style: Some("default".to_string()), |             calendar_style: Some("default".to_string()), | ||||||
|             calendar_colors: None, |             calendar_colors: None, | ||||||
|  |             last_used_calendar: None, | ||||||
|             updated_at: Utc::now(), |             updated_at: Utc::now(), | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| @@ -266,8 +300,8 @@ impl<'a> PreferencesRepository<'a> { | |||||||
|             sqlx::query( |             sqlx::query( | ||||||
|                 "INSERT INTO user_preferences  |                 "INSERT INTO user_preferences  | ||||||
|                  (user_id, calendar_selected_date, calendar_time_increment,  |                  (user_id, calendar_selected_date, calendar_time_increment,  | ||||||
|                   calendar_view_mode, calendar_theme, calendar_style, calendar_colors, updated_at)  |                   calendar_view_mode, calendar_theme, calendar_style, calendar_colors, last_used_calendar, updated_at)  | ||||||
|                  VALUES (?, ?, ?, ?, ?, ?, ?, ?)", |                  VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", | ||||||
|             ) |             ) | ||||||
|             .bind(&prefs.user_id) |             .bind(&prefs.user_id) | ||||||
|             .bind(&prefs.calendar_selected_date) |             .bind(&prefs.calendar_selected_date) | ||||||
| @@ -276,6 +310,7 @@ impl<'a> PreferencesRepository<'a> { | |||||||
|             .bind(&prefs.calendar_theme) |             .bind(&prefs.calendar_theme) | ||||||
|             .bind(&prefs.calendar_style) |             .bind(&prefs.calendar_style) | ||||||
|             .bind(&prefs.calendar_colors) |             .bind(&prefs.calendar_colors) | ||||||
|  |             .bind(&prefs.last_used_calendar) | ||||||
|             .bind(&prefs.updated_at) |             .bind(&prefs.updated_at) | ||||||
|             .execute(self.db.pool()) |             .execute(self.db.pool()) | ||||||
|             .await?; |             .await?; | ||||||
| @@ -290,7 +325,7 @@ impl<'a> PreferencesRepository<'a> { | |||||||
|             "UPDATE user_preferences  |             "UPDATE user_preferences  | ||||||
|              SET calendar_selected_date = ?, calendar_time_increment = ?,  |              SET calendar_selected_date = ?, calendar_time_increment = ?,  | ||||||
|                  calendar_view_mode = ?, calendar_theme = ?, calendar_style = ?, |                  calendar_view_mode = ?, calendar_theme = ?, calendar_style = ?, | ||||||
|                  calendar_colors = ?, updated_at = ? |                  calendar_colors = ?, last_used_calendar = ?, updated_at = ? | ||||||
|              WHERE user_id = ?", |              WHERE user_id = ?", | ||||||
|         ) |         ) | ||||||
|         .bind(&prefs.calendar_selected_date) |         .bind(&prefs.calendar_selected_date) | ||||||
| @@ -299,6 +334,7 @@ impl<'a> PreferencesRepository<'a> { | |||||||
|         .bind(&prefs.calendar_theme) |         .bind(&prefs.calendar_theme) | ||||||
|         .bind(&prefs.calendar_style) |         .bind(&prefs.calendar_style) | ||||||
|         .bind(&prefs.calendar_colors) |         .bind(&prefs.calendar_colors) | ||||||
|  |         .bind(&prefs.last_used_calendar) | ||||||
|         .bind(Utc::now()) |         .bind(Utc::now()) | ||||||
|         .bind(&prefs.user_id) |         .bind(&prefs.user_id) | ||||||
|         .execute(self.db.pool()) |         .execute(self.db.pool()) | ||||||
| @@ -307,3 +343,146 @@ impl<'a> PreferencesRepository<'a> { | |||||||
|         Ok(()) |         Ok(()) | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | /// Repository for ExternalCalendar operations | ||||||
|  | pub struct ExternalCalendarRepository<'a> { | ||||||
|  |     db: &'a Database, | ||||||
|  | } | ||||||
|  |  | ||||||
|  | impl<'a> ExternalCalendarRepository<'a> { | ||||||
|  |     pub fn new(db: &'a Database) -> Self { | ||||||
|  |         Self { db } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /// Get all external calendars for a user | ||||||
|  |     pub async fn get_by_user(&self, user_id: &str) -> Result<Vec<ExternalCalendar>> { | ||||||
|  |         sqlx::query_as::<_, ExternalCalendar>( | ||||||
|  |             "SELECT * FROM external_calendars WHERE user_id = ? ORDER BY created_at ASC", | ||||||
|  |         ) | ||||||
|  |         .bind(user_id) | ||||||
|  |         .fetch_all(self.db.pool()) | ||||||
|  |         .await | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /// Create a new external calendar | ||||||
|  |     pub async fn create(&self, calendar: &ExternalCalendar) -> Result<i32> { | ||||||
|  |         let result = sqlx::query( | ||||||
|  |             "INSERT INTO external_calendars (user_id, name, url, color, is_visible, created_at, updated_at)  | ||||||
|  |              VALUES (?, ?, ?, ?, ?, ?, ?)", | ||||||
|  |         ) | ||||||
|  |         .bind(&calendar.user_id) | ||||||
|  |         .bind(&calendar.name) | ||||||
|  |         .bind(&calendar.url) | ||||||
|  |         .bind(&calendar.color) | ||||||
|  |         .bind(&calendar.is_visible) | ||||||
|  |         .bind(&calendar.created_at) | ||||||
|  |         .bind(&calendar.updated_at) | ||||||
|  |         .execute(self.db.pool()) | ||||||
|  |         .await?; | ||||||
|  |  | ||||||
|  |         Ok(result.last_insert_rowid() as i32) | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /// Update an external calendar | ||||||
|  |     pub async fn update(&self, id: i32, calendar: &ExternalCalendar) -> Result<()> { | ||||||
|  |         sqlx::query( | ||||||
|  |             "UPDATE external_calendars  | ||||||
|  |              SET name = ?, url = ?, color = ?, is_visible = ?, updated_at = ? | ||||||
|  |              WHERE id = ? AND user_id = ?", | ||||||
|  |         ) | ||||||
|  |         .bind(&calendar.name) | ||||||
|  |         .bind(&calendar.url) | ||||||
|  |         .bind(&calendar.color) | ||||||
|  |         .bind(&calendar.is_visible) | ||||||
|  |         .bind(Utc::now()) | ||||||
|  |         .bind(id) | ||||||
|  |         .bind(&calendar.user_id) | ||||||
|  |         .execute(self.db.pool()) | ||||||
|  |         .await?; | ||||||
|  |  | ||||||
|  |         Ok(()) | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /// Delete an external calendar | ||||||
|  |     pub async fn delete(&self, id: i32, user_id: &str) -> Result<()> { | ||||||
|  |         sqlx::query("DELETE FROM external_calendars WHERE id = ? AND user_id = ?") | ||||||
|  |             .bind(id) | ||||||
|  |             .bind(user_id) | ||||||
|  |             .execute(self.db.pool()) | ||||||
|  |             .await?; | ||||||
|  |  | ||||||
|  |         Ok(()) | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /// Update last_fetched timestamp | ||||||
|  |     pub async fn update_last_fetched(&self, id: i32, user_id: &str) -> Result<()> { | ||||||
|  |         sqlx::query( | ||||||
|  |             "UPDATE external_calendars SET last_fetched = ? WHERE id = ? AND user_id = ?", | ||||||
|  |         ) | ||||||
|  |         .bind(Utc::now()) | ||||||
|  |         .bind(id) | ||||||
|  |         .bind(user_id) | ||||||
|  |         .execute(self.db.pool()) | ||||||
|  |         .await?; | ||||||
|  |  | ||||||
|  |         Ok(()) | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /// Get cached ICS data for an external calendar | ||||||
|  |     pub async fn get_cached_data(&self, external_calendar_id: i32) -> Result<Option<(String, DateTime<Utc>)>> { | ||||||
|  |         let result = sqlx::query_as::<_, (String, DateTime<Utc>)>( | ||||||
|  |             "SELECT ics_data, cached_at FROM external_calendar_cache WHERE external_calendar_id = ?", | ||||||
|  |         ) | ||||||
|  |         .bind(external_calendar_id) | ||||||
|  |         .fetch_optional(self.db.pool()) | ||||||
|  |         .await?; | ||||||
|  |  | ||||||
|  |         Ok(result) | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /// Update cache with new ICS data | ||||||
|  |     pub async fn update_cache(&self, external_calendar_id: i32, ics_data: &str, etag: Option<&str>) -> Result<()> { | ||||||
|  |         sqlx::query( | ||||||
|  |             "INSERT INTO external_calendar_cache (external_calendar_id, ics_data, etag, cached_at) | ||||||
|  |              VALUES (?, ?, ?, ?) | ||||||
|  |              ON CONFLICT(external_calendar_id) DO UPDATE SET | ||||||
|  |              ics_data = excluded.ics_data, | ||||||
|  |              etag = excluded.etag, | ||||||
|  |              cached_at = excluded.cached_at", | ||||||
|  |         ) | ||||||
|  |         .bind(external_calendar_id) | ||||||
|  |         .bind(ics_data) | ||||||
|  |         .bind(etag) | ||||||
|  |         .bind(Utc::now()) | ||||||
|  |         .execute(self.db.pool()) | ||||||
|  |         .await?; | ||||||
|  |  | ||||||
|  |         Ok(()) | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /// Check if cache is stale (older than max_age_minutes) | ||||||
|  |     pub async fn is_cache_stale(&self, external_calendar_id: i32, max_age_minutes: i64) -> Result<bool> { | ||||||
|  |         let cutoff_time = Utc::now() - Duration::minutes(max_age_minutes); | ||||||
|  |          | ||||||
|  |         let result = sqlx::query_scalar::<_, i64>( | ||||||
|  |             "SELECT COUNT(*) FROM external_calendar_cache  | ||||||
|  |              WHERE external_calendar_id = ? AND cached_at > ?", | ||||||
|  |         ) | ||||||
|  |         .bind(external_calendar_id) | ||||||
|  |         .bind(cutoff_time) | ||||||
|  |         .fetch_one(self.db.pool()) | ||||||
|  |         .await?; | ||||||
|  |  | ||||||
|  |         Ok(result == 0) | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /// Clear cache for an external calendar | ||||||
|  |     pub async fn clear_cache(&self, external_calendar_id: i32) -> Result<()> { | ||||||
|  |         sqlx::query("DELETE FROM external_calendar_cache WHERE external_calendar_id = ?") | ||||||
|  |             .bind(external_calendar_id) | ||||||
|  |             .execute(self.db.pool()) | ||||||
|  |             .await?; | ||||||
|  |  | ||||||
|  |         Ok(()) | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -1,12 +0,0 @@ | |||||||
| // Re-export all handlers from the modular structure |  | ||||||
| mod auth; |  | ||||||
| mod calendar; |  | ||||||
| mod events; |  | ||||||
| mod preferences; |  | ||||||
| mod series; |  | ||||||
|  |  | ||||||
| pub use auth::{get_user_info, login, verify_token}; |  | ||||||
| pub use calendar::{create_calendar, delete_calendar}; |  | ||||||
| pub use events::{create_event, delete_event, get_calendar_events, refresh_event, update_event}; |  | ||||||
| pub use preferences::{get_preferences, logout, update_preferences}; |  | ||||||
| pub use series::{create_event_series, delete_event_series, update_event_series}; |  | ||||||
| @@ -93,6 +93,7 @@ pub async fn get_user_info( | |||||||
|             path: path.clone(), |             path: path.clone(), | ||||||
|             display_name: extract_calendar_name(path), |             display_name: extract_calendar_name(path), | ||||||
|             color: generate_calendar_color(path), |             color: generate_calendar_color(path), | ||||||
|  |             is_visible: true, // Default to visible | ||||||
|         }) |         }) | ||||||
|         .collect(); |         .collect(); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -76,10 +76,54 @@ pub async fn get_calendar_events( | |||||||
|  |  | ||||||
|     // If year and month are specified, filter events |     // If year and month are specified, filter events | ||||||
|     if let (Some(year), Some(month)) = (params.year, params.month) { |     if let (Some(year), Some(month)) = (params.year, params.month) { | ||||||
|  |         let target_date = chrono::NaiveDate::from_ymd_opt(year, month, 1).unwrap(); | ||||||
|  |         let month_start = target_date; | ||||||
|  |         let month_end = if month == 12 { | ||||||
|  |             chrono::NaiveDate::from_ymd_opt(year + 1, 1, 1).unwrap() | ||||||
|  |         } else { | ||||||
|  |             chrono::NaiveDate::from_ymd_opt(year, month + 1, 1).unwrap() | ||||||
|  |         } - chrono::Duration::days(1); | ||||||
|  |  | ||||||
|         all_events.retain(|event| { |         all_events.retain(|event| { | ||||||
|  |             let event_date = event.dtstart.date_naive(); | ||||||
|  |              | ||||||
|  |             // For non-recurring events, check if the event date is within the month | ||||||
|  |             if event.rrule.is_none() || event.rrule.as_ref().unwrap().is_empty() { | ||||||
|                 let event_year = event.dtstart.year(); |                 let event_year = event.dtstart.year(); | ||||||
|                 let event_month = event.dtstart.month(); |                 let event_month = event.dtstart.month(); | ||||||
|             event_year == year && event_month == month |                 return event_year == year && event_month == month; | ||||||
|  |             } | ||||||
|  |              | ||||||
|  |             // For recurring events, check if they could have instances in this month | ||||||
|  |             // Include if: | ||||||
|  |             // 1. The event starts before or during the requested month | ||||||
|  |             // 2. The event doesn't have an UNTIL date, OR the UNTIL date is after the month start | ||||||
|  |             if event_date > month_end { | ||||||
|  |                 // Event starts after the requested month | ||||||
|  |                 return false; | ||||||
|  |             } | ||||||
|  |              | ||||||
|  |             // Check UNTIL date in RRULE if present | ||||||
|  |             if let Some(ref rrule) = event.rrule { | ||||||
|  |                 if let Some(until_pos) = rrule.find("UNTIL=") { | ||||||
|  |                     let until_part = &rrule[until_pos + 6..]; | ||||||
|  |                     let until_end = until_part.find(';').unwrap_or(until_part.len()); | ||||||
|  |                     let until_str = &until_part[..until_end]; | ||||||
|  |                      | ||||||
|  |                     // Try to parse UNTIL date (format: YYYYMMDDTHHMMSSZ or YYYYMMDD) | ||||||
|  |                     if until_str.len() >= 8 { | ||||||
|  |                         if let Ok(until_date) = chrono::NaiveDate::parse_from_str(&until_str[..8], "%Y%m%d") { | ||||||
|  |                             if until_date < month_start { | ||||||
|  |                                 // Recurring event ended before the requested month | ||||||
|  |                                 return false; | ||||||
|  |                             } | ||||||
|  |                         } | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |              | ||||||
|  |             // Include the recurring event - the frontend will do proper expansion | ||||||
|  |             true | ||||||
|         }); |         }); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -414,9 +458,15 @@ pub async fn create_event( | |||||||
|         parse_event_datetime(&request.start_date, &request.start_time, request.all_day) |         parse_event_datetime(&request.start_date, &request.start_time, request.all_day) | ||||||
|             .map_err(|e| ApiError::BadRequest(format!("Invalid start date/time: {}", e)))?; |             .map_err(|e| ApiError::BadRequest(format!("Invalid start date/time: {}", e)))?; | ||||||
|  |  | ||||||
|     let end_datetime = parse_event_datetime(&request.end_date, &request.end_time, request.all_day) |     let mut end_datetime = parse_event_datetime(&request.end_date, &request.end_time, request.all_day) | ||||||
|         .map_err(|e| ApiError::BadRequest(format!("Invalid end date/time: {}", e)))?; |         .map_err(|e| ApiError::BadRequest(format!("Invalid end date/time: {}", e)))?; | ||||||
|  |  | ||||||
|  |     // For all-day events, add one day to end date for RFC-5545 compliance | ||||||
|  |     // RFC-5545 uses exclusive end dates for all-day events | ||||||
|  |     if request.all_day { | ||||||
|  |         end_datetime = end_datetime + chrono::Duration::days(1); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     // Validate that end is after start (allow equal times for all-day events) |     // Validate that end is after start (allow equal times for all-day events) | ||||||
|     if request.all_day { |     if request.all_day { | ||||||
|         if end_datetime < start_datetime { |         if end_datetime < start_datetime { | ||||||
| @@ -712,9 +762,15 @@ pub async fn update_event( | |||||||
|         parse_event_datetime(&request.start_date, &request.start_time, request.all_day) |         parse_event_datetime(&request.start_date, &request.start_time, request.all_day) | ||||||
|             .map_err(|e| ApiError::BadRequest(format!("Invalid start date/time: {}", e)))?; |             .map_err(|e| ApiError::BadRequest(format!("Invalid start date/time: {}", e)))?; | ||||||
|  |  | ||||||
|     let end_datetime = parse_event_datetime(&request.end_date, &request.end_time, request.all_day) |     let mut end_datetime = parse_event_datetime(&request.end_date, &request.end_time, request.all_day) | ||||||
|         .map_err(|e| ApiError::BadRequest(format!("Invalid end date/time: {}", e)))?; |         .map_err(|e| ApiError::BadRequest(format!("Invalid end date/time: {}", e)))?; | ||||||
|  |  | ||||||
|  |     // For all-day events, add one day to end date for RFC-5545 compliance | ||||||
|  |     // RFC-5545 uses exclusive end dates for all-day events | ||||||
|  |     if request.all_day { | ||||||
|  |         end_datetime = end_datetime + chrono::Duration::days(1); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     // Validate that end is after start (allow equal times for all-day events) |     // Validate that end is after start (allow equal times for all-day events) | ||||||
|     if request.all_day { |     if request.all_day { | ||||||
|         if end_datetime < start_datetime { |         if end_datetime < start_datetime { | ||||||
| @@ -789,17 +845,18 @@ fn parse_event_datetime( | |||||||
|     time_str: &str, |     time_str: &str, | ||||||
|     all_day: bool, |     all_day: bool, | ||||||
| ) -> Result<chrono::DateTime<chrono::Utc>, String> { | ) -> Result<chrono::DateTime<chrono::Utc>, String> { | ||||||
|     use chrono::{NaiveDate, NaiveDateTime, NaiveTime, TimeZone, Utc}; |     use chrono::{Local, NaiveDate, NaiveDateTime, NaiveTime, TimeZone, Utc}; | ||||||
|  |  | ||||||
|     // Parse the date |     // Parse the date | ||||||
|     let date = NaiveDate::parse_from_str(date_str, "%Y-%m-%d") |     let date = NaiveDate::parse_from_str(date_str, "%Y-%m-%d") | ||||||
|         .map_err(|_| format!("Invalid date format: {}. Expected YYYY-MM-DD", date_str))?; |         .map_err(|_| format!("Invalid date format: {}. Expected YYYY-MM-DD", date_str))?; | ||||||
|  |  | ||||||
|     if all_day { |     if all_day { | ||||||
|         // For all-day events, use midnight UTC |         // For all-day events, use noon UTC to avoid timezone boundary issues | ||||||
|  |         // This ensures the date remains correct when converted to any local timezone | ||||||
|         let datetime = date |         let datetime = date | ||||||
|             .and_hms_opt(0, 0, 0) |             .and_hms_opt(12, 0, 0) | ||||||
|             .ok_or_else(|| "Failed to create midnight datetime".to_string())?; |             .ok_or_else(|| "Failed to create noon datetime".to_string())?; | ||||||
|         Ok(Utc.from_utc_datetime(&datetime)) |         Ok(Utc.from_utc_datetime(&datetime)) | ||||||
|     } else { |     } else { | ||||||
|         // Parse the time |         // Parse the time | ||||||
| @@ -809,7 +866,11 @@ fn parse_event_datetime( | |||||||
|         // Combine date and time |         // Combine date and time | ||||||
|         let datetime = NaiveDateTime::new(date, time); |         let datetime = NaiveDateTime::new(date, time); | ||||||
|  |  | ||||||
|         // Assume local time and convert to UTC (in a real app, you'd want timezone support) |         // Treat the datetime as local time and convert to UTC | ||||||
|         Ok(Utc.from_utc_datetime(&datetime)) |         let local_datetime = Local.from_local_datetime(&datetime) | ||||||
|  |             .single() | ||||||
|  |             .ok_or_else(|| "Ambiguous local datetime".to_string())?; | ||||||
|  |          | ||||||
|  |         Ok(local_datetime.with_timezone(&Utc)) | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
							
								
								
									
										142
									
								
								backend/src/handlers/external_calendars.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										142
									
								
								backend/src/handlers/external_calendars.rs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,142 @@ | |||||||
|  | use axum::{ | ||||||
|  |     extract::{Path, State}, | ||||||
|  |     response::Json, | ||||||
|  | }; | ||||||
|  | use serde::{Deserialize, Serialize}; | ||||||
|  | use std::sync::Arc; | ||||||
|  |  | ||||||
|  | use crate::{ | ||||||
|  |     db::{ExternalCalendar, ExternalCalendarRepository}, | ||||||
|  |     models::ApiError, | ||||||
|  |     AppState, | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | use super::auth::{extract_bearer_token}; | ||||||
|  |  | ||||||
|  | #[derive(Debug, Deserialize)] | ||||||
|  | pub struct CreateExternalCalendarRequest { | ||||||
|  |     pub name: String, | ||||||
|  |     pub url: String, | ||||||
|  |     pub color: String, | ||||||
|  | } | ||||||
|  |  | ||||||
|  | #[derive(Debug, Deserialize)] | ||||||
|  | pub struct UpdateExternalCalendarRequest { | ||||||
|  |     pub name: String, | ||||||
|  |     pub url: String, | ||||||
|  |     pub color: String, | ||||||
|  |     pub is_visible: bool, | ||||||
|  | } | ||||||
|  |  | ||||||
|  | #[derive(Debug, Serialize)] | ||||||
|  | pub struct ExternalCalendarResponse { | ||||||
|  |     pub id: i32, | ||||||
|  |     pub name: String, | ||||||
|  |     pub url: String, | ||||||
|  |     pub color: String, | ||||||
|  |     pub is_visible: bool, | ||||||
|  |     pub created_at: chrono::DateTime<chrono::Utc>, | ||||||
|  |     pub updated_at: chrono::DateTime<chrono::Utc>, | ||||||
|  |     pub last_fetched: Option<chrono::DateTime<chrono::Utc>>, | ||||||
|  | } | ||||||
|  |  | ||||||
|  | impl From<ExternalCalendar> for ExternalCalendarResponse { | ||||||
|  |     fn from(calendar: ExternalCalendar) -> Self { | ||||||
|  |         Self { | ||||||
|  |             id: calendar.id, | ||||||
|  |             name: calendar.name, | ||||||
|  |             url: calendar.url, | ||||||
|  |             color: calendar.color, | ||||||
|  |             is_visible: calendar.is_visible, | ||||||
|  |             created_at: calendar.created_at, | ||||||
|  |             updated_at: calendar.updated_at, | ||||||
|  |             last_fetched: calendar.last_fetched, | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | pub async fn get_external_calendars( | ||||||
|  |     headers: axum::http::HeaderMap, | ||||||
|  |     State(app_state): State<Arc<AppState>>, | ||||||
|  | ) -> Result<Json<Vec<ExternalCalendarResponse>>, ApiError> { | ||||||
|  |     // Extract and verify token, get user | ||||||
|  |     let token = extract_bearer_token(&headers)?; | ||||||
|  |     let user = app_state.auth_service.get_user_from_token(&token).await?; | ||||||
|  |  | ||||||
|  |     let repo = ExternalCalendarRepository::new(&app_state.db); | ||||||
|  |     let calendars = repo | ||||||
|  |         .get_by_user(&user.id) | ||||||
|  |         .await | ||||||
|  |         .map_err(|e| ApiError::Database(format!("Failed to get external calendars: {}", e)))?; | ||||||
|  |  | ||||||
|  |     let response: Vec<ExternalCalendarResponse> = calendars.into_iter().map(Into::into).collect(); | ||||||
|  |     Ok(Json(response)) | ||||||
|  | } | ||||||
|  |  | ||||||
|  | pub async fn create_external_calendar( | ||||||
|  |     headers: axum::http::HeaderMap, | ||||||
|  |     State(app_state): State<Arc<AppState>>, | ||||||
|  |     Json(request): Json<CreateExternalCalendarRequest>, | ||||||
|  | ) -> Result<Json<ExternalCalendarResponse>, ApiError> { | ||||||
|  |     let token = extract_bearer_token(&headers)?; | ||||||
|  |     let user = app_state.auth_service.get_user_from_token(&token).await?; | ||||||
|  |  | ||||||
|  |     let calendar = ExternalCalendar::new( | ||||||
|  |         user.id, | ||||||
|  |         request.name, | ||||||
|  |         request.url, | ||||||
|  |         request.color, | ||||||
|  |     ); | ||||||
|  |  | ||||||
|  |     let repo = ExternalCalendarRepository::new(&app_state.db); | ||||||
|  |     let id = repo | ||||||
|  |         .create(&calendar) | ||||||
|  |         .await | ||||||
|  |         .map_err(|e| ApiError::Database(format!("Failed to create external calendar: {}", e)))?; | ||||||
|  |  | ||||||
|  |     let mut created_calendar = calendar; | ||||||
|  |     created_calendar.id = id; | ||||||
|  |  | ||||||
|  |     Ok(Json(created_calendar.into())) | ||||||
|  | } | ||||||
|  |  | ||||||
|  | pub async fn update_external_calendar( | ||||||
|  |     headers: axum::http::HeaderMap, | ||||||
|  |     State(app_state): State<Arc<AppState>>, | ||||||
|  |     Path(id): Path<i32>, | ||||||
|  |     Json(request): Json<UpdateExternalCalendarRequest>, | ||||||
|  | ) -> Result<Json<()>, ApiError> { | ||||||
|  |     let token = extract_bearer_token(&headers)?; | ||||||
|  |     let user = app_state.auth_service.get_user_from_token(&token).await?; | ||||||
|  |  | ||||||
|  |     let mut calendar = ExternalCalendar::new( | ||||||
|  |         user.id, | ||||||
|  |         request.name, | ||||||
|  |         request.url, | ||||||
|  |         request.color, | ||||||
|  |     ); | ||||||
|  |     calendar.is_visible = request.is_visible; | ||||||
|  |  | ||||||
|  |     let repo = ExternalCalendarRepository::new(&app_state.db); | ||||||
|  |     repo.update(id, &calendar) | ||||||
|  |         .await | ||||||
|  |         .map_err(|e| ApiError::Database(format!("Failed to update external calendar: {}", e)))?; | ||||||
|  |  | ||||||
|  |     Ok(Json(())) | ||||||
|  | } | ||||||
|  |  | ||||||
|  | pub async fn delete_external_calendar( | ||||||
|  |     headers: axum::http::HeaderMap, | ||||||
|  |     State(app_state): State<Arc<AppState>>, | ||||||
|  |     Path(id): Path<i32>, | ||||||
|  | ) -> Result<Json<()>, ApiError> { | ||||||
|  |     let token = extract_bearer_token(&headers)?; | ||||||
|  |     let user = app_state.auth_service.get_user_from_token(&token).await?; | ||||||
|  |  | ||||||
|  |     let repo = ExternalCalendarRepository::new(&app_state.db); | ||||||
|  |     repo.delete(id, &user.id) | ||||||
|  |         .await | ||||||
|  |         .map_err(|e| ApiError::Database(format!("Failed to delete external calendar: {}", e)))?; | ||||||
|  |  | ||||||
|  |     Ok(Json(())) | ||||||
|  | } | ||||||
							
								
								
									
										410
									
								
								backend/src/handlers/ics_fetcher.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										410
									
								
								backend/src/handlers/ics_fetcher.rs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,410 @@ | |||||||
|  | use axum::{ | ||||||
|  |     extract::{Path, State}, | ||||||
|  |     response::Json, | ||||||
|  | }; | ||||||
|  | use chrono::{DateTime, Utc}; | ||||||
|  | use ical::parser::ical::component::IcalEvent; | ||||||
|  | use reqwest::Client; | ||||||
|  | use serde::Serialize; | ||||||
|  | use std::sync::Arc; | ||||||
|  |  | ||||||
|  | use crate::{ | ||||||
|  |     db::ExternalCalendarRepository, | ||||||
|  |     models::ApiError, | ||||||
|  |     AppState, | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | // Import VEvent from calendar-models shared crate | ||||||
|  | use calendar_models::VEvent; | ||||||
|  |  | ||||||
|  | use super::auth::{extract_bearer_token}; | ||||||
|  |  | ||||||
|  | #[derive(Debug, Serialize)] | ||||||
|  | pub struct ExternalCalendarEventsResponse { | ||||||
|  |     pub events: Vec<VEvent>, | ||||||
|  |     pub last_fetched: DateTime<Utc>, | ||||||
|  | } | ||||||
|  |  | ||||||
|  | pub async fn fetch_external_calendar_events( | ||||||
|  |     headers: axum::http::HeaderMap, | ||||||
|  |     State(app_state): State<Arc<AppState>>, | ||||||
|  |     Path(id): Path<i32>, | ||||||
|  | ) -> Result<Json<ExternalCalendarEventsResponse>, ApiError> { | ||||||
|  |     let token = extract_bearer_token(&headers)?; | ||||||
|  |     let user = app_state.auth_service.get_user_from_token(&token).await?; | ||||||
|  |  | ||||||
|  |     let repo = ExternalCalendarRepository::new(&app_state.db); | ||||||
|  |      | ||||||
|  |     // Get user's external calendars to verify ownership and get URL | ||||||
|  |     let calendars = repo | ||||||
|  |         .get_by_user(&user.id) | ||||||
|  |         .await | ||||||
|  |         .map_err(|e| ApiError::Database(format!("Failed to get external calendars: {}", e)))?; | ||||||
|  |  | ||||||
|  |     let calendar = calendars | ||||||
|  |         .into_iter() | ||||||
|  |         .find(|c| c.id == id) | ||||||
|  |         .ok_or_else(|| ApiError::NotFound("External calendar not found".to_string()))?; | ||||||
|  |  | ||||||
|  |     if !calendar.is_visible { | ||||||
|  |         return Ok(Json(ExternalCalendarEventsResponse { | ||||||
|  |             events: vec![], | ||||||
|  |             last_fetched: Utc::now(), | ||||||
|  |         })); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     // Check cache first | ||||||
|  |     let cache_max_age_minutes = 5; | ||||||
|  |     let mut ics_content = String::new(); | ||||||
|  |     let mut last_fetched = Utc::now(); | ||||||
|  |     let mut fetched_from_cache = false; | ||||||
|  |  | ||||||
|  |     // Try to get from cache if not stale | ||||||
|  |     match repo.is_cache_stale(id, cache_max_age_minutes).await { | ||||||
|  |         Ok(is_stale) => { | ||||||
|  |             if !is_stale { | ||||||
|  |                 // Cache is fresh, use it | ||||||
|  |                 if let Ok(Some((cached_data, cached_at))) = repo.get_cached_data(id).await { | ||||||
|  |                     ics_content = cached_data; | ||||||
|  |                     last_fetched = cached_at; | ||||||
|  |                     fetched_from_cache = true; | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         Err(_) => { | ||||||
|  |             // If cache check fails, proceed to fetch from URL | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     // If not fetched from cache, get from external URL | ||||||
|  |     if !fetched_from_cache { | ||||||
|  |         let client = Client::new(); | ||||||
|  |         let response = client | ||||||
|  |             .get(&calendar.url) | ||||||
|  |             .send() | ||||||
|  |             .await | ||||||
|  |             .map_err(|e| ApiError::Internal(format!("Failed to fetch calendar: {}", e)))?; | ||||||
|  |  | ||||||
|  |         if !response.status().is_success() { | ||||||
|  |             return Err(ApiError::Internal(format!("Calendar server returned: {}", response.status()))); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         ics_content = response | ||||||
|  |             .text() | ||||||
|  |             .await | ||||||
|  |             .map_err(|e| ApiError::Internal(format!("Failed to read calendar content: {}", e)))?; | ||||||
|  |  | ||||||
|  |         // Store in cache for future requests | ||||||
|  |         let etag = None; // TODO: Extract ETag from response headers if available | ||||||
|  |         if let Err(_) = repo.update_cache(id, &ics_content, etag).await { | ||||||
|  |             // Log error but don't fail the request | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         // Update last_fetched timestamp | ||||||
|  |         if let Err(_) = repo.update_last_fetched(id, &user.id).await { | ||||||
|  |         } | ||||||
|  |          | ||||||
|  |         last_fetched = Utc::now(); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     // Parse ICS content | ||||||
|  |     let events = parse_ics_content(&ics_content) | ||||||
|  |         .map_err(|e| ApiError::BadRequest(format!("Failed to parse calendar: {}", e)))?; | ||||||
|  |  | ||||||
|  |     Ok(Json(ExternalCalendarEventsResponse { | ||||||
|  |         events, | ||||||
|  |         last_fetched, | ||||||
|  |     })) | ||||||
|  | } | ||||||
|  |  | ||||||
|  | fn parse_ics_content(ics_content: &str) -> Result<Vec<VEvent>, Box<dyn std::error::Error>> { | ||||||
|  |     let reader = ical::IcalParser::new(ics_content.as_bytes()); | ||||||
|  |     let mut events = Vec::new(); | ||||||
|  |     let mut _total_components = 0; | ||||||
|  |     let mut _failed_conversions = 0; | ||||||
|  |  | ||||||
|  |     for calendar in reader { | ||||||
|  |         let calendar = calendar?; | ||||||
|  |         for component in calendar.events { | ||||||
|  |             _total_components += 1; | ||||||
|  |             match convert_ical_to_vevent(component) { | ||||||
|  |                 Ok(vevent) => { | ||||||
|  |                     events.push(vevent); | ||||||
|  |                 } | ||||||
|  |                 Err(_) => { | ||||||
|  |                     _failed_conversions += 1; | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |     Ok(events) | ||||||
|  | } | ||||||
|  |  | ||||||
|  | fn convert_ical_to_vevent(ical_event: IcalEvent) -> Result<VEvent, Box<dyn std::error::Error>> { | ||||||
|  |     use uuid::Uuid; | ||||||
|  |  | ||||||
|  |     let mut summary = None; | ||||||
|  |     let mut description = None; | ||||||
|  |     let mut location = None; | ||||||
|  |     let mut dtstart = None; | ||||||
|  |     let mut dtend = None; | ||||||
|  |     let mut uid = None; | ||||||
|  |     let mut all_day = false; | ||||||
|  |     let mut rrule = None; | ||||||
|  |  | ||||||
|  |  | ||||||
|  |     // Extract properties | ||||||
|  |     for property in ical_event.properties { | ||||||
|  |         match property.name.as_str() { | ||||||
|  |             "SUMMARY" => { | ||||||
|  |                 summary = property.value; | ||||||
|  |             } | ||||||
|  |             "DESCRIPTION" => { | ||||||
|  |                 description = property.value; | ||||||
|  |             } | ||||||
|  |             "LOCATION" => { | ||||||
|  |                 location = property.value; | ||||||
|  |             } | ||||||
|  |             "DTSTART" => { | ||||||
|  |                 if let Some(value) = property.value { | ||||||
|  |                     // Check if it's a date-only value (all-day event) | ||||||
|  |                     if value.len() == 8 && !value.contains('T') { | ||||||
|  |                         all_day = true; | ||||||
|  |                         // Parse YYYYMMDD format | ||||||
|  |                         if let Ok(date) = chrono::NaiveDate::parse_from_str(&value, "%Y%m%d") { | ||||||
|  |                             dtstart = Some(chrono::TimeZone::from_utc_datetime(&Utc, &date.and_hms_opt(12, 0, 0).unwrap())); | ||||||
|  |                         } | ||||||
|  |                     } else { | ||||||
|  |                         // Extract timezone info from parameters | ||||||
|  |                         let tzid = property.params.as_ref() | ||||||
|  |                             .and_then(|params| params.iter().find(|(k, _)| k == "TZID")) | ||||||
|  |                             .and_then(|(_, v)| v.first().cloned()); | ||||||
|  |                          | ||||||
|  |                         // Parse datetime with timezone information | ||||||
|  |                         if let Some(dt) = parse_datetime_with_tz(&value, tzid.as_deref()) { | ||||||
|  |                             dtstart = Some(dt); | ||||||
|  |                         } | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |             "DTEND" => { | ||||||
|  |                 if let Some(value) = property.value { | ||||||
|  |                     if all_day && value.len() == 8 && !value.contains('T') { | ||||||
|  |                         // For all-day events, DTEND is exclusive so use the date as-is at noon | ||||||
|  |                         if let Ok(date) = chrono::NaiveDate::parse_from_str(&value, "%Y%m%d") { | ||||||
|  |                             dtend = Some(chrono::TimeZone::from_utc_datetime(&Utc, &date.and_hms_opt(12, 0, 0).unwrap())); | ||||||
|  |                         } | ||||||
|  |                     } else { | ||||||
|  |                         // Extract timezone info from parameters | ||||||
|  |                         let tzid = property.params.as_ref() | ||||||
|  |                             .and_then(|params| params.iter().find(|(k, _)| k == "TZID")) | ||||||
|  |                             .and_then(|(_, v)| v.first().cloned()); | ||||||
|  |                          | ||||||
|  |                         // Parse datetime with timezone information | ||||||
|  |                         if let Some(dt) = parse_datetime_with_tz(&value, tzid.as_deref()) { | ||||||
|  |                             dtend = Some(dt); | ||||||
|  |                         } | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |             "UID" => { | ||||||
|  |                 uid = property.value; | ||||||
|  |             } | ||||||
|  |             "RRULE" => { | ||||||
|  |                 rrule = property.value; | ||||||
|  |             } | ||||||
|  |             _ => {} // Ignore other properties for now | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |     let dtstart = dtstart.ok_or("Missing DTSTART")?; | ||||||
|  |  | ||||||
|  |     let vevent = VEvent { | ||||||
|  |         uid: uid.unwrap_or_else(|| Uuid::new_v4().to_string()), | ||||||
|  |         dtstart, | ||||||
|  |         dtend, | ||||||
|  |         summary, | ||||||
|  |         description, | ||||||
|  |         location, | ||||||
|  |         all_day, | ||||||
|  |         rrule, | ||||||
|  |         exdate: Vec::new(), // External calendars don't need exception handling | ||||||
|  |         recurrence_id: None, | ||||||
|  |         created: None, | ||||||
|  |         last_modified: None, | ||||||
|  |         dtstamp: Utc::now(), | ||||||
|  |         sequence: Some(0), | ||||||
|  |         status: None, | ||||||
|  |         transp: None, | ||||||
|  |         organizer: None, | ||||||
|  |         attendees: Vec::new(), | ||||||
|  |         url: None, | ||||||
|  |         attachments: Vec::new(), | ||||||
|  |         categories: Vec::new(), | ||||||
|  |         priority: None, | ||||||
|  |         resources: Vec::new(), | ||||||
|  |         related_to: None, | ||||||
|  |         geo: None, | ||||||
|  |         duration: None, | ||||||
|  |         class: None, | ||||||
|  |         contact: None, | ||||||
|  |         comment: None, | ||||||
|  |         rdate: Vec::new(), | ||||||
|  |         alarms: Vec::new(), | ||||||
|  |         etag: None, | ||||||
|  |         href: None, | ||||||
|  |         calendar_path: None, | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     Ok(vevent) | ||||||
|  | } | ||||||
|  |  | ||||||
|  | fn parse_datetime_with_tz(datetime_str: &str, tzid: Option<&str>) -> Option<DateTime<Utc>> { | ||||||
|  |     use chrono::TimeZone; | ||||||
|  |     use chrono_tz::Tz; | ||||||
|  |      | ||||||
|  |      | ||||||
|  |     // Try various datetime formats commonly found in ICS files | ||||||
|  |      | ||||||
|  |     // Format: 20231201T103000Z (UTC) - handle as naive datetime first | ||||||
|  |     if datetime_str.ends_with('Z') { | ||||||
|  |         let datetime_without_z = &datetime_str[..datetime_str.len()-1]; | ||||||
|  |         if let Ok(naive_dt) = chrono::NaiveDateTime::parse_from_str(datetime_without_z, "%Y%m%dT%H%M%S") { | ||||||
|  |             return Some(naive_dt.and_utc()); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     // Format: 20231201T103000-0500 (with timezone offset) | ||||||
|  |     if let Ok(dt) = DateTime::parse_from_str(datetime_str, "%Y%m%dT%H%M%S%z") { | ||||||
|  |         return Some(dt.with_timezone(&Utc)); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     // Format: 2023-12-01T10:30:00Z (ISO format) | ||||||
|  |     if let Ok(dt) = DateTime::parse_from_str(datetime_str, "%Y-%m-%dT%H:%M:%SZ") { | ||||||
|  |         return Some(dt.with_timezone(&Utc)); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     // Handle naive datetime with timezone parameter | ||||||
|  |     let naive_dt = if let Ok(dt) = chrono::NaiveDateTime::parse_from_str(datetime_str, "%Y%m%dT%H%M%S") { | ||||||
|  |         Some(dt) | ||||||
|  |     } else if let Ok(dt) = chrono::NaiveDateTime::parse_from_str(datetime_str, "%Y-%m-%dT%H:%M:%S") { | ||||||
|  |         Some(dt) | ||||||
|  |     } else { | ||||||
|  |         None | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     if let Some(naive_dt) = naive_dt { | ||||||
|  |         // If TZID is provided, try to parse it | ||||||
|  |         if let Some(tzid_str) = tzid { | ||||||
|  |             // Handle common timezone formats | ||||||
|  |             let tz_result = if tzid_str.starts_with("/mozilla.org/") { | ||||||
|  |                 // Mozilla/Thunderbird format: /mozilla.org/20070129_1/Europe/London | ||||||
|  |                 tzid_str.split('/').last().and_then(|tz_name| tz_name.parse::<Tz>().ok()) | ||||||
|  |             } else if tzid_str.contains('/') { | ||||||
|  |                 // Standard timezone format: America/New_York, Europe/London | ||||||
|  |                 tzid_str.parse::<Tz>().ok() | ||||||
|  |             } else { | ||||||
|  |                 // Try common abbreviations and Windows timezone names | ||||||
|  |                 match tzid_str { | ||||||
|  |                     // Standard abbreviations | ||||||
|  |                     "EST" => Some(Tz::America__New_York), | ||||||
|  |                     "PST" => Some(Tz::America__Los_Angeles), | ||||||
|  |                     "MST" => Some(Tz::America__Denver),  | ||||||
|  |                     "CST" => Some(Tz::America__Chicago), | ||||||
|  |                      | ||||||
|  |                     // North America - Windows timezone names to IANA mapping | ||||||
|  |                     "Mountain Standard Time" => Some(Tz::America__Denver), | ||||||
|  |                     "Eastern Standard Time" => Some(Tz::America__New_York), | ||||||
|  |                     "Central Standard Time" => Some(Tz::America__Chicago), | ||||||
|  |                     "Pacific Standard Time" => Some(Tz::America__Los_Angeles), | ||||||
|  |                     "Mountain Daylight Time" => Some(Tz::America__Denver), | ||||||
|  |                     "Eastern Daylight Time" => Some(Tz::America__New_York), | ||||||
|  |                     "Central Daylight Time" => Some(Tz::America__Chicago), | ||||||
|  |                     "Pacific Daylight Time" => Some(Tz::America__Los_Angeles), | ||||||
|  |                     "Hawaiian Standard Time" => Some(Tz::Pacific__Honolulu), | ||||||
|  |                     "Alaskan Standard Time" => Some(Tz::America__Anchorage), | ||||||
|  |                     "Alaskan Daylight Time" => Some(Tz::America__Anchorage), | ||||||
|  |                     "Atlantic Standard Time" => Some(Tz::America__Halifax), | ||||||
|  |                     "Newfoundland Standard Time" => Some(Tz::America__St_Johns), | ||||||
|  |                      | ||||||
|  |                     // Europe | ||||||
|  |                     "GMT Standard Time" => Some(Tz::Europe__London), | ||||||
|  |                     "Greenwich Standard Time" => Some(Tz::UTC), | ||||||
|  |                     "W. Europe Standard Time" => Some(Tz::Europe__Berlin), | ||||||
|  |                     "Central Europe Standard Time" => Some(Tz::Europe__Warsaw), | ||||||
|  |                     "Romance Standard Time" => Some(Tz::Europe__Paris), | ||||||
|  |                     "Central European Standard Time" => Some(Tz::Europe__Belgrade), | ||||||
|  |                     "E. Europe Standard Time" => Some(Tz::Europe__Bucharest), | ||||||
|  |                     "FLE Standard Time" => Some(Tz::Europe__Helsinki), | ||||||
|  |                     "GTB Standard Time" => Some(Tz::Europe__Athens), | ||||||
|  |                     "Russian Standard Time" => Some(Tz::Europe__Moscow), | ||||||
|  |                     "Turkey Standard Time" => Some(Tz::Europe__Istanbul), | ||||||
|  |                      | ||||||
|  |                     // Asia | ||||||
|  |                     "China Standard Time" => Some(Tz::Asia__Shanghai), | ||||||
|  |                     "Tokyo Standard Time" => Some(Tz::Asia__Tokyo), | ||||||
|  |                     "Korea Standard Time" => Some(Tz::Asia__Seoul), | ||||||
|  |                     "Singapore Standard Time" => Some(Tz::Asia__Singapore), | ||||||
|  |                     "India Standard Time" => Some(Tz::Asia__Kolkata), | ||||||
|  |                     "Pakistan Standard Time" => Some(Tz::Asia__Karachi), | ||||||
|  |                     "Bangladesh Standard Time" => Some(Tz::Asia__Dhaka), | ||||||
|  |                     "Thailand Standard Time" => Some(Tz::Asia__Bangkok), | ||||||
|  |                     "SE Asia Standard Time" => Some(Tz::Asia__Bangkok), | ||||||
|  |                     "Myanmar Standard Time" => Some(Tz::Asia__Yangon), | ||||||
|  |                     "Sri Lanka Standard Time" => Some(Tz::Asia__Colombo), | ||||||
|  |                     "Nepal Standard Time" => Some(Tz::Asia__Kathmandu), | ||||||
|  |                     "Central Asia Standard Time" => Some(Tz::Asia__Almaty), | ||||||
|  |                     "West Asia Standard Time" => Some(Tz::Asia__Tashkent), | ||||||
|  |                     "Afghanistan Standard Time" => Some(Tz::Asia__Kabul), | ||||||
|  |                     "Iran Standard Time" => Some(Tz::Asia__Tehran), | ||||||
|  |                     "Arabian Standard Time" => Some(Tz::Asia__Dubai), | ||||||
|  |                     "Arab Standard Time" => Some(Tz::Asia__Riyadh), | ||||||
|  |                     "Israel Standard Time" => Some(Tz::Asia__Jerusalem), | ||||||
|  |                     "Jordan Standard Time" => Some(Tz::Asia__Amman), | ||||||
|  |                     "Syria Standard Time" => Some(Tz::Asia__Damascus), | ||||||
|  |                     "Middle East Standard Time" => Some(Tz::Asia__Beirut), | ||||||
|  |                     "Egypt Standard Time" => Some(Tz::Africa__Cairo), | ||||||
|  |                     "South Africa Standard Time" => Some(Tz::Africa__Johannesburg), | ||||||
|  |                     "E. Africa Standard Time" => Some(Tz::Africa__Nairobi), | ||||||
|  |                     "W. Central Africa Standard Time" => Some(Tz::Africa__Lagos), | ||||||
|  |                      | ||||||
|  |                     // Asia Pacific | ||||||
|  |                     "AUS Eastern Standard Time" => Some(Tz::Australia__Sydney), | ||||||
|  |                     "AUS Central Standard Time" => Some(Tz::Australia__Darwin), | ||||||
|  |                     "W. Australia Standard Time" => Some(Tz::Australia__Perth), | ||||||
|  |                     "Tasmania Standard Time" => Some(Tz::Australia__Hobart), | ||||||
|  |                     "New Zealand Standard Time" => Some(Tz::Pacific__Auckland), | ||||||
|  |                     "Fiji Standard Time" => Some(Tz::Pacific__Fiji), | ||||||
|  |                     "Tonga Standard Time" => Some(Tz::Pacific__Tongatapu), | ||||||
|  |                      | ||||||
|  |                     // South America | ||||||
|  |                     "Argentina Standard Time" => Some(Tz::America__Buenos_Aires), | ||||||
|  |                     "E. South America Standard Time" => Some(Tz::America__Sao_Paulo), | ||||||
|  |                     "SA Eastern Standard Time" => Some(Tz::America__Cayenne), | ||||||
|  |                     "SA Pacific Standard Time" => Some(Tz::America__Bogota), | ||||||
|  |                     "SA Western Standard Time" => Some(Tz::America__La_Paz), | ||||||
|  |                     "Pacific SA Standard Time" => Some(Tz::America__Santiago), | ||||||
|  |                     "Venezuela Standard Time" => Some(Tz::America__Caracas), | ||||||
|  |                     "Montevideo Standard Time" => Some(Tz::America__Montevideo), | ||||||
|  |                      | ||||||
|  |                     // Try parsing as IANA name | ||||||
|  |                     _ => tzid_str.parse::<Tz>().ok() | ||||||
|  |                 } | ||||||
|  |             }; | ||||||
|  |  | ||||||
|  |             if let Some(tz) = tz_result { | ||||||
|  |                 if let Some(dt_with_tz) = tz.from_local_datetime(&naive_dt).single() { | ||||||
|  |                     return Some(dt_with_tz.with_timezone(&Utc)); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |          | ||||||
|  |         // If no timezone info or parsing failed, treat as UTC (safer than local time assumptions) | ||||||
|  |         return Some(chrono::TimeZone::from_utc_datetime(&Utc, &naive_dt)); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     None | ||||||
|  | } | ||||||
							
								
								
									
										15
									
								
								backend/src/handlers/mod.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								backend/src/handlers/mod.rs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,15 @@ | |||||||
|  | pub mod auth; | ||||||
|  | pub mod calendar; | ||||||
|  | pub mod events; | ||||||
|  | pub mod external_calendars; | ||||||
|  | pub mod ics_fetcher; | ||||||
|  | pub mod preferences; | ||||||
|  | pub mod series; | ||||||
|  |  | ||||||
|  | pub use auth::*; | ||||||
|  | pub use calendar::*; | ||||||
|  | pub use events::*; | ||||||
|  | pub use external_calendars::*; | ||||||
|  | pub use ics_fetcher::*; | ||||||
|  | pub use preferences::*; | ||||||
|  | pub use series::*; | ||||||
| @@ -40,6 +40,7 @@ pub async fn get_preferences( | |||||||
|         calendar_theme: preferences.calendar_theme, |         calendar_theme: preferences.calendar_theme, | ||||||
|         calendar_style: preferences.calendar_style, |         calendar_style: preferences.calendar_style, | ||||||
|         calendar_colors: preferences.calendar_colors, |         calendar_colors: preferences.calendar_colors, | ||||||
|  |         last_used_calendar: preferences.last_used_calendar, | ||||||
|     })) |     })) | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -85,6 +86,9 @@ pub async fn update_preferences( | |||||||
|     if request.calendar_colors.is_some() { |     if request.calendar_colors.is_some() { | ||||||
|         preferences.calendar_colors = request.calendar_colors; |         preferences.calendar_colors = request.calendar_colors; | ||||||
|     } |     } | ||||||
|  |     if request.last_used_calendar.is_some() { | ||||||
|  |         preferences.last_used_calendar = request.last_used_calendar; | ||||||
|  |     } | ||||||
|  |  | ||||||
|     prefs_repo |     prefs_repo | ||||||
|         .update(&preferences) |         .update(&preferences) | ||||||
| @@ -100,6 +104,7 @@ pub async fn update_preferences( | |||||||
|             calendar_theme: preferences.calendar_theme, |             calendar_theme: preferences.calendar_theme, | ||||||
|             calendar_style: preferences.calendar_style, |             calendar_style: preferences.calendar_style, | ||||||
|             calendar_colors: preferences.calendar_colors, |             calendar_colors: preferences.calendar_colors, | ||||||
|  |             last_used_calendar: preferences.last_used_calendar, | ||||||
|         }), |         }), | ||||||
|     )) |     )) | ||||||
| } | } | ||||||
|   | |||||||
| @@ -130,9 +130,17 @@ pub async fn create_event_series( | |||||||
|             .and_hms_opt(23, 59, 59) |             .and_hms_opt(23, 59, 59) | ||||||
|             .ok_or_else(|| ApiError::BadRequest("Invalid end date".to_string()))?; |             .ok_or_else(|| ApiError::BadRequest("Invalid end date".to_string()))?; | ||||||
|  |  | ||||||
|  |         // Convert from local time to UTC | ||||||
|  |         let start_local = chrono::Local.from_local_datetime(&start_dt) | ||||||
|  |             .single() | ||||||
|  |             .ok_or_else(|| ApiError::BadRequest("Ambiguous start datetime".to_string()))?; | ||||||
|  |         let end_local = chrono::Local.from_local_datetime(&end_dt) | ||||||
|  |             .single() | ||||||
|  |             .ok_or_else(|| ApiError::BadRequest("Ambiguous end datetime".to_string()))?; | ||||||
|  |          | ||||||
|         ( |         ( | ||||||
|             chrono::Utc.from_utc_datetime(&start_dt), |             start_local.with_timezone(&chrono::Utc), | ||||||
|             chrono::Utc.from_utc_datetime(&end_dt), |             end_local.with_timezone(&chrono::Utc), | ||||||
|         ) |         ) | ||||||
|     } else { |     } else { | ||||||
|         // Parse times for timed events |         // Parse times for timed events | ||||||
| @@ -163,9 +171,17 @@ pub async fn create_event_series( | |||||||
|             start_date.and_time(end_time) |             start_date.and_time(end_time) | ||||||
|         }; |         }; | ||||||
|  |  | ||||||
|  |         // Convert from local time to UTC | ||||||
|  |         let start_local = chrono::Local.from_local_datetime(&start_dt) | ||||||
|  |             .single() | ||||||
|  |             .ok_or_else(|| ApiError::BadRequest("Ambiguous start datetime".to_string()))?; | ||||||
|  |         let end_local = chrono::Local.from_local_datetime(&end_dt) | ||||||
|  |             .single() | ||||||
|  |             .ok_or_else(|| ApiError::BadRequest("Ambiguous end datetime".to_string()))?; | ||||||
|  |          | ||||||
|         ( |         ( | ||||||
|             chrono::Utc.from_utc_datetime(&start_dt), |             start_local.with_timezone(&chrono::Utc), | ||||||
|             chrono::Utc.from_utc_datetime(&end_dt), |             end_local.with_timezone(&chrono::Utc), | ||||||
|         ) |         ) | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
| @@ -175,6 +191,7 @@ pub async fn create_event_series( | |||||||
|     // Create the VEvent for the series |     // Create the VEvent for the series | ||||||
|     let mut event = VEvent::new(uid.clone(), start_datetime); |     let mut event = VEvent::new(uid.clone(), start_datetime); | ||||||
|     event.dtend = Some(end_datetime); |     event.dtend = Some(end_datetime); | ||||||
|  |     event.all_day = request.all_day; // Set the all_day flag properly | ||||||
|     event.summary = if request.title.trim().is_empty() { |     event.summary = if request.title.trim().is_empty() { | ||||||
|         None |         None | ||||||
|     } else { |     } else { | ||||||
| @@ -245,8 +262,8 @@ pub async fn update_event_series( | |||||||
|     Json(request): Json<UpdateEventSeriesRequest>, |     Json(request): Json<UpdateEventSeriesRequest>, | ||||||
| ) -> Result<Json<UpdateEventSeriesResponse>, ApiError> { | ) -> Result<Json<UpdateEventSeriesResponse>, ApiError> { | ||||||
|     println!( |     println!( | ||||||
|         "🔄 Update event series request received: series_uid='{}', update_scope='{}'", |         "🔄 Update event series request received: series_uid='{}', update_scope='{}', recurrence_count={:?}, recurrence_end_date={:?}", | ||||||
|         request.series_uid, request.update_scope |         request.series_uid, request.update_scope, request.recurrence_count, request.recurrence_end_date | ||||||
|     ); |     ); | ||||||
|  |  | ||||||
|     // Extract and verify token |     // Extract and verify token | ||||||
| @@ -380,8 +397,9 @@ pub async fn update_event_series( | |||||||
|     }; |     }; | ||||||
|  |  | ||||||
|     let (start_datetime, end_datetime) = if request.all_day { |     let (start_datetime, end_datetime) = if request.all_day { | ||||||
|  |         // For all-day events, use noon UTC to avoid timezone boundary issues | ||||||
|         let start_dt = start_date |         let start_dt = start_date | ||||||
|             .and_hms_opt(0, 0, 0) |             .and_hms_opt(12, 0, 0) | ||||||
|             .ok_or_else(|| ApiError::BadRequest("Invalid start date".to_string()))?; |             .ok_or_else(|| ApiError::BadRequest("Invalid start date".to_string()))?; | ||||||
|  |  | ||||||
|         // For all-day events, also preserve the original date pattern |         // For all-day events, also preserve the original date pattern | ||||||
| @@ -397,9 +415,10 @@ pub async fn update_event_series( | |||||||
|         }; |         }; | ||||||
|  |  | ||||||
|         let end_dt = end_date |         let end_dt = end_date | ||||||
|             .and_hms_opt(23, 59, 59) |             .and_hms_opt(12, 0, 0) | ||||||
|             .ok_or_else(|| ApiError::BadRequest("Invalid end date".to_string()))?; |             .ok_or_else(|| ApiError::BadRequest("Invalid end date".to_string()))?; | ||||||
|  |  | ||||||
|  |         // For all-day events, use UTC directly (no local conversion needed) | ||||||
|         ( |         ( | ||||||
|             chrono::Utc.from_utc_datetime(&start_dt), |             chrono::Utc.from_utc_datetime(&start_dt), | ||||||
|             chrono::Utc.from_utc_datetime(&end_dt), |             chrono::Utc.from_utc_datetime(&end_dt), | ||||||
| @@ -437,9 +456,17 @@ pub async fn update_event_series( | |||||||
|             (chrono::Utc.from_utc_datetime(&start_dt) + original_duration).naive_utc() |             (chrono::Utc.from_utc_datetime(&start_dt) + original_duration).naive_utc() | ||||||
|         }; |         }; | ||||||
|  |  | ||||||
|  |         // Convert from local time to UTC | ||||||
|  |         let start_local = chrono::Local.from_local_datetime(&start_dt) | ||||||
|  |             .single() | ||||||
|  |             .ok_or_else(|| ApiError::BadRequest("Ambiguous start datetime".to_string()))?; | ||||||
|  |         let end_local = chrono::Local.from_local_datetime(&end_dt) | ||||||
|  |             .single() | ||||||
|  |             .ok_or_else(|| ApiError::BadRequest("Ambiguous end datetime".to_string()))?; | ||||||
|  |          | ||||||
|         ( |         ( | ||||||
|             chrono::Utc.from_utc_datetime(&start_dt), |             start_local.with_timezone(&chrono::Utc), | ||||||
|             chrono::Utc.from_utc_datetime(&end_dt), |             end_local.with_timezone(&chrono::Utc), | ||||||
|         ) |         ) | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
| @@ -732,9 +759,36 @@ fn update_entire_series( | |||||||
|     updated_event.last_modified = Some(now); |     updated_event.last_modified = Some(now); | ||||||
|     // Keep original created timestamp to preserve event history |     // Keep original created timestamp to preserve event history | ||||||
|  |  | ||||||
|     // For simple updates (like drag operations), preserve the existing RRULE |     // Update RRULE if recurrence parameters are provided | ||||||
|     // For more complex updates, we might need to regenerate it, but for now keep it simple |     if let Some(ref existing_rrule) = updated_event.rrule { | ||||||
|     // updated_event.rrule remains unchanged from the clone |         let mut new_rrule = existing_rrule.clone(); | ||||||
|  |         println!("🔄 Original RRULE: {}", existing_rrule); | ||||||
|  |          | ||||||
|  |         // Update COUNT if provided | ||||||
|  |         if let Some(count) = request.recurrence_count { | ||||||
|  |             println!("🔄 Updating RRULE with new COUNT: {}", count); | ||||||
|  |             // Remove old COUNT or UNTIL parameters | ||||||
|  |             new_rrule = new_rrule.split(';') | ||||||
|  |                 .filter(|part| !part.starts_with("COUNT=") && !part.starts_with("UNTIL=")) | ||||||
|  |                 .collect::<Vec<_>>() | ||||||
|  |                 .join(";"); | ||||||
|  |             // Add new COUNT | ||||||
|  |             new_rrule = format!("{};COUNT={}", new_rrule, count); | ||||||
|  |         } else if let Some(ref end_date) = request.recurrence_end_date { | ||||||
|  |             println!("🔄 Updating RRULE with new UNTIL: {}", end_date); | ||||||
|  |             // Remove old COUNT or UNTIL parameters | ||||||
|  |             new_rrule = new_rrule.split(';') | ||||||
|  |                 .filter(|part| !part.starts_with("COUNT=") && !part.starts_with("UNTIL=")) | ||||||
|  |                 .collect::<Vec<_>>() | ||||||
|  |                 .join(";"); | ||||||
|  |             // Add new UNTIL (convert YYYY-MM-DD to YYYYMMDD format) | ||||||
|  |             let until_date = end_date.replace("-", ""); | ||||||
|  |             new_rrule = format!("{};UNTIL={}", new_rrule, until_date); | ||||||
|  |         } | ||||||
|  |          | ||||||
|  |         println!("🔄 Updated RRULE: {}", new_rrule); | ||||||
|  |         updated_event.rrule = Some(new_rrule); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     // Copy the updated event back to existing_event for the main handler |     // Copy the updated event back to existing_event for the main handler | ||||||
|     *existing_event = updated_event.clone(); |     *existing_event = updated_event.clone(); | ||||||
|   | |||||||
| @@ -1,6 +1,6 @@ | |||||||
| use axum::{ | use axum::{ | ||||||
|     response::Json, |     response::Json, | ||||||
|     routing::{get, post}, |     routing::{delete, get, post}, | ||||||
|     Router, |     Router, | ||||||
| }; | }; | ||||||
| use std::sync::Arc; | use std::sync::Arc; | ||||||
| @@ -72,6 +72,12 @@ pub async fn run_server() -> Result<(), Box<dyn std::error::Error>> { | |||||||
|         .route("/api/preferences", get(handlers::get_preferences)) |         .route("/api/preferences", get(handlers::get_preferences)) | ||||||
|         .route("/api/preferences", post(handlers::update_preferences)) |         .route("/api/preferences", post(handlers::update_preferences)) | ||||||
|         .route("/api/auth/logout", post(handlers::logout)) |         .route("/api/auth/logout", post(handlers::logout)) | ||||||
|  |         // External calendars endpoints | ||||||
|  |         .route("/api/external-calendars", get(handlers::get_external_calendars)) | ||||||
|  |         .route("/api/external-calendars", post(handlers::create_external_calendar)) | ||||||
|  |         .route("/api/external-calendars/:id", post(handlers::update_external_calendar)) | ||||||
|  |         .route("/api/external-calendars/:id", delete(handlers::delete_external_calendar)) | ||||||
|  |         .route("/api/external-calendars/:id/events", get(handlers::fetch_external_calendar_events)) | ||||||
|         .layer( |         .layer( | ||||||
|             CorsLayer::new() |             CorsLayer::new() | ||||||
|                 .allow_origin(Any) |                 .allow_origin(Any) | ||||||
|   | |||||||
| @@ -30,6 +30,7 @@ pub struct UserPreferencesResponse { | |||||||
|     pub calendar_theme: Option<String>, |     pub calendar_theme: Option<String>, | ||||||
|     pub calendar_style: Option<String>, |     pub calendar_style: Option<String>, | ||||||
|     pub calendar_colors: Option<String>, |     pub calendar_colors: Option<String>, | ||||||
|  |     pub last_used_calendar: Option<String>, | ||||||
| } | } | ||||||
|  |  | ||||||
| #[derive(Debug, Deserialize)] | #[derive(Debug, Deserialize)] | ||||||
| @@ -40,6 +41,7 @@ pub struct UpdatePreferencesRequest { | |||||||
|     pub calendar_theme: Option<String>, |     pub calendar_theme: Option<String>, | ||||||
|     pub calendar_style: Option<String>, |     pub calendar_style: Option<String>, | ||||||
|     pub calendar_colors: Option<String>, |     pub calendar_colors: Option<String>, | ||||||
|  |     pub last_used_calendar: Option<String>, | ||||||
| } | } | ||||||
|  |  | ||||||
| #[derive(Debug, Serialize)] | #[derive(Debug, Serialize)] | ||||||
| @@ -54,6 +56,7 @@ pub struct CalendarInfo { | |||||||
|     pub path: String, |     pub path: String, | ||||||
|     pub display_name: String, |     pub display_name: String, | ||||||
|     pub color: String, |     pub color: String, | ||||||
|  |     pub is_visible: bool, | ||||||
| } | } | ||||||
|  |  | ||||||
| #[derive(Debug, Deserialize)] | #[derive(Debug, Deserialize)] | ||||||
|   | |||||||
							
								
								
									
										
											BIN
										
									
								
								calendar.db
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								calendar.db
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							| @@ -1,10 +1,11 @@ | |||||||
| services: | services: | ||||||
|   calendar-backend: |   calendar-backend: | ||||||
|     build: . |     build: | ||||||
|  |       context: . | ||||||
|  |       dockerfile: ./backend/Dockerfile | ||||||
|     ports: |     ports: | ||||||
|       - "3000:3000" |       - "3000:3000" | ||||||
|     volumes: |     volumes: | ||||||
|       - ./data/site_dist:/srv/www |  | ||||||
|       - ./data/db:/db |       - ./data/db:/db | ||||||
|  |  | ||||||
|   calendar-frontend: |   calendar-frontend: | ||||||
| @@ -15,7 +16,7 @@ services: | |||||||
|       - "80:80" |       - "80:80" | ||||||
|       - "443:443" |       - "443:443" | ||||||
|     volumes: |     volumes: | ||||||
|       - ./data/site_dist:/srv/www:ro |       - ./frontend/dist:/srv/www:ro | ||||||
|       - ./Caddyfile:/etc/caddy/Caddyfile:ro |       - ./Caddyfile:/etc/caddy/Caddyfile:ro | ||||||
|       - ./data/caddy/data:/data |       - ./data/caddy/data:/data | ||||||
|       - ./data/caddy/config:/config |       - ./data/caddy/config:/config | ||||||
|   | |||||||
							
								
								
									
										4
									
								
								deploy_frontend.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										4
									
								
								deploy_frontend.sh
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,4 @@ | |||||||
|  | #!/bin/sh | ||||||
|  |  | ||||||
|  | trunk build --release --config /home/connor/docs/projects/calendar/frontend/Trunk.toml | ||||||
|  | sudo rsync -azX --delete --info=progress2 -e 'ssh -T -q' --rsync-path='sudo rsync' /home/connor/docs/projects/calendar/frontend/dist connor@server.rcjohnstone.com:/home/connor/data/runway/ | ||||||
							
								
								
									
										
											BIN
										
									
								
								favicon_big.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								favicon_big.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 952 KiB | 
| @@ -37,6 +37,7 @@ reqwest = { version = "0.11", features = ["json"] } | |||||||
| ical = "0.7" | ical = "0.7" | ||||||
| serde = { version = "1.0", features = ["derive"] } | serde = { version = "1.0", features = ["derive"] } | ||||||
| serde_json = "1.0" | serde_json = "1.0" | ||||||
|  | serde-wasm-bindgen = "0.6" | ||||||
|  |  | ||||||
| # Date and time handling | # Date and time handling | ||||||
| chrono = { version = "0.4", features = ["serde", "wasm-bindgen"] } | chrono = { version = "0.4", features = ["serde", "wasm-bindgen"] } | ||||||
|   | |||||||
							
								
								
									
										
											BIN
										
									
								
								frontend/favicon.ico
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								frontend/favicon.ico
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 58 KiB | 
| @@ -7,10 +7,11 @@ | |||||||
|     <base data-trunk-public-url /> |     <base data-trunk-public-url /> | ||||||
|     <link data-trunk rel="css" href="styles.css"> |     <link data-trunk rel="css" href="styles.css"> | ||||||
|     <link data-trunk rel="copy-file" href="styles/google.css"> |     <link data-trunk rel="copy-file" href="styles/google.css"> | ||||||
|  |     <link data-trunk rel="icon" href="favicon.ico"> | ||||||
| </head> | </head> | ||||||
| <body> | <body> | ||||||
|     <script> |     <script> | ||||||
|         console.log("HTML loaded, waiting for WASM..."); |         console.log("HTML fully loaded, waiting for WASM..."); | ||||||
|         window.addEventListener('TrunkApplicationStarted', () => { |         window.addEventListener('TrunkApplicationStarted', () => { | ||||||
|             console.log("Trunk application started successfully!"); |             console.log("Trunk application started successfully!"); | ||||||
|         }); |         }); | ||||||
|   | |||||||
| @@ -1,13 +1,14 @@ | |||||||
| use crate::components::{ | use crate::components::{ | ||||||
|     CalendarContextMenu, ContextMenu, CreateCalendarModal, CreateEventModal, DeleteAction, |     CalendarContextMenu, ContextMenu, CreateCalendarModal, CreateEventModal, DeleteAction, | ||||||
|     EditAction, EventClass, EventContextMenu, EventCreationData, EventStatus, RecurrenceType, |     EditAction, EventContextMenu, EventCreationData, ExternalCalendarModal, RouteHandler,  | ||||||
|     ReminderType, RouteHandler, Sidebar, Theme, ViewMode, |     Sidebar, Theme, ViewMode, | ||||||
| }; | }; | ||||||
| use crate::components::sidebar::{Style}; | use crate::components::sidebar::{Style}; | ||||||
| use crate::models::ical::VEvent; | use crate::models::ical::VEvent; | ||||||
| use crate::services::{calendar_service::UserInfo, CalendarService}; | use crate::services::{calendar_service::{UserInfo, ExternalCalendar}, CalendarService}; | ||||||
| use chrono::NaiveDate; | use chrono::NaiveDate; | ||||||
| use gloo_storage::{LocalStorage, Storage}; | use gloo_storage::{LocalStorage, Storage}; | ||||||
|  | use gloo_timers::callback::Interval; | ||||||
| use wasm_bindgen::JsCast; | use wasm_bindgen::JsCast; | ||||||
| use web_sys::MouseEvent; | use web_sys::MouseEvent; | ||||||
| use yew::prelude::*; | use yew::prelude::*; | ||||||
| @@ -75,6 +76,12 @@ pub fn App() -> Html { | |||||||
|     let _recurring_edit_event = use_state(|| -> Option<VEvent> { None }); |     let _recurring_edit_event = use_state(|| -> Option<VEvent> { None }); | ||||||
|     let _recurring_edit_data = use_state(|| -> Option<EventCreationData> { None }); |     let _recurring_edit_data = use_state(|| -> Option<EventCreationData> { None }); | ||||||
|      |      | ||||||
|  |     // External calendar state | ||||||
|  |     let external_calendars = use_state(|| -> Vec<ExternalCalendar> { Vec::new() }); | ||||||
|  |     let external_calendar_events = use_state(|| -> Vec<VEvent> { Vec::new() }); | ||||||
|  |     let external_calendar_modal_open = use_state(|| false); | ||||||
|  |     let refresh_interval = use_state(|| -> Option<Interval> { None }); | ||||||
|  |  | ||||||
|     // Calendar view state - load from localStorage if available |     // Calendar view state - load from localStorage if available | ||||||
|     let current_view = use_state(|| { |     let current_view = use_state(|| { | ||||||
|         // Try to load saved view mode from localStorage |         // Try to load saved view mode from localStorage | ||||||
| @@ -302,6 +309,80 @@ pub fn App() -> Html { | |||||||
|         }); |         }); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     // Function to refresh external calendars | ||||||
|  |     let refresh_external_calendars = { | ||||||
|  |         let external_calendars = external_calendars.clone(); | ||||||
|  |         let external_calendar_events = external_calendar_events.clone(); | ||||||
|  |         Callback::from(move |_| { | ||||||
|  |             let external_calendars = external_calendars.clone(); | ||||||
|  |             let external_calendar_events = external_calendar_events.clone(); | ||||||
|  |  | ||||||
|  |             wasm_bindgen_futures::spawn_local(async move { | ||||||
|  |                 // Load external calendars | ||||||
|  |                 match CalendarService::get_external_calendars().await { | ||||||
|  |                     Ok(calendars) => { | ||||||
|  |                         external_calendars.set(calendars.clone()); | ||||||
|  |                          | ||||||
|  |                         // Load events for visible external calendars | ||||||
|  |                         let mut all_events = Vec::new(); | ||||||
|  |                         for calendar in calendars { | ||||||
|  |                             if calendar.is_visible { | ||||||
|  |                                 if let Ok(mut events) = CalendarService::fetch_external_calendar_events(calendar.id).await { | ||||||
|  |                                     // Set calendar_path for color matching | ||||||
|  |                                     for event in &mut events { | ||||||
|  |                                         event.calendar_path = Some(format!("external_{}", calendar.id)); | ||||||
|  |                                     } | ||||||
|  |                                     all_events.extend(events); | ||||||
|  |                                 } | ||||||
|  |                             } | ||||||
|  |                         } | ||||||
|  |                         external_calendar_events.set(all_events); | ||||||
|  |                     } | ||||||
|  |                     Err(err) => { | ||||||
|  |                         web_sys::console::log_1( | ||||||
|  |                             &format!("Failed to load external calendars: {}", err).into(), | ||||||
|  |                         ); | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |             }); | ||||||
|  |         }) | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     // Load external calendars when auth token is available and set up auto-refresh | ||||||
|  |     { | ||||||
|  |         let auth_token = auth_token.clone(); | ||||||
|  |         let refresh_external_calendars = refresh_external_calendars.clone(); | ||||||
|  |         let refresh_interval = refresh_interval.clone(); | ||||||
|  |         let external_calendars = external_calendars.clone(); | ||||||
|  |         let external_calendar_events = external_calendar_events.clone(); | ||||||
|  |  | ||||||
|  |         use_effect_with((*auth_token).clone(), move |token| { | ||||||
|  |             if let Some(_) = token { | ||||||
|  |                 // Initial load | ||||||
|  |                 refresh_external_calendars.emit(()); | ||||||
|  |                  | ||||||
|  |                 // Set up 5-minute refresh interval | ||||||
|  |                 let refresh_external_calendars = refresh_external_calendars.clone(); | ||||||
|  |                 let interval = Interval::new(5 * 60 * 1000, move || { | ||||||
|  |                     refresh_external_calendars.emit(()); | ||||||
|  |                 }); | ||||||
|  |                 refresh_interval.set(Some(interval)); | ||||||
|  |             } else { | ||||||
|  |                 // Clear data and interval when logged out | ||||||
|  |                 external_calendars.set(Vec::new()); | ||||||
|  |                 external_calendar_events.set(Vec::new()); | ||||||
|  |                 refresh_interval.set(None); | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             // Cleanup function | ||||||
|  |             let refresh_interval = refresh_interval.clone(); | ||||||
|  |             move || { | ||||||
|  |                 // Clear interval on cleanup | ||||||
|  |                 refresh_interval.set(None); | ||||||
|  |             } | ||||||
|  |         }); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     let on_outside_click = { |     let on_outside_click = { | ||||||
|         let color_picker_open = color_picker_open.clone(); |         let color_picker_open = color_picker_open.clone(); | ||||||
|         let context_menu_open = context_menu_open.clone(); |         let context_menu_open = context_menu_open.clone(); | ||||||
| @@ -413,7 +494,151 @@ pub fn App() -> Html { | |||||||
|         let create_event_modal_open = create_event_modal_open.clone(); |         let create_event_modal_open = create_event_modal_open.clone(); | ||||||
|         let auth_token = auth_token.clone(); |         let auth_token = auth_token.clone(); | ||||||
|         Callback::from(move |event_data: EventCreationData| { |         Callback::from(move |event_data: EventCreationData| { | ||||||
|  |             // Check if this is an update operation (has original_uid) or a create operation | ||||||
|  |             if let Some(original_uid) = event_data.original_uid.clone() { | ||||||
|  |                 web_sys::console::log_1(&format!("Updating event via modal: {:?}", event_data).into()); | ||||||
|  |                  | ||||||
|  |                 create_event_modal_open.set(false); | ||||||
|  |                  | ||||||
|  |                 // Handle the update operation using the existing backend update logic | ||||||
|  |                 if let Some(token) = (*auth_token).clone() { | ||||||
|  |                     let event_data_for_update = event_data.clone(); | ||||||
|  |                     wasm_bindgen_futures::spawn_local(async move { | ||||||
|  |                         let calendar_service = CalendarService::new(); | ||||||
|  |  | ||||||
|  |                         // Get CalDAV password from storage | ||||||
|  |                         let password = if let Ok(credentials_str) = | ||||||
|  |                             LocalStorage::get::<String>("caldav_credentials") | ||||||
|  |                         { | ||||||
|  |                             if let Ok(credentials) = | ||||||
|  |                                 serde_json::from_str::<serde_json::Value>(&credentials_str) | ||||||
|  |                             { | ||||||
|  |                                 credentials["password"].as_str().unwrap_or("").to_string() | ||||||
|  |                             } else { | ||||||
|  |                                 String::new() | ||||||
|  |                             } | ||||||
|  |                         } else { | ||||||
|  |                             String::new() | ||||||
|  |                         }; | ||||||
|  |  | ||||||
|  |                         // Convert EventCreationData to update parameters | ||||||
|  |                         let params = event_data_for_update.to_create_event_params(); | ||||||
|  |                          | ||||||
|  |                         // Determine if this is a recurring event update | ||||||
|  |                         let is_recurring = matches!(event_data_for_update.recurrence, crate::components::event_form::RecurrenceType::Daily |  | ||||||
|  |                                                    crate::components::event_form::RecurrenceType::Weekly |  | ||||||
|  |                                                    crate::components::event_form::RecurrenceType::Monthly |  | ||||||
|  |                                                    crate::components::event_form::RecurrenceType::Yearly); | ||||||
|  |                          | ||||||
|  |                         let update_result = if is_recurring && event_data_for_update.edit_scope.is_some() { | ||||||
|  |                             // Use series update endpoint for recurring events | ||||||
|  |                             let edit_action = event_data_for_update.edit_scope.unwrap(); | ||||||
|  |                             let scope = match edit_action { | ||||||
|  |                                 crate::components::EditAction::EditAll => "all_in_series".to_string(), | ||||||
|  |                                 crate::components::EditAction::EditFuture => "this_and_future".to_string(), | ||||||
|  |                                 crate::components::EditAction::EditThis => "this_only".to_string(), | ||||||
|  |                             }; | ||||||
|  |                              | ||||||
|  |                             calendar_service | ||||||
|  |                                 .update_series( | ||||||
|  |                                     &token, | ||||||
|  |                                     &password, | ||||||
|  |                                     original_uid.clone(), | ||||||
|  |                                     params.0,  // title | ||||||
|  |                                     params.1,  // description | ||||||
|  |                                     params.2,  // start_date | ||||||
|  |                                     params.3,  // start_time | ||||||
|  |                                     params.4,  // end_date | ||||||
|  |                                     params.5,  // end_time | ||||||
|  |                                     params.6,  // location | ||||||
|  |                                     params.7,  // all_day | ||||||
|  |                                     params.8,  // status | ||||||
|  |                                     params.9,  // class | ||||||
|  |                                     params.10, // priority | ||||||
|  |                                     params.11, // organizer | ||||||
|  |                                     params.12, // attendees | ||||||
|  |                                     params.13, // categories | ||||||
|  |                                     params.14, // reminder | ||||||
|  |                                     params.15, // recurrence | ||||||
|  |                                     params.16, // recurrence_days | ||||||
|  |                                     params.18, // recurrence_count | ||||||
|  |                                     params.19, // recurrence_until | ||||||
|  |                                     params.17, // calendar_path | ||||||
|  |                                     scope, | ||||||
|  |                                     event_data_for_update.occurrence_date.map(|d| d.format("%Y-%m-%d").to_string()), // occurrence_date | ||||||
|  |                                 ) | ||||||
|  |                                 .await | ||||||
|  |                         } else { | ||||||
|  |                             // Use regular update endpoint for single events | ||||||
|  |                             calendar_service | ||||||
|  |                                 .update_event( | ||||||
|  |                                     &token, | ||||||
|  |                                     &password, | ||||||
|  |                                     original_uid.clone(), | ||||||
|  |                                     params.0,  // title | ||||||
|  |                                     params.1,  // description | ||||||
|  |                                     params.2,  // start_date | ||||||
|  |                                     params.3,  // start_time | ||||||
|  |                                     params.4,  // end_date | ||||||
|  |                                     params.5,  // end_time | ||||||
|  |                                     params.6,  // location | ||||||
|  |                                     params.7,  // all_day | ||||||
|  |                                     params.8,  // status | ||||||
|  |                                     params.9,  // class | ||||||
|  |                                     params.10, // priority | ||||||
|  |                                     params.11, // organizer | ||||||
|  |                                     params.12, // attendees | ||||||
|  |                                     params.13, // categories | ||||||
|  |                                     params.14, // reminder | ||||||
|  |                                     params.15, // recurrence | ||||||
|  |                                     params.16, // recurrence_days | ||||||
|  |                                     params.17, // calendar_path | ||||||
|  |                                     vec![], // exception_dates - empty for simple updates | ||||||
|  |                                     None,   // update_action - None for regular updates | ||||||
|  |                                     None,   // until_date - None for regular updates | ||||||
|  |                                 ) | ||||||
|  |                                 .await | ||||||
|  |                         }; | ||||||
|  |  | ||||||
|  |                         match update_result { | ||||||
|  |                             Ok(_) => { | ||||||
|  |                                 web_sys::console::log_1(&"Event updated successfully via modal".into()); | ||||||
|  |                                 // Trigger a page reload to refresh events from all calendars | ||||||
|  |                                 if let Some(window) = web_sys::window() { | ||||||
|  |                                     let _ = window.location().reload(); | ||||||
|  |                                 } | ||||||
|  |                             } | ||||||
|  |                             Err(err) => { | ||||||
|  |                                 web_sys::console::error_1( | ||||||
|  |                                     &format!("Failed to update event: {}", err).into(), | ||||||
|  |                                 ); | ||||||
|  |                                 web_sys::window() | ||||||
|  |                                     .unwrap() | ||||||
|  |                                     .alert_with_message(&format!("Failed to update event: {}", err)) | ||||||
|  |                                     .unwrap(); | ||||||
|  |                             } | ||||||
|  |                         } | ||||||
|  |                     }); | ||||||
|  |                 } | ||||||
|  |                 return; | ||||||
|  |             } | ||||||
|  |              | ||||||
|             web_sys::console::log_1(&format!("Creating event: {:?}", event_data).into()); |             web_sys::console::log_1(&format!("Creating event: {:?}", event_data).into()); | ||||||
|  |              | ||||||
|  |             // Save the selected calendar as the last used calendar | ||||||
|  |             if let Some(ref calendar_path) = event_data.selected_calendar { | ||||||
|  |                 let _ = LocalStorage::set("last_used_calendar", calendar_path); | ||||||
|  |                  | ||||||
|  |                 // Also sync to backend asynchronously | ||||||
|  |                 let calendar_path_for_sync = calendar_path.clone(); | ||||||
|  |                 wasm_bindgen_futures::spawn_local(async move { | ||||||
|  |                     let preferences_service = crate::services::preferences::PreferencesService::new(); | ||||||
|  |                     if let Err(e) = preferences_service.update_last_used_calendar(&calendar_path_for_sync).await { | ||||||
|  |                         web_sys::console::warn_1(&format!("Failed to sync last used calendar to backend: {}", e).into()); | ||||||
|  |                     } | ||||||
|  |                 }); | ||||||
|  |             } | ||||||
|  |              | ||||||
|             create_event_modal_open.set(false); |             create_event_modal_open.set(false); | ||||||
|  |  | ||||||
|             if let Some(_token) = (*auth_token).clone() { |             if let Some(_token) = (*auth_token).clone() { | ||||||
| @@ -455,6 +680,8 @@ pub fn App() -> Html { | |||||||
|                             params.14, // reminder |                             params.14, // reminder | ||||||
|                             params.15, // recurrence |                             params.15, // recurrence | ||||||
|                             params.16, // recurrence_days |                             params.16, // recurrence_days | ||||||
|  |                             params.18, // recurrence_count | ||||||
|  |                             params.19, // recurrence_until | ||||||
|                             params.17, // calendar_path |                             params.17, // calendar_path | ||||||
|                         ) |                         ) | ||||||
|                         .await; |                         .await; | ||||||
| @@ -534,18 +761,11 @@ pub fn App() -> Html { | |||||||
|                             String::new() |                             String::new() | ||||||
|                         }; |                         }; | ||||||
|  |  | ||||||
|                         // Convert local times to UTC for backend storage |                         // Send local time directly to backend (backend will handle UTC conversion) | ||||||
|                         let start_utc = new_start |                         let start_date = new_start.format("%Y-%m-%d").to_string(); | ||||||
|                             .and_local_timezone(chrono::Local) |                         let start_time = new_start.format("%H:%M").to_string(); | ||||||
|                             .unwrap() |                         let end_date = new_end.format("%Y-%m-%d").to_string(); | ||||||
|                             .to_utc(); |                         let end_time = new_end.format("%H:%M").to_string(); | ||||||
|                         let end_utc = new_end.and_local_timezone(chrono::Local).unwrap().to_utc(); |  | ||||||
|  |  | ||||||
|                         // Format UTC date and time strings for backend |  | ||||||
|                         let start_date = start_utc.format("%Y-%m-%d").to_string(); |  | ||||||
|                         let start_time = start_utc.format("%H:%M").to_string(); |  | ||||||
|                         let end_date = end_utc.format("%Y-%m-%d").to_string(); |  | ||||||
|                         let end_time = end_utc.format("%H:%M").to_string(); |  | ||||||
|  |  | ||||||
|                         // Convert existing event data to string formats for the API |                         // Convert existing event data to string formats for the API | ||||||
|                         let status_str = match original_event.status { |                         let status_str = match original_event.status { | ||||||
| @@ -624,6 +844,9 @@ pub fn App() -> Html { | |||||||
|                                             original_event.categories.join(","), |                                             original_event.categories.join(","), | ||||||
|                                             reminder_str.clone(), |                                             reminder_str.clone(), | ||||||
|                                             recurrence_str.clone(), |                                             recurrence_str.clone(), | ||||||
|  |                                             vec![false; 7], | ||||||
|  |                                             None, | ||||||
|  |                                             None, | ||||||
|                                             original_event.calendar_path.clone(), |                                             original_event.calendar_path.clone(), | ||||||
|                                             scope.clone(), |                                             scope.clone(), | ||||||
|                                             occurrence_date, |                                             occurrence_date, | ||||||
| @@ -783,11 +1006,146 @@ pub fn App() -> Html { | |||||||
|                                         let create_modal_open = create_modal_open.clone(); |                                         let create_modal_open = create_modal_open.clone(); | ||||||
|                                         move |_| create_modal_open.set(true) |                                         move |_| create_modal_open.set(true) | ||||||
|                                     })} |                                     })} | ||||||
|  |                                     on_create_external_calendar={Callback::from({ | ||||||
|  |                                         let external_calendar_modal_open = external_calendar_modal_open.clone(); | ||||||
|  |                                         move |_| external_calendar_modal_open.set(true) | ||||||
|  |                                     })} | ||||||
|  |                                     external_calendars={(*external_calendars).clone()} | ||||||
|  |                                     on_external_calendar_toggle={Callback::from({ | ||||||
|  |                                         let external_calendars = external_calendars.clone(); | ||||||
|  |                                         let external_calendar_events = external_calendar_events.clone(); | ||||||
|  |                                         move |id: i32| { | ||||||
|  |                                             let external_calendars = external_calendars.clone(); | ||||||
|  |                                             let external_calendar_events = external_calendar_events.clone(); | ||||||
|  |                                             wasm_bindgen_futures::spawn_local(async move { | ||||||
|  |                                                 // Find the calendar and toggle its visibility | ||||||
|  |                                                 let mut calendars = (*external_calendars).clone(); | ||||||
|  |                                                 if let Some(calendar) = calendars.iter_mut().find(|c| c.id == id) { | ||||||
|  |                                                     calendar.is_visible = !calendar.is_visible; | ||||||
|  |                                                      | ||||||
|  |                                                     // Update on server | ||||||
|  |                                                     if let Err(err) = CalendarService::update_external_calendar( | ||||||
|  |                                                         calendar.id, | ||||||
|  |                                                         &calendar.name, | ||||||
|  |                                                         &calendar.url, | ||||||
|  |                                                         &calendar.color, | ||||||
|  |                                                         calendar.is_visible, | ||||||
|  |                                                     ).await { | ||||||
|  |                                                         web_sys::console::log_1( | ||||||
|  |                                                             &format!("Failed to update external calendar: {}", err).into(), | ||||||
|  |                                                         ); | ||||||
|  |                                                         return; | ||||||
|  |                                                     } | ||||||
|  |                                                      | ||||||
|  |                                                     external_calendars.set(calendars.clone()); | ||||||
|  |                                                      | ||||||
|  |                                                     // Reload events for all visible external calendars   | ||||||
|  |                                                     let mut all_events = Vec::new(); | ||||||
|  |                                                     for cal in calendars { | ||||||
|  |                                                         if cal.is_visible { | ||||||
|  |                                                             if let Ok(mut events) = CalendarService::fetch_external_calendar_events(cal.id).await { | ||||||
|  |                                                                 // Set calendar_path for color matching | ||||||
|  |                                                                 for event in &mut events { | ||||||
|  |                                                                     event.calendar_path = Some(format!("external_{}", cal.id)); | ||||||
|  |                                                                 } | ||||||
|  |                                                                 all_events.extend(events); | ||||||
|  |                                                             } | ||||||
|  |                                                         } | ||||||
|  |                                                     } | ||||||
|  |                                                     external_calendar_events.set(all_events); | ||||||
|  |                                                 } | ||||||
|  |                                             }); | ||||||
|  |                                         } | ||||||
|  |                                     })} | ||||||
|  |                                     on_external_calendar_delete={Callback::from({ | ||||||
|  |                                         let external_calendars = external_calendars.clone(); | ||||||
|  |                                         let external_calendar_events = external_calendar_events.clone(); | ||||||
|  |                                         move |id: i32| { | ||||||
|  |                                             let external_calendars = external_calendars.clone(); | ||||||
|  |                                             let external_calendar_events = external_calendar_events.clone(); | ||||||
|  |                                             wasm_bindgen_futures::spawn_local(async move { | ||||||
|  |                                                 // Delete the external calendar from the server | ||||||
|  |                                                 if let Err(err) = CalendarService::delete_external_calendar(id).await { | ||||||
|  |                                                     web_sys::console::log_1( | ||||||
|  |                                                         &format!("Failed to delete external calendar: {}", err).into(), | ||||||
|  |                                                     ); | ||||||
|  |                                                     return; | ||||||
|  |                                                 } | ||||||
|  |                                                  | ||||||
|  |                                                 // Remove calendar from local state | ||||||
|  |                                                 let mut calendars = (*external_calendars).clone(); | ||||||
|  |                                                 calendars.retain(|c| c.id != id); | ||||||
|  |                                                 external_calendars.set(calendars.clone()); | ||||||
|  |                                                  | ||||||
|  |                                                 // Remove events from this calendar | ||||||
|  |                                                 let mut events = (*external_calendar_events).clone(); | ||||||
|  |                                                 events.retain(|e| { | ||||||
|  |                                                     if let Some(ref calendar_path) = e.calendar_path { | ||||||
|  |                                                         calendar_path != &format!("external_{}", id) | ||||||
|  |                                                     } else { | ||||||
|  |                                                         true | ||||||
|  |                                                     } | ||||||
|  |                                                 }); | ||||||
|  |                                                 external_calendar_events.set(events); | ||||||
|  |                                             }); | ||||||
|  |                                         } | ||||||
|  |                                     })} | ||||||
|  |                                     on_external_calendar_refresh={Callback::from({ | ||||||
|  |                                         let external_calendar_events = external_calendar_events.clone(); | ||||||
|  |                                         let external_calendars = external_calendars.clone(); | ||||||
|  |                                         move |id: i32| { | ||||||
|  |                                             let external_calendar_events = external_calendar_events.clone(); | ||||||
|  |                                             let external_calendars = external_calendars.clone(); | ||||||
|  |                                             wasm_bindgen_futures::spawn_local(async move { | ||||||
|  |                                                 // Force refresh of this specific calendar | ||||||
|  |                                                 if let Ok(mut events) = CalendarService::fetch_external_calendar_events(id).await { | ||||||
|  |                                                     // Set calendar_path for color matching | ||||||
|  |                                                     for event in &mut events { | ||||||
|  |                                                         event.calendar_path = Some(format!("external_{}", id)); | ||||||
|  |                                                     } | ||||||
|  |                                                      | ||||||
|  |                                                     // Update events for this calendar | ||||||
|  |                                                     let mut all_events = (*external_calendar_events).clone(); | ||||||
|  |                                                     // Remove old events from this calendar | ||||||
|  |                                                     all_events.retain(|e| { | ||||||
|  |                                                         if let Some(ref calendar_path) = e.calendar_path { | ||||||
|  |                                                             calendar_path != &format!("external_{}", id) | ||||||
|  |                                                         } else { | ||||||
|  |                                                             true | ||||||
|  |                                                         } | ||||||
|  |                                                     }); | ||||||
|  |                                                     // Add new events | ||||||
|  |                                                     all_events.extend(events); | ||||||
|  |                                                     external_calendar_events.set(all_events); | ||||||
|  |                                                      | ||||||
|  |                                                     // Update the last_fetched timestamp in calendars list | ||||||
|  |                                                     if let Ok(calendars) = CalendarService::get_external_calendars().await { | ||||||
|  |                                                         external_calendars.set(calendars); | ||||||
|  |                                                     } | ||||||
|  |                                                 } | ||||||
|  |                                             }); | ||||||
|  |                                         } | ||||||
|  |                                     })} | ||||||
|                                     color_picker_open={(*color_picker_open).clone()} |                                     color_picker_open={(*color_picker_open).clone()} | ||||||
|                                     on_color_change={on_color_change} |                                     on_color_change={on_color_change} | ||||||
|                                     on_color_picker_toggle={on_color_picker_toggle} |                                     on_color_picker_toggle={on_color_picker_toggle} | ||||||
|                                     available_colors={(*available_colors).clone()} |                                     available_colors={(*available_colors).clone()} | ||||||
|                                     on_calendar_context_menu={on_calendar_context_menu} |                                     on_calendar_context_menu={on_calendar_context_menu} | ||||||
|  |                                     on_calendar_visibility_toggle={Callback::from({ | ||||||
|  |                                         let user_info = user_info.clone(); | ||||||
|  |                                         move |calendar_path: String| { | ||||||
|  |                                             let user_info = user_info.clone(); | ||||||
|  |                                             wasm_bindgen_futures::spawn_local(async move { | ||||||
|  |                                                 if let Some(mut info) = (*user_info).clone() { | ||||||
|  |                                                     // Toggle the visibility | ||||||
|  |                                                     if let Some(calendar) = info.calendars.iter_mut().find(|c| c.path == calendar_path) { | ||||||
|  |                                                         calendar.is_visible = !calendar.is_visible; | ||||||
|  |                                                         user_info.set(Some(info)); | ||||||
|  |                                                     } | ||||||
|  |                                                 } | ||||||
|  |                                             }); | ||||||
|  |                                         } | ||||||
|  |                                     })} | ||||||
|                                     current_view={(*current_view).clone()} |                                     current_view={(*current_view).clone()} | ||||||
|                                     on_view_change={on_view_change} |                                     on_view_change={on_view_change} | ||||||
|                                     current_theme={(*current_theme).clone()} |                                     current_theme={(*current_theme).clone()} | ||||||
| @@ -800,6 +1158,8 @@ pub fn App() -> Html { | |||||||
|                                         auth_token={(*auth_token).clone()} |                                         auth_token={(*auth_token).clone()} | ||||||
|                                         user_info={(*user_info).clone()} |                                         user_info={(*user_info).clone()} | ||||||
|                                         on_login={on_login.clone()} |                                         on_login={on_login.clone()} | ||||||
|  |                                         external_calendar_events={(*external_calendar_events).clone()} | ||||||
|  |                                         external_calendars={(*external_calendars).clone()} | ||||||
|                                         on_event_context_menu={Some(on_event_context_menu.clone())} |                                         on_event_context_menu={Some(on_event_context_menu.clone())} | ||||||
|                                         on_calendar_context_menu={Some(on_calendar_date_context_menu.clone())} |                                         on_calendar_context_menu={Some(on_calendar_date_context_menu.clone())} | ||||||
|                                         view={(*current_view).clone()} |                                         view={(*current_view).clone()} | ||||||
| @@ -1034,6 +1394,8 @@ pub fn App() -> Html { | |||||||
|                 <CreateEventModal |                 <CreateEventModal | ||||||
|                     is_open={*create_event_modal_open} |                     is_open={*create_event_modal_open} | ||||||
|                     selected_date={(*selected_date_for_event).clone()} |                     selected_date={(*selected_date_for_event).clone()} | ||||||
|  |                     initial_start_time={None} | ||||||
|  |                     initial_end_time={None} | ||||||
|                     event_to_edit={(*event_context_menu_event).clone()} |                     event_to_edit={(*event_context_menu_event).clone()} | ||||||
|                     edit_scope={(*event_edit_scope).clone()} |                     edit_scope={(*event_edit_scope).clone()} | ||||||
|                     on_close={Callback::from({ |                     on_close={Callback::from({ | ||||||
| @@ -1048,243 +1410,60 @@ pub fn App() -> Html { | |||||||
|                         } |                         } | ||||||
|                     })} |                     })} | ||||||
|                     on_create={on_event_create} |                     on_create={on_event_create} | ||||||
|                     on_update={Callback::from({ |                     available_calendars={user_info.as_ref().map(|ui| ui.calendars.clone()).unwrap_or_default()} | ||||||
|                         let auth_token = auth_token.clone(); |                 /> | ||||||
|                         let create_event_modal_open = create_event_modal_open.clone(); |  | ||||||
|                         let event_context_menu_event = event_context_menu_event.clone(); |  | ||||||
|                         let event_edit_scope = event_edit_scope.clone(); |  | ||||||
|                         move |(original_event, updated_data): (VEvent, EventCreationData)| { |  | ||||||
|                             web_sys::console::log_1(&format!("Updating event: {:?}, edit_scope: {:?}", updated_data, updated_data.edit_scope).into()); |  | ||||||
|                             create_event_modal_open.set(false); |  | ||||||
|                             event_context_menu_event.set(None); |  | ||||||
|                             event_edit_scope.set(None); |  | ||||||
|  |  | ||||||
|                             if let Some(token) = (*auth_token).clone() { |                 <ExternalCalendarModal | ||||||
|  |                     is_open={*external_calendar_modal_open} | ||||||
|  |                     on_close={Callback::from({ | ||||||
|  |                         let external_calendar_modal_open = external_calendar_modal_open.clone(); | ||||||
|  |                         move |_| external_calendar_modal_open.set(false) | ||||||
|  |                     })} | ||||||
|  |                     on_success={Callback::from({ | ||||||
|  |                         let external_calendars = external_calendars.clone(); | ||||||
|  |                         let external_calendar_events = external_calendar_events.clone(); | ||||||
|  |                         move |new_calendar_id: i32| { | ||||||
|  |                             let external_calendars = external_calendars.clone(); | ||||||
|  |                             let external_calendar_events = external_calendar_events.clone(); | ||||||
|                             wasm_bindgen_futures::spawn_local(async move { |                             wasm_bindgen_futures::spawn_local(async move { | ||||||
|                                     let calendar_service = CalendarService::new(); |                                 // First, refresh the calendar list to get the new calendar | ||||||
|  |                                 match CalendarService::get_external_calendars().await { | ||||||
|  |                                     Ok(calendars) => { | ||||||
|  |                                         external_calendars.set(calendars.clone()); | ||||||
|                                          |                                          | ||||||
|                                     // Get CalDAV password from storage |                                         // Then immediately fetch events for the new calendar if it's visible | ||||||
|                                     let password = if let Ok(credentials_str) = LocalStorage::get::<String>("caldav_credentials") { |                                         if let Some(new_calendar) = calendars.iter().find(|c| c.id == new_calendar_id) { | ||||||
|                                         if let Ok(credentials) = serde_json::from_str::<serde_json::Value>(&credentials_str) { |                                             if new_calendar.is_visible { | ||||||
|                                             credentials["password"].as_str().unwrap_or("").to_string() |                                                 match CalendarService::fetch_external_calendar_events(new_calendar_id).await { | ||||||
|                                         } else { |                                                     Ok(mut events) => { | ||||||
|                                             String::new() |                                                         // Set calendar_path for color matching | ||||||
|  |                                                         for event in &mut events { | ||||||
|  |                                                             event.calendar_path = Some(format!("external_{}", new_calendar_id)); | ||||||
|                                                         } |                                                         } | ||||||
|                                     } else { |  | ||||||
|                                         String::new() |  | ||||||
|                                     }; |  | ||||||
|                                                          |                                                          | ||||||
|                                     // Convert local times to UTC for backend storage |                                                         // Add the new calendar's events to existing events | ||||||
|                                     let start_local = updated_data.start_date.and_time(updated_data.start_time); |                                                         let mut all_events = (*external_calendar_events).clone(); | ||||||
|                                     let end_local = updated_data.end_date.and_time(updated_data.end_time); |                                                         all_events.extend(events); | ||||||
|  |                                                         external_calendar_events.set(all_events); | ||||||
|                                     let start_utc = start_local.and_local_timezone(chrono::Local).unwrap().to_utc(); |                                                     } | ||||||
|                                     let end_utc = end_local.and_local_timezone(chrono::Local).unwrap().to_utc(); |                                                     Err(e) => { | ||||||
|  |                                                         web_sys::console::log_1( | ||||||
|                                     // Format UTC date and time strings for backend |                                                             &format!("Failed to fetch events for new calendar {}: {}", new_calendar_id, e).into(), | ||||||
|                                     let start_date = start_utc.format("%Y-%m-%d").to_string(); |                                                         ); | ||||||
|                                     let start_time = start_utc.format("%H:%M").to_string(); |                                                     } | ||||||
|                                     let end_date = end_utc.format("%Y-%m-%d").to_string(); |  | ||||||
|                                     let end_time = end_utc.format("%H:%M").to_string(); |  | ||||||
|  |  | ||||||
|                                     // Convert enums to strings for backend |  | ||||||
|                                     let status_str = match updated_data.status { |  | ||||||
|                                         EventStatus::Tentative => "tentative", |  | ||||||
|                                         EventStatus::Cancelled => "cancelled", |  | ||||||
|                                         _ => "confirmed", |  | ||||||
|                                     }.to_string(); |  | ||||||
|  |  | ||||||
|                                     let class_str = match updated_data.class { |  | ||||||
|                                         EventClass::Private => "private", |  | ||||||
|                                         EventClass::Confidential => "confidential", |  | ||||||
|                                         _ => "public", |  | ||||||
|                                     }.to_string(); |  | ||||||
|  |  | ||||||
|                                     let reminder_str = match updated_data.reminder { |  | ||||||
|                                         ReminderType::Minutes15 => "15min", |  | ||||||
|                                         ReminderType::Minutes30 => "30min", |  | ||||||
|                                         ReminderType::Hour1 => "1hour", |  | ||||||
|                                         ReminderType::Hours2 => "2hours", |  | ||||||
|                                         ReminderType::Day1 => "1day", |  | ||||||
|                                         ReminderType::Days2 => "2days", |  | ||||||
|                                         ReminderType::Week1 => "1week", |  | ||||||
|                                         _ => "none", |  | ||||||
|                                     }.to_string(); |  | ||||||
|  |  | ||||||
|                                     let recurrence_str = match updated_data.recurrence { |  | ||||||
|                                         RecurrenceType::Daily => "daily", |  | ||||||
|                                         RecurrenceType::Weekly => "weekly", |  | ||||||
|                                         RecurrenceType::Monthly => "monthly", |  | ||||||
|                                         RecurrenceType::Yearly => "yearly", |  | ||||||
|                                         _ => "none", |  | ||||||
|                                     }.to_string(); |  | ||||||
|  |  | ||||||
|                                     // Check if the calendar has changed |  | ||||||
|                                     let calendar_changed = original_event.calendar_path.as_ref() != updated_data.selected_calendar.as_ref(); |  | ||||||
|  |  | ||||||
|                                     if calendar_changed { |  | ||||||
|                                         // Calendar changed - need to delete from original and create in new |  | ||||||
|                                         web_sys::console::log_1(&"Calendar changed - performing delete + create".into()); |  | ||||||
|  |  | ||||||
|                                         // First delete from original calendar |  | ||||||
|                                         if let Some(original_calendar_path) = &original_event.calendar_path { |  | ||||||
|                                             if let Some(event_href) = &original_event.href { |  | ||||||
|                                                 match calendar_service.delete_event( |  | ||||||
|                                                     &token, |  | ||||||
|                                                     &password, |  | ||||||
|                                                     original_calendar_path.clone(), |  | ||||||
|                                                     event_href.clone(), |  | ||||||
|                                                     "single".to_string(), // delete single occurrence |  | ||||||
|                                                     None |  | ||||||
|                                                 ).await { |  | ||||||
|                                                     Ok(_) => { |  | ||||||
|                                                         web_sys::console::log_1(&"Original event deleted successfully".into()); |  | ||||||
|  |  | ||||||
|                                                         // Now create the event in the new calendar |  | ||||||
|                                                         match calendar_service.create_event( |  | ||||||
|                                                             &token, |  | ||||||
|                                                             &password, |  | ||||||
|                                                             updated_data.title, |  | ||||||
|                                                             updated_data.description, |  | ||||||
|                                                             start_date, |  | ||||||
|                                                             start_time, |  | ||||||
|                                                             end_date, |  | ||||||
|                                                             end_time, |  | ||||||
|                                                             updated_data.location, |  | ||||||
|                                                             updated_data.all_day, |  | ||||||
|                                                             status_str, |  | ||||||
|                                                             class_str, |  | ||||||
|                                                             updated_data.priority, |  | ||||||
|                                                             updated_data.organizer, |  | ||||||
|                                                             updated_data.attendees, |  | ||||||
|                                                             updated_data.categories, |  | ||||||
|                                                             reminder_str, |  | ||||||
|                                                             recurrence_str, |  | ||||||
|                                                             updated_data.recurrence_days, |  | ||||||
|                                                             updated_data.selected_calendar |  | ||||||
|                                                         ).await { |  | ||||||
|                                                             Ok(_) => { |  | ||||||
|                                                                 web_sys::console::log_1(&"Event moved to new calendar successfully".into()); |  | ||||||
|                                                                 // Trigger a page reload to refresh events from all calendars |  | ||||||
|                                                                 web_sys::window().unwrap().location().reload().unwrap(); |  | ||||||
|                                                 } |                                                 } | ||||||
|                                                             Err(err) => { |  | ||||||
|                                                                 web_sys::console::error_1(&format!("Failed to create event in new calendar: {}", err).into()); |  | ||||||
|                                                                 web_sys::window().unwrap().alert_with_message(&format!("Failed to move event to new calendar: {}", err)).unwrap(); |  | ||||||
|                                             } |                                             } | ||||||
|                                         } |                                         } | ||||||
|                                     } |                                     } | ||||||
|                                     Err(err) => { |                                     Err(err) => { | ||||||
|                                                         web_sys::console::error_1(&format!("Failed to delete original event: {}", err).into()); |                                         web_sys::console::log_1( | ||||||
|                                                         web_sys::window().unwrap().alert_with_message(&format!("Failed to delete original event: {}", err)).unwrap(); |                                             &format!("Failed to refresh calendars after creation: {}", err).into(), | ||||||
|                                                     } |                                         ); | ||||||
|                                                 } |  | ||||||
|                                             } else { |  | ||||||
|                                                 web_sys::console::error_1(&"Original event missing href for deletion".into()); |  | ||||||
|                                                 web_sys::window().unwrap().alert_with_message("Cannot move event - original event missing href").unwrap(); |  | ||||||
|                                             } |  | ||||||
|                                         } else { |  | ||||||
|                                             web_sys::console::error_1(&"Original event missing calendar_path for deletion".into()); |  | ||||||
|                                             web_sys::window().unwrap().alert_with_message("Cannot move event - original event missing calendar path").unwrap(); |  | ||||||
|                                         } |  | ||||||
|                                     } else { |  | ||||||
|                                         // Calendar hasn't changed - check if we should use series endpoint |  | ||||||
|                                         let use_series_endpoint = updated_data.edit_scope.is_some() && original_event.rrule.is_some(); |  | ||||||
|  |  | ||||||
|                                         if use_series_endpoint { |  | ||||||
|                                             // Use series endpoint for recurring event modal edits |  | ||||||
|                                             let update_scope = match updated_data.edit_scope.as_ref().unwrap() { |  | ||||||
|                                                 EditAction::EditThis => "this_only", |  | ||||||
|                                                 EditAction::EditFuture => "this_and_future", |  | ||||||
|                                                 EditAction::EditAll => "all_in_series", |  | ||||||
|                                             }; |  | ||||||
|  |  | ||||||
|                                             // For single occurrence edits, we need the occurrence date |  | ||||||
|                                             let occurrence_date = if update_scope == "this_only" || update_scope == "this_and_future" { |  | ||||||
|                                                 // Use the original event's start date as the occurrence date |  | ||||||
|                                                 Some(original_event.dtstart.format("%Y-%m-%d").to_string()) |  | ||||||
|                                             } else { |  | ||||||
|                                                 None |  | ||||||
|                                             }; |  | ||||||
|  |  | ||||||
|                                             match calendar_service.update_series( |  | ||||||
|                                                 &token, |  | ||||||
|                                                 &password, |  | ||||||
|                                                 original_event.uid, |  | ||||||
|                                                 updated_data.title, |  | ||||||
|                                                 updated_data.description, |  | ||||||
|                                                 start_date, |  | ||||||
|                                                 start_time, |  | ||||||
|                                                 end_date, |  | ||||||
|                                                 end_time, |  | ||||||
|                                                 updated_data.location, |  | ||||||
|                                                 updated_data.all_day, |  | ||||||
|                                                 status_str, |  | ||||||
|                                                 class_str, |  | ||||||
|                                                 updated_data.priority, |  | ||||||
|                                                 updated_data.organizer, |  | ||||||
|                                                 updated_data.attendees, |  | ||||||
|                                                 updated_data.categories, |  | ||||||
|                                                 reminder_str, |  | ||||||
|                                                 recurrence_str, |  | ||||||
|                                                 updated_data.selected_calendar, |  | ||||||
|                                                 update_scope.to_string(), |  | ||||||
|                                                 occurrence_date, |  | ||||||
|                                             ).await { |  | ||||||
|                                                 Ok(_) => { |  | ||||||
|                                                     web_sys::console::log_1(&"Series updated successfully".into()); |  | ||||||
|                                                     web_sys::window().unwrap().location().reload().unwrap(); |  | ||||||
|                                                 } |  | ||||||
|                                                 Err(err) => { |  | ||||||
|                                                     web_sys::console::error_1(&format!("Failed to update series: {}", err).into()); |  | ||||||
|                                                     web_sys::window().unwrap().alert_with_message(&format!("Failed to update series: {}", err)).unwrap(); |  | ||||||
|                                                 } |  | ||||||
|                                             } |  | ||||||
|                                         } else { |  | ||||||
|                                             // Use regular event endpoint for non-recurring events or legacy updates |  | ||||||
|                                             match calendar_service.update_event( |  | ||||||
|                                             &token, |  | ||||||
|                                             &password, |  | ||||||
|                                             original_event.uid, |  | ||||||
|                                             updated_data.title, |  | ||||||
|                                             updated_data.description, |  | ||||||
|                                             start_date, |  | ||||||
|                                             start_time, |  | ||||||
|                                             end_date, |  | ||||||
|                                             end_time, |  | ||||||
|                                             updated_data.location, |  | ||||||
|                                             updated_data.all_day, |  | ||||||
|                                             status_str, |  | ||||||
|                                             class_str, |  | ||||||
|                                             updated_data.priority, |  | ||||||
|                                             updated_data.organizer, |  | ||||||
|                                             updated_data.attendees, |  | ||||||
|                                             updated_data.categories, |  | ||||||
|                                             reminder_str, |  | ||||||
|                                             recurrence_str, |  | ||||||
|                                             updated_data.recurrence_days, |  | ||||||
|                                             updated_data.selected_calendar, |  | ||||||
|                                             original_event.exdate.clone(), |  | ||||||
|                                             Some("update_series".to_string()), // This is for event edit modal, preserve original RRULE |  | ||||||
|                                             None // No until_date for edit modal |  | ||||||
|                                         ).await { |  | ||||||
|                                             Ok(_) => { |  | ||||||
|                                                 web_sys::console::log_1(&"Event updated successfully".into()); |  | ||||||
|                                                 // Trigger a page reload to refresh events from all calendars |  | ||||||
|                                                 web_sys::window().unwrap().location().reload().unwrap(); |  | ||||||
|                                             } |  | ||||||
|                                             Err(err) => { |  | ||||||
|                                                 web_sys::console::error_1(&format!("Failed to update event: {}", err).into()); |  | ||||||
|                                                 web_sys::window().unwrap().alert_with_message(&format!("Failed to update event: {}", err)).unwrap(); |  | ||||||
|                                             } |  | ||||||
|                                         } |  | ||||||
|                                     } |                                     } | ||||||
|                                 } |                                 } | ||||||
|                             }); |                             }); | ||||||
|                         } |                         } | ||||||
|                         } |  | ||||||
|                     })} |                     })} | ||||||
|                     available_calendars={user_info.as_ref().map(|ui| ui.calendars.clone()).unwrap_or_default()} |  | ||||||
|                 /> |                 /> | ||||||
|             </div> |             </div> | ||||||
|         </BrowserRouter> |         </BrowserRouter> | ||||||
|   | |||||||
| @@ -2,7 +2,7 @@ use crate::components::{ | |||||||
|     CalendarHeader, CreateEventModal, EventCreationData, EventModal, MonthView, ViewMode, WeekView, |     CalendarHeader, CreateEventModal, EventCreationData, EventModal, MonthView, ViewMode, WeekView, | ||||||
| }; | }; | ||||||
| use crate::models::ical::VEvent; | use crate::models::ical::VEvent; | ||||||
| use crate::services::{calendar_service::UserInfo, CalendarService}; | use crate::services::{calendar_service::{UserInfo, ExternalCalendar}, CalendarService}; | ||||||
| use chrono::{Datelike, Duration, Local, NaiveDate}; | use chrono::{Datelike, Duration, Local, NaiveDate}; | ||||||
| use gloo_storage::{LocalStorage, Storage}; | use gloo_storage::{LocalStorage, Storage}; | ||||||
| use std::collections::HashMap; | use std::collections::HashMap; | ||||||
| @@ -14,6 +14,10 @@ pub struct CalendarProps { | |||||||
|     #[prop_or_default] |     #[prop_or_default] | ||||||
|     pub user_info: Option<UserInfo>, |     pub user_info: Option<UserInfo>, | ||||||
|     #[prop_or_default] |     #[prop_or_default] | ||||||
|  |     pub external_calendar_events: Vec<VEvent>, | ||||||
|  |     #[prop_or_default] | ||||||
|  |     pub external_calendars: Vec<ExternalCalendar>, | ||||||
|  |     #[prop_or_default] | ||||||
|     pub on_event_context_menu: Option<Callback<(web_sys::MouseEvent, VEvent)>>, |     pub on_event_context_menu: Option<Callback<(web_sys::MouseEvent, VEvent)>>, | ||||||
|     #[prop_or_default] |     #[prop_or_default] | ||||||
|     pub on_calendar_context_menu: Option<Callback<(web_sys::MouseEvent, NaiveDate)>>, |     pub on_calendar_context_menu: Option<Callback<(web_sys::MouseEvent, NaiveDate)>>, | ||||||
| @@ -101,10 +105,14 @@ pub fn Calendar(props: &CalendarProps) -> Html { | |||||||
|         let loading = loading.clone(); |         let loading = loading.clone(); | ||||||
|         let error = error.clone(); |         let error = error.clone(); | ||||||
|         let current_date = current_date.clone(); |         let current_date = current_date.clone(); | ||||||
|  |         let external_events = props.external_calendar_events.clone(); // Clone before the effect | ||||||
|  |         let view = props.view.clone(); // Clone before the effect | ||||||
|          |          | ||||||
|         use_effect_with((*current_date, props.view.clone()), move |(date, _view)| { |         use_effect_with((*current_date, view.clone(), external_events.len(), props.user_info.clone()), move |(date, _view, _external_len, user_info)| { | ||||||
|             let auth_token: Option<String> = LocalStorage::get("auth_token").ok(); |             let auth_token: Option<String> = LocalStorage::get("auth_token").ok(); | ||||||
|             let date = *date; // Clone the date to avoid lifetime issues |             let date = *date; // Clone the date to avoid lifetime issues | ||||||
|  |             let external_events = external_events.clone(); // Clone external events to avoid lifetime issues | ||||||
|  |             let user_info = user_info.clone(); // Clone user_info to avoid lifetime issues | ||||||
|              |              | ||||||
|             if let Some(token) = auth_token { |             if let Some(token) = auth_token { | ||||||
|                 let events = events.clone(); |                 let events = events.clone(); | ||||||
| @@ -141,7 +149,38 @@ pub fn Calendar(props: &CalendarProps) -> Html { | |||||||
|                         .await |                         .await | ||||||
|                     { |                     { | ||||||
|                         Ok(vevents) => { |                         Ok(vevents) => { | ||||||
|                             let grouped_events = CalendarService::group_events_by_date(vevents); |                             // Filter CalDAV events based on calendar visibility | ||||||
|  |                             let mut filtered_events = if let Some(user_info) = user_info.as_ref() { | ||||||
|  |                                 vevents.into_iter() | ||||||
|  |                                     .filter(|event| { | ||||||
|  |                                         if let Some(calendar_path) = event.calendar_path.as_ref() { | ||||||
|  |                                             // Find the calendar info for this event | ||||||
|  |                                             user_info.calendars.iter() | ||||||
|  |                                                 .find(|cal| &cal.path == calendar_path) | ||||||
|  |                                                 .map(|cal| cal.is_visible) | ||||||
|  |                                                 .unwrap_or(true) // Default to visible if not found | ||||||
|  |                                         } else { | ||||||
|  |                                             true // Show events without calendar path | ||||||
|  |                                         } | ||||||
|  |                                     }) | ||||||
|  |                                     .collect() | ||||||
|  |                             } else { | ||||||
|  |                                 vevents // Show all events if no user info | ||||||
|  |                             }; | ||||||
|  |                              | ||||||
|  |                             // Mark external events as external by adding a special category | ||||||
|  |                             let marked_external_events: Vec<VEvent> = external_events | ||||||
|  |                                 .into_iter() | ||||||
|  |                                 .map(|mut event| { | ||||||
|  |                                     // Add a special category to identify external events | ||||||
|  |                                     event.categories.push("__EXTERNAL_CALENDAR__".to_string()); | ||||||
|  |                                     event | ||||||
|  |                                 }) | ||||||
|  |                                 .collect(); | ||||||
|  |                              | ||||||
|  |                             filtered_events.extend(marked_external_events); | ||||||
|  |                              | ||||||
|  |                             let grouped_events = CalendarService::group_events_by_date(filtered_events); | ||||||
|                             events.set(grouped_events); |                             events.set(grouped_events); | ||||||
|                             loading.set(false); |                             loading.set(false); | ||||||
|                         } |                         } | ||||||
| @@ -452,6 +491,7 @@ pub fn Calendar(props: &CalendarProps) -> Html { | |||||||
|                                 on_event_click={on_event_click.clone()} |                                 on_event_click={on_event_click.clone()} | ||||||
|                                 refreshing_event_uid={(*refreshing_event_uid).clone()} |                                 refreshing_event_uid={(*refreshing_event_uid).clone()} | ||||||
|                                 user_info={props.user_info.clone()} |                                 user_info={props.user_info.clone()} | ||||||
|  |                                 external_calendars={props.external_calendars.clone()} | ||||||
|                                 on_event_context_menu={props.on_event_context_menu.clone()} |                                 on_event_context_menu={props.on_event_context_menu.clone()} | ||||||
|                                 on_calendar_context_menu={props.on_calendar_context_menu.clone()} |                                 on_calendar_context_menu={props.on_calendar_context_menu.clone()} | ||||||
|                                 selected_date={Some(*selected_date)} |                                 selected_date={Some(*selected_date)} | ||||||
| @@ -467,6 +507,7 @@ pub fn Calendar(props: &CalendarProps) -> Html { | |||||||
|                             on_event_click={on_event_click.clone()} |                             on_event_click={on_event_click.clone()} | ||||||
|                             refreshing_event_uid={(*refreshing_event_uid).clone()} |                             refreshing_event_uid={(*refreshing_event_uid).clone()} | ||||||
|                             user_info={props.user_info.clone()} |                             user_info={props.user_info.clone()} | ||||||
|  |                             external_calendars={props.external_calendars.clone()} | ||||||
|                             on_event_context_menu={props.on_event_context_menu.clone()} |                             on_event_context_menu={props.on_event_context_menu.clone()} | ||||||
|                             on_calendar_context_menu={props.on_calendar_context_menu.clone()} |                             on_calendar_context_menu={props.on_calendar_context_menu.clone()} | ||||||
|                             on_create_event={Some(on_create_event)} |                             on_create_event={Some(on_create_event)} | ||||||
| @@ -521,15 +562,6 @@ pub fn Calendar(props: &CalendarProps) -> Html { | |||||||
|                         } |                         } | ||||||
|                     }) |                     }) | ||||||
|                 }} |                 }} | ||||||
|                 on_update={{ |  | ||||||
|                     let show_create_modal = show_create_modal.clone(); |  | ||||||
|                     let create_event_data = create_event_data.clone(); |  | ||||||
|                     Callback::from(move |(_original_event, _updated_data): (VEvent, EventCreationData)| { |  | ||||||
|                         show_create_modal.set(false); |  | ||||||
|                         create_event_data.set(None); |  | ||||||
|                         // TODO: Handle actual event update |  | ||||||
|                     }) |  | ||||||
|                 }} |  | ||||||
|             /> |             /> | ||||||
|         </div> |         </div> | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -18,9 +18,45 @@ pub fn calendar_context_menu(props: &CalendarContextMenuProps) -> Html { | |||||||
|         return html! {}; |         return html! {}; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     // Smart positioning to keep menu within viewport | ||||||
|  |     let (x, y) = { | ||||||
|  |         let mut x = props.x; | ||||||
|  |         let mut y = props.y; | ||||||
|  |          | ||||||
|  |         // Try to get actual viewport dimensions | ||||||
|  |         if let Some(window) = web_sys::window() { | ||||||
|  |             if let (Ok(width), Ok(height)) = (window.inner_width(), window.inner_height()) { | ||||||
|  |                 if let (Some(w), Some(h)) = (width.as_f64(), height.as_f64()) { | ||||||
|  |                     let viewport_width = w as i32; | ||||||
|  |                     let viewport_height = h as i32; | ||||||
|  |                      | ||||||
|  |                     // Calendar context menu: "Create Event" with icon | ||||||
|  |                     let menu_width = 180; // "Create Event" text + icon + padding | ||||||
|  |                     let menu_height = 60; // Single item + padding + margins | ||||||
|  |                      | ||||||
|  |                     // Adjust horizontally if too close to right edge | ||||||
|  |                     if x + menu_width > viewport_width - 10 { | ||||||
|  |                         x = x.saturating_sub(menu_width); | ||||||
|  |                     } | ||||||
|  |                      | ||||||
|  |                     // Adjust vertically if too close to bottom edge | ||||||
|  |                     if y + menu_height > viewport_height - 10 { | ||||||
|  |                         y = y.saturating_sub(menu_height); | ||||||
|  |                     } | ||||||
|  |                      | ||||||
|  |                     // Ensure minimum margins from edges | ||||||
|  |                     x = x.max(5); | ||||||
|  |                     y = y.max(5); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |          | ||||||
|  |         (x, y) | ||||||
|  |     }; | ||||||
|  |  | ||||||
|     let style = format!( |     let style = format!( | ||||||
|         "position: fixed; left: {}px; top: {}px; z-index: 1001;", |         "position: fixed; left: {}px; top: {}px; z-index: 1001;", | ||||||
|         props.x, props.y |         x, y | ||||||
|     ); |     ); | ||||||
|  |  | ||||||
|     let on_create_event_click = { |     let on_create_event_click = { | ||||||
|   | |||||||
| @@ -10,6 +10,7 @@ pub struct CalendarListItemProps { | |||||||
|     pub on_color_picker_toggle: Callback<String>,    // calendar_path |     pub on_color_picker_toggle: Callback<String>,    // calendar_path | ||||||
|     pub available_colors: Vec<String>, |     pub available_colors: Vec<String>, | ||||||
|     pub on_context_menu: Callback<(MouseEvent, String)>, // (event, calendar_path) |     pub on_context_menu: Callback<(MouseEvent, String)>, // (event, calendar_path) | ||||||
|  |     pub on_visibility_toggle: Callback<String>,      // calendar_path | ||||||
| } | } | ||||||
|  |  | ||||||
| #[function_component(CalendarListItem)] | #[function_component(CalendarListItem)] | ||||||
| @@ -32,8 +33,22 @@ pub fn calendar_list_item(props: &CalendarListItemProps) -> Html { | |||||||
|         }) |         }) | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
|  |     let on_visibility_toggle = { | ||||||
|  |         let cal_path = props.calendar.path.clone(); | ||||||
|  |         let on_visibility_toggle = props.on_visibility_toggle.clone(); | ||||||
|  |         Callback::from(move |_| { | ||||||
|  |             on_visibility_toggle.emit(cal_path.clone()); | ||||||
|  |         }) | ||||||
|  |     }; | ||||||
|  |  | ||||||
|     html! { |     html! { | ||||||
|         <li key={props.calendar.path.clone()} oncontextmenu={on_context_menu}> |         <li key={props.calendar.path.clone()} oncontextmenu={on_context_menu}> | ||||||
|  |             <div class="calendar-info"> | ||||||
|  |                 <input | ||||||
|  |                     type="checkbox" | ||||||
|  |                     checked={props.calendar.is_visible} | ||||||
|  |                     onchange={on_visibility_toggle} | ||||||
|  |                 /> | ||||||
|                 <span class="calendar-color" |                 <span class="calendar-color" | ||||||
|                       style={format!("background-color: {}", props.calendar.color)} |                       style={format!("background-color: {}", props.calendar.color)} | ||||||
|                       onclick={on_color_click}> |                       onclick={on_color_click}> | ||||||
| @@ -70,6 +85,7 @@ pub fn calendar_list_item(props: &CalendarListItemProps) -> Html { | |||||||
|                     } |                     } | ||||||
|                 </span> |                 </span> | ||||||
|                 <span class="calendar-name">{&props.calendar.display_name}</span> |                 <span class="calendar-name">{&props.calendar.display_name}</span> | ||||||
|  |             </div> | ||||||
|         </li> |         </li> | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -20,9 +20,45 @@ pub fn context_menu(props: &ContextMenuProps) -> Html { | |||||||
|         return html! {}; |         return html! {}; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     // Smart positioning to keep menu within viewport | ||||||
|  |     let (x, y) = { | ||||||
|  |         let mut x = props.x; | ||||||
|  |         let mut y = props.y; | ||||||
|  |          | ||||||
|  |         // Try to get actual viewport dimensions | ||||||
|  |         if let Some(window) = web_sys::window() { | ||||||
|  |             if let (Ok(width), Ok(height)) = (window.inner_width(), window.inner_height()) { | ||||||
|  |                 if let (Some(w), Some(h)) = (width.as_f64(), height.as_f64()) { | ||||||
|  |                     let viewport_width = w as i32; | ||||||
|  |                     let viewport_height = h as i32; | ||||||
|  |                      | ||||||
|  |                     // Generic context menu: "Delete Calendar"  | ||||||
|  |                     let menu_width = 180; // "Delete Calendar" text + padding | ||||||
|  |                     let menu_height = 60; // Single item + padding + margins | ||||||
|  |                      | ||||||
|  |                     // Adjust horizontally if too close to right edge | ||||||
|  |                     if x + menu_width > viewport_width - 10 { | ||||||
|  |                         x = x.saturating_sub(menu_width); | ||||||
|  |                     } | ||||||
|  |                      | ||||||
|  |                     // Adjust vertically if too close to bottom edge | ||||||
|  |                     if y + menu_height > viewport_height - 10 { | ||||||
|  |                         y = y.saturating_sub(menu_height); | ||||||
|  |                     } | ||||||
|  |                      | ||||||
|  |                     // Ensure minimum margins from edges | ||||||
|  |                     x = x.max(5); | ||||||
|  |                     y = y.max(5); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |          | ||||||
|  |         (x, y) | ||||||
|  |     }; | ||||||
|  |  | ||||||
|     let style = format!( |     let style = format!( | ||||||
|         "position: fixed; left: {}px; top: {}px; z-index: 1001;", |         "position: fixed; left: {}px; top: {}px; z-index: 1001;", | ||||||
|         props.x, props.y |         x, y | ||||||
|     ); |     ); | ||||||
|  |  | ||||||
|     let on_delete_click = { |     let on_delete_click = { | ||||||
|   | |||||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @@ -35,9 +35,53 @@ pub fn event_context_menu(props: &EventContextMenuProps) -> Html { | |||||||
|         return html! {}; |         return html! {}; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     // Smart positioning to keep menu within viewport | ||||||
|  |     let (x, y) = { | ||||||
|  |         let mut x = props.x; | ||||||
|  |         let mut y = props.y; | ||||||
|  |          | ||||||
|  |         // Try to get actual viewport dimensions | ||||||
|  |         if let Some(window) = web_sys::window() { | ||||||
|  |             if let (Ok(width), Ok(height)) = (window.inner_width(), window.inner_height()) { | ||||||
|  |                 if let (Some(w), Some(h)) = (width.as_f64(), height.as_f64()) { | ||||||
|  |                     let viewport_width = w as i32; | ||||||
|  |                     let viewport_height = h as i32; | ||||||
|  |                      | ||||||
|  |                     // More accurate menu dimensions based on actual CSS and content | ||||||
|  |                     let menu_width = if props.event.as_ref().map_or(false, |e| e.rrule.is_some()) { | ||||||
|  |                         280 // Recurring: "Edit This and Future Events" is long text + padding | ||||||
|  |                     } else { | ||||||
|  |                         180 // Non-recurring: "Edit Event" + "Delete Event" + padding | ||||||
|  |                     }; | ||||||
|  |                     let menu_height = if props.event.as_ref().map_or(false, |e| e.rrule.is_some()) { | ||||||
|  |                         200 // 6 items × ~32px per item (12px padding top/bottom + text height + borders) | ||||||
|  |                     } else { | ||||||
|  |                         100 // 2 items × ~32px per item + some extra margin | ||||||
|  |                     }; | ||||||
|  |                      | ||||||
|  |                     // Adjust horizontally if too close to right edge | ||||||
|  |                     if x + menu_width > viewport_width - 10 { | ||||||
|  |                         x = x.saturating_sub(menu_width); | ||||||
|  |                     } | ||||||
|  |                      | ||||||
|  |                     // Adjust vertically if too close to bottom edge | ||||||
|  |                     if y + menu_height > viewport_height - 10 { | ||||||
|  |                         y = y.saturating_sub(menu_height); | ||||||
|  |                     } | ||||||
|  |                      | ||||||
|  |                     // Ensure minimum margins from edges | ||||||
|  |                     x = x.max(5); | ||||||
|  |                     y = y.max(5); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |          | ||||||
|  |         (x, y) | ||||||
|  |     }; | ||||||
|  |  | ||||||
|     let style = format!( |     let style = format!( | ||||||
|         "position: fixed; left: {}px; top: {}px; z-index: 1001;", |         "position: fixed; left: {}px; top: {}px; z-index: 1001;", | ||||||
|         props.x, props.y |         x, y | ||||||
|     ); |     ); | ||||||
|  |  | ||||||
|     // Check if the event is recurring |     // Check if the event is recurring | ||||||
|   | |||||||
							
								
								
									
										109
									
								
								frontend/src/components/event_form/advanced.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										109
									
								
								frontend/src/components/event_form/advanced.rs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,109 @@ | |||||||
|  | use super::types::*; | ||||||
|  | // Types are already imported from super::types::* | ||||||
|  | use wasm_bindgen::JsCast; | ||||||
|  | use web_sys::HtmlSelectElement; | ||||||
|  | use yew::prelude::*; | ||||||
|  |  | ||||||
|  | #[function_component(AdvancedTab)] | ||||||
|  | pub fn advanced_tab(props: &TabProps) -> Html { | ||||||
|  |     let data = &props.data; | ||||||
|  |      | ||||||
|  |     let on_status_change = { | ||||||
|  |         let data = data.clone(); | ||||||
|  |         Callback::from(move |e: Event| { | ||||||
|  |             if let Some(target) = e.target() { | ||||||
|  |                 if let Ok(select) = target.dyn_into::<HtmlSelectElement>() { | ||||||
|  |                     let mut event_data = (*data).clone(); | ||||||
|  |                     event_data.status = match select.value().as_str() { | ||||||
|  |                         "tentative" => EventStatus::Tentative, | ||||||
|  |                         "cancelled" => EventStatus::Cancelled, | ||||||
|  |                         _ => EventStatus::Confirmed, | ||||||
|  |                     }; | ||||||
|  |                     data.set(event_data); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         }) | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     let on_class_change = { | ||||||
|  |         let data = data.clone(); | ||||||
|  |         Callback::from(move |e: Event| { | ||||||
|  |             if let Some(target) = e.target() { | ||||||
|  |                 if let Ok(select) = target.dyn_into::<HtmlSelectElement>() { | ||||||
|  |                     let mut event_data = (*data).clone(); | ||||||
|  |                     event_data.class = match select.value().as_str() { | ||||||
|  |                         "private" => EventClass::Private, | ||||||
|  |                         "confidential" => EventClass::Confidential, | ||||||
|  |                         _ => EventClass::Public, | ||||||
|  |                     }; | ||||||
|  |                     data.set(event_data); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         }) | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     let on_priority_change = { | ||||||
|  |         let data = data.clone(); | ||||||
|  |         Callback::from(move |e: Event| { | ||||||
|  |             if let Some(target) = e.target() { | ||||||
|  |                 if let Ok(select) = target.dyn_into::<HtmlSelectElement>() { | ||||||
|  |                     let mut event_data = (*data).clone(); | ||||||
|  |                     let value = select.value(); | ||||||
|  |                     event_data.priority = if value.is_empty() { | ||||||
|  |                         None | ||||||
|  |                     } else { | ||||||
|  |                         value.parse::<u8>().ok().filter(|&p| p <= 9) | ||||||
|  |                     }; | ||||||
|  |                     data.set(event_data); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         }) | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     html! { | ||||||
|  |         <div class="tab-panel"> | ||||||
|  |             <div class="form-row"> | ||||||
|  |                 <div class="form-group"> | ||||||
|  |                     <label for="event-status">{"Status"}</label> | ||||||
|  |                     <select | ||||||
|  |                         id="event-status" | ||||||
|  |                         class="form-input" | ||||||
|  |                         onchange={on_status_change} | ||||||
|  |                     > | ||||||
|  |                         <option value="confirmed" selected={matches!(data.status, EventStatus::Confirmed)}>{"Confirmed"}</option> | ||||||
|  |                         <option value="tentative" selected={matches!(data.status, EventStatus::Tentative)}>{"Tentative"}</option> | ||||||
|  |                         <option value="cancelled" selected={matches!(data.status, EventStatus::Cancelled)}>{"Cancelled"}</option> | ||||||
|  |                     </select> | ||||||
|  |                 </div> | ||||||
|  |  | ||||||
|  |                 <div class="form-group"> | ||||||
|  |                     <label for="event-class">{"Privacy"}</label> | ||||||
|  |                     <select | ||||||
|  |                         id="event-class" | ||||||
|  |                         class="form-input" | ||||||
|  |                         onchange={on_class_change} | ||||||
|  |                     > | ||||||
|  |                         <option value="public" selected={matches!(data.class, EventClass::Public)}>{"Public"}</option> | ||||||
|  |                         <option value="private" selected={matches!(data.class, EventClass::Private)}>{"Private"}</option> | ||||||
|  |                         <option value="confidential" selected={matches!(data.class, EventClass::Confidential)}>{"Confidential"}</option> | ||||||
|  |                     </select> | ||||||
|  |                 </div> | ||||||
|  |             </div> | ||||||
|  |  | ||||||
|  |             <div class="form-group"> | ||||||
|  |                 <label for="event-priority">{"Priority"}</label> | ||||||
|  |                 <select  | ||||||
|  |                     id="event-priority"  | ||||||
|  |                     class="form-input" | ||||||
|  |                     onchange={on_priority_change} | ||||||
|  |                 > | ||||||
|  |                     <option value="" selected={data.priority.is_none()}>{"Not set"}</option> | ||||||
|  |                     <option value="1" selected={data.priority == Some(1)}>{"High"}</option> | ||||||
|  |                     <option value="5" selected={data.priority == Some(5)}>{"Medium"}</option> | ||||||
|  |                     <option value="9" selected={data.priority == Some(9)}>{"Low"}</option> | ||||||
|  |                 </select> | ||||||
|  |                 <p class="form-help-text">{"Set the importance level for this event."}</p> | ||||||
|  |             </div> | ||||||
|  |         </div> | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										730
									
								
								frontend/src/components/event_form/basic_details.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										730
									
								
								frontend/src/components/event_form/basic_details.rs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,730 @@ | |||||||
|  | use super::types::*; | ||||||
|  | // Types are already imported from super::types::* | ||||||
|  | use chrono::{Datelike, NaiveDate}; | ||||||
|  | use wasm_bindgen::JsCast; | ||||||
|  | use web_sys::{HtmlInputElement, HtmlSelectElement, HtmlTextAreaElement}; | ||||||
|  | use yew::prelude::*; | ||||||
|  |  | ||||||
|  | #[function_component(BasicDetailsTab)] | ||||||
|  | pub fn basic_details_tab(props: &TabProps) -> Html { | ||||||
|  |     let data = &props.data; | ||||||
|  |      | ||||||
|  |     // Event handlers | ||||||
|  |     let on_title_input = { | ||||||
|  |         let data = data.clone(); | ||||||
|  |         Callback::from(move |e: InputEvent| { | ||||||
|  |             if let Some(target) = e.target() { | ||||||
|  |                 if let Ok(input) = target.dyn_into::<HtmlInputElement>() { | ||||||
|  |                     let mut event_data = (*data).clone(); | ||||||
|  |                     event_data.title = input.value(); | ||||||
|  |                     if !event_data.changed_fields.contains(&"title".to_string()) { | ||||||
|  |                         event_data.changed_fields.push("title".to_string()); | ||||||
|  |                     } | ||||||
|  |                     data.set(event_data); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         }) | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     let on_description_input = { | ||||||
|  |         let data = data.clone(); | ||||||
|  |         Callback::from(move |e: InputEvent| { | ||||||
|  |             if let Some(target) = e.target() { | ||||||
|  |                 if let Ok(textarea) = target.dyn_into::<HtmlTextAreaElement>() { | ||||||
|  |                     let mut event_data = (*data).clone(); | ||||||
|  |                     event_data.description = textarea.value(); | ||||||
|  |                     data.set(event_data); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         }) | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     let on_calendar_change = { | ||||||
|  |         let data = data.clone(); | ||||||
|  |         Callback::from(move |e: Event| { | ||||||
|  |             if let Some(target) = e.target() { | ||||||
|  |                 if let Ok(select) = target.dyn_into::<HtmlSelectElement>() { | ||||||
|  |                     let mut event_data = (*data).clone(); | ||||||
|  |                     let value = select.value(); | ||||||
|  |                     let new_calendar = if value.is_empty() { None } else { Some(value) }; | ||||||
|  |                     if event_data.selected_calendar != new_calendar { | ||||||
|  |                         event_data.selected_calendar = new_calendar; | ||||||
|  |                         if !event_data.changed_fields.contains(&"selected_calendar".to_string()) { | ||||||
|  |                             event_data.changed_fields.push("selected_calendar".to_string()); | ||||||
|  |                         } | ||||||
|  |                     } | ||||||
|  |                     data.set(event_data); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         }) | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     let on_all_day_change = { | ||||||
|  |         let data = data.clone(); | ||||||
|  |         Callback::from(move |e: Event| { | ||||||
|  |             if let Some(target) = e.target() { | ||||||
|  |                 if let Ok(input) = target.dyn_into::<HtmlInputElement>() { | ||||||
|  |                     let mut event_data = (*data).clone(); | ||||||
|  |                     event_data.all_day = input.checked(); | ||||||
|  |                     data.set(event_data); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         }) | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     let on_recurrence_change = { | ||||||
|  |         let data = data.clone(); | ||||||
|  |         Callback::from(move |e: Event| { | ||||||
|  |             if let Some(target) = e.target() { | ||||||
|  |                 if let Ok(select) = target.dyn_into::<HtmlSelectElement>() { | ||||||
|  |                     let mut event_data = (*data).clone(); | ||||||
|  |                     event_data.recurrence = match select.value().as_str() { | ||||||
|  |                         "daily" => RecurrenceType::Daily, | ||||||
|  |                         "weekly" => RecurrenceType::Weekly, | ||||||
|  |                         "monthly" => RecurrenceType::Monthly, | ||||||
|  |                         "yearly" => RecurrenceType::Yearly, | ||||||
|  |                         _ => RecurrenceType::None, | ||||||
|  |                     }; | ||||||
|  |                     // Reset recurrence-related fields when changing type | ||||||
|  |                     event_data.recurrence_days = vec![false; 7]; | ||||||
|  |                     event_data.recurrence_interval = 1; | ||||||
|  |                     event_data.recurrence_until = None; | ||||||
|  |                     event_data.recurrence_count = None; | ||||||
|  |                     event_data.monthly_by_day = None; | ||||||
|  |                     event_data.monthly_by_monthday = None; | ||||||
|  |                     event_data.yearly_by_month = vec![false; 12]; | ||||||
|  |                     data.set(event_data); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         }) | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     let on_reminder_change = { | ||||||
|  |         let data = data.clone(); | ||||||
|  |         Callback::from(move |e: Event| { | ||||||
|  |             if let Some(target) = e.target() { | ||||||
|  |                 if let Ok(select) = target.dyn_into::<HtmlSelectElement>() { | ||||||
|  |                     let mut event_data = (*data).clone(); | ||||||
|  |                     event_data.reminder = match select.value().as_str() { | ||||||
|  |                         "15min" => ReminderType::Minutes15, | ||||||
|  |                         "30min" => ReminderType::Minutes30, | ||||||
|  |                         "1hour" => ReminderType::Hour1, | ||||||
|  |                         "1day" => ReminderType::Day1, | ||||||
|  |                         "2days" => ReminderType::Days2, | ||||||
|  |                         "1week" => ReminderType::Week1, | ||||||
|  |                         _ => ReminderType::None, | ||||||
|  |                     }; | ||||||
|  |                     data.set(event_data); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         }) | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     let on_recurrence_interval_change = { | ||||||
|  |         let data = data.clone(); | ||||||
|  |         Callback::from(move |e: Event| { | ||||||
|  |             if let Some(input) = e.target_dyn_into::<HtmlInputElement>() { | ||||||
|  |                 if let Ok(interval) = input.value().parse::<u32>() { | ||||||
|  |                     let mut event_data = (*data).clone(); | ||||||
|  |                     event_data.recurrence_interval = interval.max(1); | ||||||
|  |                     data.set(event_data); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         }) | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     let on_recurrence_until_change = { | ||||||
|  |         let data = data.clone(); | ||||||
|  |         Callback::from(move |e: Event| { | ||||||
|  |             if let Some(input) = e.target_dyn_into::<HtmlInputElement>() { | ||||||
|  |                 let mut event_data = (*data).clone(); | ||||||
|  |                 if input.value().is_empty() { | ||||||
|  |                     event_data.recurrence_until = None; | ||||||
|  |                 } else if let Ok(date) = NaiveDate::parse_from_str(&input.value(), "%Y-%m-%d") { | ||||||
|  |                     event_data.recurrence_until = Some(date); | ||||||
|  |                 } | ||||||
|  |                 data.set(event_data); | ||||||
|  |             } | ||||||
|  |         }) | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     let on_recurrence_count_change = { | ||||||
|  |         let data = data.clone(); | ||||||
|  |         Callback::from(move |e: Event| { | ||||||
|  |             if let Some(input) = e.target_dyn_into::<HtmlInputElement>() { | ||||||
|  |                 let mut event_data = (*data).clone(); | ||||||
|  |                 if input.value().is_empty() { | ||||||
|  |                     event_data.recurrence_count = None; | ||||||
|  |                 } else if let Ok(count) = input.value().parse::<u32>() { | ||||||
|  |                     event_data.recurrence_count = Some(count.max(1)); | ||||||
|  |                 } | ||||||
|  |                 data.set(event_data); | ||||||
|  |             } | ||||||
|  |         }) | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     let on_monthly_by_monthday_change = { | ||||||
|  |         let data = data.clone(); | ||||||
|  |         Callback::from(move |e: Event| { | ||||||
|  |             if let Some(input) = e.target_dyn_into::<HtmlInputElement>() { | ||||||
|  |                 let mut event_data = (*data).clone(); | ||||||
|  |                 if input.value().is_empty() { | ||||||
|  |                     event_data.monthly_by_monthday = None; | ||||||
|  |                 } else if let Ok(day) = input.value().parse::<u8>() { | ||||||
|  |                     if day >= 1 && day <= 31 { | ||||||
|  |                         event_data.monthly_by_monthday = Some(day); | ||||||
|  |                         event_data.monthly_by_day = None; // Clear the other option | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |                 data.set(event_data); | ||||||
|  |             } | ||||||
|  |         }) | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     let on_monthly_by_day_change = { | ||||||
|  |         let data = data.clone(); | ||||||
|  |         Callback::from(move |e: Event| { | ||||||
|  |             if let Some(select) = e.target_dyn_into::<HtmlSelectElement>() { | ||||||
|  |                 let mut event_data = (*data).clone(); | ||||||
|  |                 if select.value().is_empty() || select.value() == "none" { | ||||||
|  |                     event_data.monthly_by_day = None; | ||||||
|  |                 } else { | ||||||
|  |                     event_data.monthly_by_day = Some(select.value()); | ||||||
|  |                     event_data.monthly_by_monthday = None; // Clear the other option | ||||||
|  |                 } | ||||||
|  |                 data.set(event_data); | ||||||
|  |             } | ||||||
|  |         }) | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     let on_weekday_change = { | ||||||
|  |         let data = data.clone(); | ||||||
|  |         move |day_index: usize| { | ||||||
|  |             let data = data.clone(); | ||||||
|  |             Callback::from(move |e: Event| { | ||||||
|  |                 if let Some(input) = e.target_dyn_into::<HtmlInputElement>() { | ||||||
|  |                     let mut event_data = (*data).clone(); | ||||||
|  |                     if day_index < event_data.recurrence_days.len() { | ||||||
|  |                         event_data.recurrence_days[day_index] = input.checked(); | ||||||
|  |                         data.set(event_data); | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |             }) | ||||||
|  |         } | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     let on_yearly_month_change = { | ||||||
|  |         let data = data.clone(); | ||||||
|  |         move |month_index: usize| { | ||||||
|  |             let data = data.clone(); | ||||||
|  |             Callback::from(move |e: Event| { | ||||||
|  |                 if let Some(input) = e.target_dyn_into::<HtmlInputElement>() { | ||||||
|  |                     let mut event_data = (*data).clone(); | ||||||
|  |                     if month_index < event_data.yearly_by_month.len() { | ||||||
|  |                         event_data.yearly_by_month[month_index] = input.checked(); | ||||||
|  |                         data.set(event_data); | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |             }) | ||||||
|  |         } | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     let on_start_date_change = { | ||||||
|  |         let data = data.clone(); | ||||||
|  |         Callback::from(move |e: Event| { | ||||||
|  |             if let Some(input) = e.target_dyn_into::<HtmlInputElement>() { | ||||||
|  |                 if let Ok(date) = NaiveDate::parse_from_str(&input.value(), "%Y-%m-%d") { | ||||||
|  |                     let mut event_data = (*data).clone(); | ||||||
|  |                     event_data.start_date = date; | ||||||
|  |                     data.set(event_data); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         }) | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     let on_start_time_change = { | ||||||
|  |         let data = data.clone(); | ||||||
|  |         Callback::from(move |e: Event| { | ||||||
|  |             if let Some(input) = e.target_dyn_into::<HtmlInputElement>() { | ||||||
|  |                 if let Ok(time) = chrono::NaiveTime::parse_from_str(&input.value(), "%H:%M") { | ||||||
|  |                     let mut event_data = (*data).clone(); | ||||||
|  |                     event_data.start_time = time; | ||||||
|  |                     data.set(event_data); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         }) | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     let on_end_date_change = { | ||||||
|  |         let data = data.clone(); | ||||||
|  |         Callback::from(move |e: Event| { | ||||||
|  |             if let Some(input) = e.target_dyn_into::<HtmlInputElement>() { | ||||||
|  |                 if let Ok(date) = NaiveDate::parse_from_str(&input.value(), "%Y-%m-%d") { | ||||||
|  |                     let mut event_data = (*data).clone(); | ||||||
|  |                     event_data.end_date = date; | ||||||
|  |                     data.set(event_data); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         }) | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     let on_end_time_change = { | ||||||
|  |         let data = data.clone(); | ||||||
|  |         Callback::from(move |e: Event| { | ||||||
|  |             if let Some(input) = e.target_dyn_into::<HtmlInputElement>() { | ||||||
|  |                 if let Ok(time) = chrono::NaiveTime::parse_from_str(&input.value(), "%H:%M") { | ||||||
|  |                     let mut event_data = (*data).clone(); | ||||||
|  |                     event_data.end_time = time; | ||||||
|  |                     data.set(event_data); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         }) | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     let on_location_input = { | ||||||
|  |         let data = data.clone(); | ||||||
|  |         Callback::from(move |e: InputEvent| { | ||||||
|  |             if let Some(target) = e.target() { | ||||||
|  |                 if let Ok(input) = target.dyn_into::<HtmlInputElement>() { | ||||||
|  |                     let mut event_data = (*data).clone(); | ||||||
|  |                     event_data.location = input.value(); | ||||||
|  |                     data.set(event_data); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         }) | ||||||
|  |     }; | ||||||
|  |      | ||||||
|  |     html! { | ||||||
|  |         <div class="tab-panel"> | ||||||
|  |             <div class="form-group"> | ||||||
|  |                 <label for="event-title">{"Event Title *"}</label> | ||||||
|  |                 <input | ||||||
|  |                     type="text" | ||||||
|  |                     id="event-title" | ||||||
|  |                     class="form-input" | ||||||
|  |                     value={data.title.clone()} | ||||||
|  |                     oninput={on_title_input} | ||||||
|  |                     placeholder="Add a title" | ||||||
|  |                     required=true | ||||||
|  |                 /> | ||||||
|  |             </div> | ||||||
|  |  | ||||||
|  |             <div class="form-group"> | ||||||
|  |                 <label for="event-description">{"Description"}</label> | ||||||
|  |                 <textarea | ||||||
|  |                     id="event-description" | ||||||
|  |                     class="form-input" | ||||||
|  |                     value={data.description.clone()} | ||||||
|  |                     oninput={on_description_input} | ||||||
|  |                     placeholder="Add a description" | ||||||
|  |                     rows="3" | ||||||
|  |                 ></textarea> | ||||||
|  |             </div> | ||||||
|  |  | ||||||
|  |             <div class="form-group"> | ||||||
|  |                 <label for="event-calendar">{"Calendar"}</label> | ||||||
|  |                 <select | ||||||
|  |                     id="event-calendar" | ||||||
|  |                     class="form-input" | ||||||
|  |                     onchange={on_calendar_change} | ||||||
|  |                 > | ||||||
|  |                     <option value="">{"Select Calendar"}</option> | ||||||
|  |                     { | ||||||
|  |                         props.available_calendars.iter().map(|calendar| { | ||||||
|  |                             html! { | ||||||
|  |                                 <option | ||||||
|  |                                     key={calendar.path.clone()} | ||||||
|  |                                     value={calendar.path.clone()} | ||||||
|  |                                     selected={data.selected_calendar.as_ref() == Some(&calendar.path)} | ||||||
|  |                                 > | ||||||
|  |                                     {&calendar.display_name} | ||||||
|  |                                 </option> | ||||||
|  |                             } | ||||||
|  |                         }).collect::<Html>() | ||||||
|  |                     } | ||||||
|  |                 </select> | ||||||
|  |             </div> | ||||||
|  |  | ||||||
|  |             <div class="form-group"> | ||||||
|  |                 <label class="checkbox-label"> | ||||||
|  |                     <input | ||||||
|  |                         type="checkbox" | ||||||
|  |                         checked={data.all_day} | ||||||
|  |                         onchange={on_all_day_change} | ||||||
|  |                     /> | ||||||
|  |                     {" All Day"} | ||||||
|  |                 </label> | ||||||
|  |             </div> | ||||||
|  |  | ||||||
|  |             <div class="form-row"> | ||||||
|  |                 <div class="form-group"> | ||||||
|  |                     <label for="event-recurrence-basic">{"Repeat"}</label> | ||||||
|  |                     <select | ||||||
|  |                         id="event-recurrence-basic" | ||||||
|  |                         class="form-input" | ||||||
|  |                         onchange={on_recurrence_change} | ||||||
|  |                     > | ||||||
|  |                         <option value="none" selected={matches!(data.recurrence, RecurrenceType::None)}>{"Does not repeat"}</option> | ||||||
|  |                         <option value="daily" selected={matches!(data.recurrence, RecurrenceType::Daily)}>{"Daily"}</option> | ||||||
|  |                         <option value="weekly" selected={matches!(data.recurrence, RecurrenceType::Weekly)}>{"Weekly"}</option> | ||||||
|  |                         <option value="monthly" selected={matches!(data.recurrence, RecurrenceType::Monthly)}>{"Monthly"}</option> | ||||||
|  |                         <option value="yearly" selected={matches!(data.recurrence, RecurrenceType::Yearly)}>{"Yearly"}</option> | ||||||
|  |                     </select> | ||||||
|  |                 </div> | ||||||
|  |  | ||||||
|  |                 <div class="form-group"> | ||||||
|  |                     <label for="event-reminder-basic">{"Reminder"}</label> | ||||||
|  |                     <select | ||||||
|  |                         id="event-reminder-basic" | ||||||
|  |                         class="form-input" | ||||||
|  |                         onchange={on_reminder_change} | ||||||
|  |                     > | ||||||
|  |                         <option value="none" selected={matches!(data.reminder, ReminderType::None)}>{"None"}</option> | ||||||
|  |                         <option value="15min" selected={matches!(data.reminder, ReminderType::Minutes15)}>{"15 minutes before"}</option> | ||||||
|  |                         <option value="30min" selected={matches!(data.reminder, ReminderType::Minutes30)}>{"30 minutes before"}</option> | ||||||
|  |                         <option value="1hour" selected={matches!(data.reminder, ReminderType::Hour1)}>{"1 hour before"}</option> | ||||||
|  |                         <option value="1day" selected={matches!(data.reminder, ReminderType::Day1)}>{"1 day before"}</option> | ||||||
|  |                     </select> | ||||||
|  |                 </div> | ||||||
|  |             </div> | ||||||
|  |  | ||||||
|  |             // RECURRENCE OPTIONS GO RIGHT HERE - directly below repeat/reminder! | ||||||
|  |             if matches!(data.recurrence, RecurrenceType::Weekly) { | ||||||
|  |                 <div class="form-group"> | ||||||
|  |                     <label>{"Repeat on"}</label> | ||||||
|  |                     <div class="weekday-selection"> | ||||||
|  |                         { | ||||||
|  |                             ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"] | ||||||
|  |                                 .iter() | ||||||
|  |                                 .enumerate() | ||||||
|  |                                 .map(|(i, day)| { | ||||||
|  |                                     let day_checked = data.recurrence_days.get(i).cloned().unwrap_or(false); | ||||||
|  |                                     let on_change = on_weekday_change(i); | ||||||
|  |                                     html! { | ||||||
|  |                                         <label key={i} class="weekday-checkbox"> | ||||||
|  |                                             <input | ||||||
|  |                                                 type="checkbox" | ||||||
|  |                                                 checked={day_checked} | ||||||
|  |                                                 onchange={on_change} | ||||||
|  |                                             /> | ||||||
|  |                                             <span class="weekday-label">{day}</span> | ||||||
|  |                                         </label> | ||||||
|  |                                     } | ||||||
|  |                                 }) | ||||||
|  |                                 .collect::<Html>() | ||||||
|  |                         } | ||||||
|  |                     </div> | ||||||
|  |                 </div> | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             if !matches!(data.recurrence, RecurrenceType::None) { | ||||||
|  |                 <div class="recurrence-options"> | ||||||
|  |                     <div class="form-row"> | ||||||
|  |                         <div class="form-group"> | ||||||
|  |                             <label for="recurrence-interval">{"Every"}</label> | ||||||
|  |                             <div class="interval-input"> | ||||||
|  |                                 <input | ||||||
|  |                                     id="recurrence-interval" | ||||||
|  |                                     type="number" | ||||||
|  |                                     class="form-input" | ||||||
|  |                                     value={data.recurrence_interval.to_string()} | ||||||
|  |                                     min="1" | ||||||
|  |                                     max="999" | ||||||
|  |                                     onchange={on_recurrence_interval_change} | ||||||
|  |                                 /> | ||||||
|  |                                 <span class="interval-unit"> | ||||||
|  |                                     {match data.recurrence { | ||||||
|  |                                         RecurrenceType::Daily => if data.recurrence_interval == 1 { "day" } else { "days" }, | ||||||
|  |                                         RecurrenceType::Weekly => if data.recurrence_interval == 1 { "week" } else { "weeks" }, | ||||||
|  |                                         RecurrenceType::Monthly => if data.recurrence_interval == 1 { "month" } else { "months" }, | ||||||
|  |                                         RecurrenceType::Yearly => if data.recurrence_interval == 1 { "year" } else { "years" }, | ||||||
|  |                                         RecurrenceType::None => "", | ||||||
|  |                                     }} | ||||||
|  |                                 </span> | ||||||
|  |                             </div> | ||||||
|  |                         </div> | ||||||
|  |  | ||||||
|  |                         <div class="form-group"> | ||||||
|  |                             <label>{"Ends"}</label> | ||||||
|  |                             <div class="end-options"> | ||||||
|  |                                 <div class="end-option"> | ||||||
|  |                                     <label class="radio-label"> | ||||||
|  |                                         <input | ||||||
|  |                                             type="radio" | ||||||
|  |                                             name="recurrence-end" | ||||||
|  |                                             value="never" | ||||||
|  |                                             checked={data.recurrence_until.is_none() && data.recurrence_count.is_none()} | ||||||
|  |                                             onchange={{ | ||||||
|  |                                                 let data = data.clone(); | ||||||
|  |                                                 Callback::from(move |_| { | ||||||
|  |                                                     let mut new_data = (*data).clone(); | ||||||
|  |                                                     new_data.recurrence_until = None; | ||||||
|  |                                                     new_data.recurrence_count = None; | ||||||
|  |                                                     data.set(new_data); | ||||||
|  |                                                 }) | ||||||
|  |                                             }} | ||||||
|  |                                         /> | ||||||
|  |                                         {"Never"} | ||||||
|  |                                     </label> | ||||||
|  |                                 </div> | ||||||
|  |  | ||||||
|  |                                 <div class="end-option"> | ||||||
|  |                                     <label class="radio-label"> | ||||||
|  |                                         <input | ||||||
|  |                                             type="radio" | ||||||
|  |                                             name="recurrence-end" | ||||||
|  |                                             value="until" | ||||||
|  |                                             checked={data.recurrence_until.is_some()} | ||||||
|  |                                             onchange={{ | ||||||
|  |                                                 let data = data.clone(); | ||||||
|  |                                                 Callback::from(move |_| { | ||||||
|  |                                                     let mut new_data = (*data).clone(); | ||||||
|  |                                                     new_data.recurrence_count = None; | ||||||
|  |                                                     new_data.recurrence_until = Some(new_data.start_date); | ||||||
|  |                                                     data.set(new_data); | ||||||
|  |                                                 }) | ||||||
|  |                                             }} | ||||||
|  |                                         /> | ||||||
|  |                                         {"Until"} | ||||||
|  |                                     </label> | ||||||
|  |                                     <input | ||||||
|  |                                         type="date" | ||||||
|  |                                         class="form-input" | ||||||
|  |                                         value={data.recurrence_until.map(|d| d.format("%Y-%m-%d").to_string()).unwrap_or_default()} | ||||||
|  |                                         onchange={on_recurrence_until_change} | ||||||
|  |                                     /> | ||||||
|  |                                 </div> | ||||||
|  |  | ||||||
|  |                                 <div class="end-option"> | ||||||
|  |                                     <label class="radio-label"> | ||||||
|  |                                         <input | ||||||
|  |                                             type="radio" | ||||||
|  |                                             name="recurrence-end" | ||||||
|  |                                             value="count" | ||||||
|  |                                             checked={data.recurrence_count.is_some()} | ||||||
|  |                                             onchange={{ | ||||||
|  |                                                 let data = data.clone(); | ||||||
|  |                                                 Callback::from(move |_| { | ||||||
|  |                                                     let mut new_data = (*data).clone(); | ||||||
|  |                                                     new_data.recurrence_until = None; | ||||||
|  |                                                     new_data.recurrence_count = Some(10); // Default count | ||||||
|  |                                                     data.set(new_data); | ||||||
|  |                                                 }) | ||||||
|  |                                             }} | ||||||
|  |                                         /> | ||||||
|  |                                         {"After"} | ||||||
|  |                                     </label> | ||||||
|  |                                     <input | ||||||
|  |                                         type="number" | ||||||
|  |                                         class="form-input count-input" | ||||||
|  |                                         value={data.recurrence_count.map(|c| c.to_string()).unwrap_or_default()} | ||||||
|  |                                         min="1" | ||||||
|  |                                         max="999" | ||||||
|  |                                         placeholder="1" | ||||||
|  |                                         onchange={on_recurrence_count_change} | ||||||
|  |                                     /> | ||||||
|  |                                     <span class="count-unit">{"occurrences"}</span> | ||||||
|  |                                 </div> | ||||||
|  |                             </div> | ||||||
|  |                         </div> | ||||||
|  |                     </div> | ||||||
|  |                      | ||||||
|  |                     // Monthly specific options | ||||||
|  |                     if matches!(data.recurrence, RecurrenceType::Monthly) { | ||||||
|  |                         <div class="form-group"> | ||||||
|  |                             <label>{"Repeat by"}</label> | ||||||
|  |                             <div class="monthly-options"> | ||||||
|  |                                 <div class="monthly-option"> | ||||||
|  |                                     <label class="radio-label"> | ||||||
|  |                                         <input | ||||||
|  |                                             type="radio" | ||||||
|  |                                             name="monthly-type" | ||||||
|  |                                             checked={data.monthly_by_monthday.is_some()} | ||||||
|  |                                             onchange={{ | ||||||
|  |                                                 let data = data.clone(); | ||||||
|  |                                                 Callback::from(move |_| { | ||||||
|  |                                                     let mut new_data = (*data).clone(); | ||||||
|  |                                                     new_data.monthly_by_day = None; | ||||||
|  |                                                     new_data.monthly_by_monthday = Some(new_data.start_date.day() as u8); | ||||||
|  |                                                     data.set(new_data); | ||||||
|  |                                                 }) | ||||||
|  |                                             }} | ||||||
|  |                                         /> | ||||||
|  |                                         {"Day of month:"} | ||||||
|  |                                     </label> | ||||||
|  |                                     <input | ||||||
|  |                                         type="number" | ||||||
|  |                                         class="form-input day-input" | ||||||
|  |                                         value={data.monthly_by_monthday.map(|d| d.to_string()).unwrap_or_else(|| data.start_date.day().to_string())} | ||||||
|  |                                         min="1" | ||||||
|  |                                         max="31" | ||||||
|  |                                         onchange={on_monthly_by_monthday_change} | ||||||
|  |                                     /> | ||||||
|  |                                 </div> | ||||||
|  |  | ||||||
|  |                                 <div class="monthly-option"> | ||||||
|  |                                     <label class="radio-label"> | ||||||
|  |                                         <input | ||||||
|  |                                             type="radio" | ||||||
|  |                                             name="monthly-type" | ||||||
|  |                                             checked={data.monthly_by_day.is_some()} | ||||||
|  |                                             onchange={{ | ||||||
|  |                                                 let data = data.clone(); | ||||||
|  |                                                 Callback::from(move |_| { | ||||||
|  |                                                     let mut new_data = (*data).clone(); | ||||||
|  |                                                     new_data.monthly_by_monthday = None; | ||||||
|  |                                                     new_data.monthly_by_day = Some("1MO".to_string()); // Default to first Monday | ||||||
|  |                                                     data.set(new_data); | ||||||
|  |                                                 }) | ||||||
|  |                                             }} | ||||||
|  |                                         /> | ||||||
|  |                                         {"Day of week:"} | ||||||
|  |                                     </label> | ||||||
|  |                                     <select | ||||||
|  |                                         class="form-input" | ||||||
|  |                                         value={data.monthly_by_day.clone().unwrap_or_default()} | ||||||
|  |                                         onchange={on_monthly_by_day_change} | ||||||
|  |                                     > | ||||||
|  |                                         <option value="none">{"Select..."}</option> | ||||||
|  |                                         <option value="1MO">{"First Monday"}</option> | ||||||
|  |                                         <option value="1TU">{"First Tuesday"}</option> | ||||||
|  |                                         <option value="1WE">{"First Wednesday"}</option> | ||||||
|  |                                         <option value="1TH">{"First Thursday"}</option> | ||||||
|  |                                         <option value="1FR">{"First Friday"}</option> | ||||||
|  |                                         <option value="1SA">{"First Saturday"}</option> | ||||||
|  |                                         <option value="1SU">{"First Sunday"}</option> | ||||||
|  |                                         <option value="2MO">{"Second Monday"}</option> | ||||||
|  |                                         <option value="2TU">{"Second Tuesday"}</option> | ||||||
|  |                                         <option value="2WE">{"Second Wednesday"}</option> | ||||||
|  |                                         <option value="2TH">{"Second Thursday"}</option> | ||||||
|  |                                         <option value="2FR">{"Second Friday"}</option> | ||||||
|  |                                         <option value="2SA">{"Second Saturday"}</option> | ||||||
|  |                                         <option value="2SU">{"Second Sunday"}</option> | ||||||
|  |                                         <option value="3MO">{"Third Monday"}</option> | ||||||
|  |                                         <option value="3TU">{"Third Tuesday"}</option> | ||||||
|  |                                         <option value="3WE">{"Third Wednesday"}</option> | ||||||
|  |                                         <option value="3TH">{"Third Thursday"}</option> | ||||||
|  |                                         <option value="3FR">{"Third Friday"}</option> | ||||||
|  |                                         <option value="3SA">{"Third Saturday"}</option> | ||||||
|  |                                         <option value="3SU">{"Third Sunday"}</option> | ||||||
|  |                                         <option value="4MO">{"Fourth Monday"}</option> | ||||||
|  |                                         <option value="4TU">{"Fourth Tuesday"}</option> | ||||||
|  |                                         <option value="4WE">{"Fourth Wednesday"}</option> | ||||||
|  |                                         <option value="4TH">{"Fourth Thursday"}</option> | ||||||
|  |                                         <option value="4FR">{"Fourth Friday"}</option> | ||||||
|  |                                         <option value="4SA">{"Fourth Saturday"}</option> | ||||||
|  |                                         <option value="4SU">{"Fourth Sunday"}</option> | ||||||
|  |                                         <option value="-1MO">{"Last Monday"}</option> | ||||||
|  |                                         <option value="-1TU">{"Last Tuesday"}</option> | ||||||
|  |                                         <option value="-1WE">{"Last Wednesday"}</option> | ||||||
|  |                                         <option value="-1TH">{"Last Thursday"}</option> | ||||||
|  |                                         <option value="-1FR">{"Last Friday"}</option> | ||||||
|  |                                         <option value="-1SA">{"Last Saturday"}</option> | ||||||
|  |                                         <option value="-1SU">{"Last Sunday"}</option> | ||||||
|  |                                     </select> | ||||||
|  |                                 </div> | ||||||
|  |                             </div> | ||||||
|  |                         </div> | ||||||
|  |                     } | ||||||
|  |                      | ||||||
|  |                     // Yearly specific options   | ||||||
|  |                     if matches!(data.recurrence, RecurrenceType::Yearly) { | ||||||
|  |                         <div class="form-group"> | ||||||
|  |                             <label>{"Repeat in months"}</label> | ||||||
|  |                             <div class="yearly-months"> | ||||||
|  |                                 { | ||||||
|  |                                     ["Jan", "Feb", "Mar", "Apr", "May", "Jun",  | ||||||
|  |                                      "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] | ||||||
|  |                                         .iter() | ||||||
|  |                                         .enumerate() | ||||||
|  |                                         .map(|(i, month)| { | ||||||
|  |                                             let month_checked = data.yearly_by_month.get(i).cloned().unwrap_or(false); | ||||||
|  |                                             let on_change = on_yearly_month_change(i); | ||||||
|  |                                             html! { | ||||||
|  |                                                 <label key={i} class="month-checkbox"> | ||||||
|  |                                                     <input | ||||||
|  |                                                         type="checkbox" | ||||||
|  |                                                         checked={month_checked} | ||||||
|  |                                                         onchange={on_change} | ||||||
|  |                                                     /> | ||||||
|  |                                                     <span class="month-label">{month}</span> | ||||||
|  |                                                 </label> | ||||||
|  |                                             } | ||||||
|  |                                         }) | ||||||
|  |                                         .collect::<Html>() | ||||||
|  |                                 } | ||||||
|  |                             </div> | ||||||
|  |                         </div> | ||||||
|  |                     } | ||||||
|  |                 </div> | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             // Date and time fields go here AFTER recurrence options | ||||||
|  |             <div class="form-row"> | ||||||
|  |                 <div class="form-group"> | ||||||
|  |                     <label for="start-date">{"Start Date *"}</label> | ||||||
|  |                     <input | ||||||
|  |                         type="date" | ||||||
|  |                         id="start-date" | ||||||
|  |                         class="form-input" | ||||||
|  |                         value={data.start_date.format("%Y-%m-%d").to_string()} | ||||||
|  |                         onchange={on_start_date_change} | ||||||
|  |                         required=true | ||||||
|  |                     /> | ||||||
|  |                 </div> | ||||||
|  |                  | ||||||
|  |                 if !data.all_day { | ||||||
|  |                     <div class="form-group"> | ||||||
|  |                         <label for="start-time">{"Start Time"}</label> | ||||||
|  |                         <input | ||||||
|  |                             type="time" | ||||||
|  |                             id="start-time" | ||||||
|  |                             class="form-input" | ||||||
|  |                             value={data.start_time.format("%H:%M").to_string()} | ||||||
|  |                             onchange={on_start_time_change} | ||||||
|  |                         /> | ||||||
|  |                     </div> | ||||||
|  |                 } | ||||||
|  |             </div> | ||||||
|  |  | ||||||
|  |             <div class="form-row"> | ||||||
|  |                 <div class="form-group"> | ||||||
|  |                     <label for="end-date">{"End Date *"}</label> | ||||||
|  |                     <input | ||||||
|  |                         type="date" | ||||||
|  |                         id="end-date" | ||||||
|  |                         class="form-input" | ||||||
|  |                         value={data.end_date.format("%Y-%m-%d").to_string()} | ||||||
|  |                         onchange={on_end_date_change} | ||||||
|  |                         required=true | ||||||
|  |                     /> | ||||||
|  |                 </div> | ||||||
|  |                  | ||||||
|  |                 if !data.all_day { | ||||||
|  |                     <div class="form-group"> | ||||||
|  |                         <label for="end-time">{"End Time"}</label> | ||||||
|  |                         <input | ||||||
|  |                             type="time" | ||||||
|  |                             id="end-time" | ||||||
|  |                             class="form-input" | ||||||
|  |                             value={data.end_time.format("%H:%M").to_string()} | ||||||
|  |                             onchange={on_end_time_change} | ||||||
|  |                         /> | ||||||
|  |                     </div> | ||||||
|  |                 } | ||||||
|  |             </div> | ||||||
|  |  | ||||||
|  |             <div class="form-group"> | ||||||
|  |                 <label for="event-location">{"Location"}</label> | ||||||
|  |                 <input | ||||||
|  |                     type="text" | ||||||
|  |                     id="event-location" | ||||||
|  |                     class="form-input" | ||||||
|  |                     value={data.location.clone()} | ||||||
|  |                     oninput={on_location_input} | ||||||
|  |                     placeholder="Enter event location" | ||||||
|  |                 /> | ||||||
|  |             </div> | ||||||
|  |         </div> | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										98
									
								
								frontend/src/components/event_form/categories.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										98
									
								
								frontend/src/components/event_form/categories.rs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,98 @@ | |||||||
|  | use super::types::*; | ||||||
|  | use wasm_bindgen::JsCast; | ||||||
|  | use web_sys::HtmlInputElement; | ||||||
|  | use yew::prelude::*; | ||||||
|  |  | ||||||
|  | #[function_component(CategoriesTab)] | ||||||
|  | pub fn categories_tab(props: &TabProps) -> Html { | ||||||
|  |     let data = &props.data; | ||||||
|  |      | ||||||
|  |     let on_categories_input = { | ||||||
|  |         let data = data.clone(); | ||||||
|  |         Callback::from(move |e: InputEvent| { | ||||||
|  |             if let Some(target) = e.target() { | ||||||
|  |                 if let Ok(input) = target.dyn_into::<HtmlInputElement>() { | ||||||
|  |                     let mut event_data = (*data).clone(); | ||||||
|  |                     event_data.categories = input.value(); | ||||||
|  |                     data.set(event_data); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         }) | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     let add_category = { | ||||||
|  |         let data = data.clone(); | ||||||
|  |         move |category: &str| { | ||||||
|  |             let data = data.clone(); | ||||||
|  |             let category = category.to_string(); | ||||||
|  |             Callback::from(move |_| { | ||||||
|  |                 let mut event_data = (*data).clone(); | ||||||
|  |                 if event_data.categories.is_empty() { | ||||||
|  |                     event_data.categories = category.clone(); | ||||||
|  |                 } else { | ||||||
|  |                     event_data.categories = format!("{}, {}", event_data.categories, category); | ||||||
|  |                 } | ||||||
|  |                 data.set(event_data); | ||||||
|  |             }) | ||||||
|  |         } | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     html! { | ||||||
|  |         <div class="tab-panel"> | ||||||
|  |             <div class="form-group"> | ||||||
|  |                 <label for="event-categories">{"Categories"}</label> | ||||||
|  |                 <input | ||||||
|  |                     type="text" | ||||||
|  |                     id="event-categories" | ||||||
|  |                     class="form-input" | ||||||
|  |                     value={data.categories.clone()} | ||||||
|  |                     oninput={on_categories_input} | ||||||
|  |                     placeholder="work, meeting, personal, project, urgent" | ||||||
|  |                 /> | ||||||
|  |                 <p class="form-help-text">{"Enter categories separated by commas to help organize and filter your events"}</p> | ||||||
|  |             </div> | ||||||
|  |  | ||||||
|  |             <div class="categories-suggestions"> | ||||||
|  |                 <h5>{"Common Categories"}</h5> | ||||||
|  |                 <div class="category-tags"> | ||||||
|  |                     <button type="button" class="category-tag" onclick={add_category("work")}>{"work"}</button> | ||||||
|  |                     <button type="button" class="category-tag" onclick={add_category("meeting")}>{"meeting"}</button> | ||||||
|  |                     <button type="button" class="category-tag" onclick={add_category("personal")}>{"personal"}</button> | ||||||
|  |                     <button type="button" class="category-tag" onclick={add_category("project")}>{"project"}</button> | ||||||
|  |                     <button type="button" class="category-tag" onclick={add_category("urgent")}>{"urgent"}</button> | ||||||
|  |                     <button type="button" class="category-tag" onclick={add_category("social")}>{"social"}</button> | ||||||
|  |                     <button type="button" class="category-tag" onclick={add_category("travel")}>{"travel"}</button> | ||||||
|  |                     <button type="button" class="category-tag" onclick={add_category("health")}>{"health"}</button> | ||||||
|  |                 </div> | ||||||
|  |                 <p class="form-help-text">{"Click to add these common categories to your event"}</p> | ||||||
|  |             </div> | ||||||
|  |  | ||||||
|  |             <div class="categories-info"> | ||||||
|  |                 <h5>{"Event Organization & Filtering"}</h5> | ||||||
|  |                 <ul> | ||||||
|  |                     <li>{"Categories help organize events in calendar views"}</li> | ||||||
|  |                     <li>{"Filter events by category to focus on specific types"}</li> | ||||||
|  |                     <li>{"Categories are searchable and can be used for reporting"}</li> | ||||||
|  |                     <li>{"Multiple categories per event are fully supported"}</li> | ||||||
|  |                 </ul> | ||||||
|  |  | ||||||
|  |                 <div class="categories-examples"> | ||||||
|  |                     <h6>{"Category Usage Examples"}</h6> | ||||||
|  |                     <div class="category-example"> | ||||||
|  |                         <strong>{"Work Events:"}</strong> | ||||||
|  |                         <span>{"work, meeting, project, urgent, deadline"}</span> | ||||||
|  |                     </div> | ||||||
|  |                     <div class="category-example"> | ||||||
|  |                         <strong>{"Personal Events:"}</strong> | ||||||
|  |                         <span>{"personal, family, health, social, travel"}</span> | ||||||
|  |                     </div> | ||||||
|  |                     <div class="category-example"> | ||||||
|  |                         <strong>{"Mixed Events:"}</strong> | ||||||
|  |                         <span>{"work, travel, client, important"}</span> | ||||||
|  |                     </div> | ||||||
|  |                     <p class="form-help-text">{"Categories follow RFC 5545 CATEGORIES property standards"}</p> | ||||||
|  |                 </div> | ||||||
|  |             </div> | ||||||
|  |         </div> | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										118
									
								
								frontend/src/components/event_form/location.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										118
									
								
								frontend/src/components/event_form/location.rs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,118 @@ | |||||||
|  | use super::types::*; | ||||||
|  | use wasm_bindgen::JsCast; | ||||||
|  | use web_sys::HtmlInputElement; | ||||||
|  | use yew::prelude::*; | ||||||
|  |  | ||||||
|  | #[function_component(LocationTab)] | ||||||
|  | pub fn location_tab(props: &TabProps) -> Html { | ||||||
|  |     let data = &props.data; | ||||||
|  |      | ||||||
|  |     let on_location_input = { | ||||||
|  |         let data = data.clone(); | ||||||
|  |         Callback::from(move |e: InputEvent| { | ||||||
|  |             if let Some(target) = e.target() { | ||||||
|  |                 if let Ok(input) = target.dyn_into::<HtmlInputElement>() { | ||||||
|  |                     let mut event_data = (*data).clone(); | ||||||
|  |                     event_data.location = input.value(); | ||||||
|  |                     data.set(event_data); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         }) | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     let set_location = { | ||||||
|  |         let data = data.clone(); | ||||||
|  |         move |location: &str| { | ||||||
|  |             let data = data.clone(); | ||||||
|  |             let location = location.to_string(); | ||||||
|  |             Callback::from(move |_| { | ||||||
|  |                 let mut event_data = (*data).clone(); | ||||||
|  |                 event_data.location = location.clone(); | ||||||
|  |                 data.set(event_data); | ||||||
|  |             }) | ||||||
|  |         } | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     html! { | ||||||
|  |         <div class="tab-panel"> | ||||||
|  |             <div class="form-group"> | ||||||
|  |                 <label for="event-location-detailed">{"Event Location"}</label> | ||||||
|  |                 <input | ||||||
|  |                     type="text" | ||||||
|  |                     id="event-location-detailed" | ||||||
|  |                     class="form-input" | ||||||
|  |                     value={data.location.clone()} | ||||||
|  |                     oninput={on_location_input} | ||||||
|  |                     placeholder="Conference Room A, 123 Main St, City, State 12345" | ||||||
|  |                 /> | ||||||
|  |                 <p class="form-help-text">{"Enter the full address or location description for the event"}</p> | ||||||
|  |             </div> | ||||||
|  |  | ||||||
|  |             <div class="location-suggestions"> | ||||||
|  |                 <h5>{"Common Locations"}</h5> | ||||||
|  |                 <div class="location-tags"> | ||||||
|  |                     <button type="button" class="location-tag" onclick={set_location("Conference Room")}>{"Conference Room"}</button> | ||||||
|  |                     <button type="button" class="location-tag" onclick={set_location("Online Meeting")}>{"Online Meeting"}</button> | ||||||
|  |                     <button type="button" class="location-tag" onclick={set_location("Main Office")}>{"Main Office"}</button> | ||||||
|  |                     <button type="button" class="location-tag" onclick={set_location("Client Site")}>{"Client Site"}</button> | ||||||
|  |                     <button type="button" class="location-tag" onclick={set_location("Home Office")}>{"Home Office"}</button> | ||||||
|  |                     <button type="button" class="location-tag" onclick={set_location("Remote")}>{"Remote"}</button> | ||||||
|  |                 </div> | ||||||
|  |                 <p class="form-help-text">{"Click to quickly set common location types"}</p> | ||||||
|  |             </div> | ||||||
|  |  | ||||||
|  |             <div class="location-info"> | ||||||
|  |                 <h5>{"Location Features & Integration"}</h5> | ||||||
|  |                 <ul> | ||||||
|  |                     <li>{"Location information is included in calendar invitations"}</li> | ||||||
|  |                     <li>{"Supports both physical addresses and virtual meeting links"}</li> | ||||||
|  |                     <li>{"Compatible with mapping and navigation applications"}</li> | ||||||
|  |                     <li>{"Room booking integration available for enterprise setups"}</li> | ||||||
|  |                 </ul> | ||||||
|  |  | ||||||
|  |                 <div class="geo-section"> | ||||||
|  |                     <h6>{"Geographic Coordinates (Advanced)"}</h6> | ||||||
|  |                     <p>{"Future versions will support:"}</p> | ||||||
|  |                     <div class="geo-features"> | ||||||
|  |                         <div class="geo-item"> | ||||||
|  |                             <strong>{"GPS Coordinates:"}</strong> | ||||||
|  |                             <span>{"Precise latitude/longitude positioning"}</span> | ||||||
|  |                         </div> | ||||||
|  |                         <div class="geo-item"> | ||||||
|  |                             <strong>{"Map Integration:"}</strong> | ||||||
|  |                             <span>{"Embedded maps in event details"}</span> | ||||||
|  |                         </div> | ||||||
|  |                         <div class="geo-item"> | ||||||
|  |                             <strong>{"Travel Time:"}</strong> | ||||||
|  |                             <span>{"Automatic travel time calculation"}</span> | ||||||
|  |                         </div> | ||||||
|  |                         <div class="geo-item"> | ||||||
|  |                             <strong>{"Proximity Alerts:"}</strong> | ||||||
|  |                             <span>{"Location-based notifications"}</span> | ||||||
|  |                         </div> | ||||||
|  |                     </div> | ||||||
|  |                     <p class="form-help-text">{"Advanced geographic features will be implemented in future releases"}</p> | ||||||
|  |                 </div> | ||||||
|  |  | ||||||
|  |                 <div class="virtual-meeting-section"> | ||||||
|  |                     <h6>{"Virtual Meeting Integration"}</h6> | ||||||
|  |                     <div class="meeting-platforms"> | ||||||
|  |                         <div class="platform-item"> | ||||||
|  |                             <strong>{"Video Conferencing:"}</strong> | ||||||
|  |                             <span>{"Zoom, Teams, Google Meet links"}</span> | ||||||
|  |                         </div> | ||||||
|  |                         <div class="platform-item"> | ||||||
|  |                             <strong>{"Phone Conference:"}</strong> | ||||||
|  |                             <span>{"Dial-in numbers and access codes"}</span> | ||||||
|  |                         </div> | ||||||
|  |                         <div class="platform-item"> | ||||||
|  |                             <strong>{"Webinar Links:"}</strong> | ||||||
|  |                             <span>{"Live streaming and presentation URLs"}</span> | ||||||
|  |                         </div> | ||||||
|  |                     </div> | ||||||
|  |                     <p class="form-help-text">{"Paste meeting links directly in the location field for virtual events"}</p> | ||||||
|  |                 </div> | ||||||
|  |             </div> | ||||||
|  |         </div> | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										16
									
								
								frontend/src/components/event_form/mod.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								frontend/src/components/event_form/mod.rs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,16 @@ | |||||||
|  | // Event form components module | ||||||
|  | pub mod types; | ||||||
|  | pub mod basic_details; | ||||||
|  | pub mod advanced; | ||||||
|  | pub mod people; | ||||||
|  | pub mod categories; | ||||||
|  | pub mod location; | ||||||
|  | pub mod reminders; | ||||||
|  |  | ||||||
|  | pub use types::*; | ||||||
|  | pub use basic_details::BasicDetailsTab; | ||||||
|  | pub use advanced::AdvancedTab; | ||||||
|  | pub use people::PeopleTab; | ||||||
|  | pub use categories::CategoriesTab; | ||||||
|  | pub use location::LocationTab; | ||||||
|  | pub use reminders::RemindersTab; | ||||||
							
								
								
									
										103
									
								
								frontend/src/components/event_form/people.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										103
									
								
								frontend/src/components/event_form/people.rs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,103 @@ | |||||||
|  | use super::types::*; | ||||||
|  | use wasm_bindgen::JsCast; | ||||||
|  | use web_sys::{HtmlInputElement, HtmlTextAreaElement}; | ||||||
|  | use yew::prelude::*; | ||||||
|  |  | ||||||
|  | #[function_component(PeopleTab)] | ||||||
|  | pub fn people_tab(props: &TabProps) -> Html { | ||||||
|  |     let data = &props.data; | ||||||
|  |      | ||||||
|  |     let on_organizer_input = { | ||||||
|  |         let data = data.clone(); | ||||||
|  |         Callback::from(move |e: InputEvent| { | ||||||
|  |             if let Some(target) = e.target() { | ||||||
|  |                 if let Ok(input) = target.dyn_into::<HtmlInputElement>() { | ||||||
|  |                     let mut event_data = (*data).clone(); | ||||||
|  |                     event_data.organizer = input.value(); | ||||||
|  |                     data.set(event_data); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         }) | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     let on_attendees_input = { | ||||||
|  |         let data = data.clone(); | ||||||
|  |         Callback::from(move |e: InputEvent| { | ||||||
|  |             if let Some(target) = e.target() { | ||||||
|  |                 if let Ok(textarea) = target.dyn_into::<HtmlTextAreaElement>() { | ||||||
|  |                     let mut event_data = (*data).clone(); | ||||||
|  |                     event_data.attendees = textarea.value(); | ||||||
|  |                     data.set(event_data); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         }) | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     html! { | ||||||
|  |         <div class="tab-panel"> | ||||||
|  |             <div class="form-group"> | ||||||
|  |                 <label for="event-organizer">{"Organizer"}</label> | ||||||
|  |                 <input | ||||||
|  |                     type="email" | ||||||
|  |                     id="event-organizer" | ||||||
|  |                     class="form-input" | ||||||
|  |                     value={data.organizer.clone()} | ||||||
|  |                     oninput={on_organizer_input} | ||||||
|  |                     placeholder="organizer@example.com" | ||||||
|  |                 /> | ||||||
|  |                 <p class="form-help-text">{"Email address of the person organizing this event"}</p> | ||||||
|  |             </div> | ||||||
|  |  | ||||||
|  |             <div class="form-group"> | ||||||
|  |                 <label for="event-attendees">{"Attendees"}</label> | ||||||
|  |                 <textarea | ||||||
|  |                     id="event-attendees" | ||||||
|  |                     class="form-input" | ||||||
|  |                     value={data.attendees.clone()} | ||||||
|  |                     oninput={on_attendees_input} | ||||||
|  |                     placeholder="attendee1@example.com, attendee2@example.com, attendee3@example.com" | ||||||
|  |                     rows="4" | ||||||
|  |                 ></textarea> | ||||||
|  |                 <p class="form-help-text">{"Enter attendee email addresses separated by commas"}</p> | ||||||
|  |             </div> | ||||||
|  |  | ||||||
|  |             <div class="people-info"> | ||||||
|  |                 <h5>{"Invitation & Response Management"}</h5> | ||||||
|  |                 <ul> | ||||||
|  |                     <li>{"Invitations are sent automatically when the event is saved"}</li> | ||||||
|  |                     <li>{"Attendees can respond with Accept, Decline, or Tentative"}</li> | ||||||
|  |                     <li>{"Response tracking follows RFC 5545 PARTSTAT standards"}</li> | ||||||
|  |                     <li>{"Delegation and role management available after event creation"}</li> | ||||||
|  |                 </ul> | ||||||
|  |  | ||||||
|  |                 <div class="people-validation"> | ||||||
|  |                     <h6>{"Email Validation"}</h6> | ||||||
|  |                     <p>{"Email addresses will be validated when you save the event. Invalid emails will be highlighted and must be corrected before proceeding."}</p> | ||||||
|  |                 </div> | ||||||
|  |             </div> | ||||||
|  |  | ||||||
|  |             <div class="attendee-roles-preview"> | ||||||
|  |                 <h5>{"Advanced Attendee Features"}</h5> | ||||||
|  |                 <div class="role-examples"> | ||||||
|  |                     <div class="role-item"> | ||||||
|  |                         <strong>{"Required Participant:"}</strong> | ||||||
|  |                         <span>{"Must attend for meeting to proceed"}</span> | ||||||
|  |                     </div> | ||||||
|  |                     <div class="role-item"> | ||||||
|  |                         <strong>{"Optional Participant:"}</strong> | ||||||
|  |                         <span>{"Attendance welcome but not required"}</span> | ||||||
|  |                     </div> | ||||||
|  |                     <div class="role-item"> | ||||||
|  |                         <strong>{"Resource:"}</strong> | ||||||
|  |                         <span>{"Meeting room, equipment, or facility"}</span> | ||||||
|  |                     </div> | ||||||
|  |                     <div class="role-item"> | ||||||
|  |                         <strong>{"Non-Participant:"}</strong> | ||||||
|  |                         <span>{"For information only"}</span> | ||||||
|  |                     </div> | ||||||
|  |                 </div> | ||||||
|  |                 <p class="form-help-text">{"Advanced role assignment and RSVP management will be available in future versions"}</p> | ||||||
|  |             </div> | ||||||
|  |         </div> | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										100
									
								
								frontend/src/components/event_form/reminders.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										100
									
								
								frontend/src/components/event_form/reminders.rs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,100 @@ | |||||||
|  | use super::types::*; | ||||||
|  | // Types are already imported from super::types::* | ||||||
|  | use wasm_bindgen::JsCast; | ||||||
|  | use web_sys::HtmlSelectElement; | ||||||
|  | use yew::prelude::*; | ||||||
|  |  | ||||||
|  | #[function_component(RemindersTab)] | ||||||
|  | pub fn reminders_tab(props: &TabProps) -> Html { | ||||||
|  |     let data = &props.data; | ||||||
|  |      | ||||||
|  |     let on_reminder_change = { | ||||||
|  |         let data = data.clone(); | ||||||
|  |         Callback::from(move |e: Event| { | ||||||
|  |             if let Some(target) = e.target() { | ||||||
|  |                 if let Ok(select) = target.dyn_into::<HtmlSelectElement>() { | ||||||
|  |                     let mut event_data = (*data).clone(); | ||||||
|  |                     event_data.reminder = match select.value().as_str() { | ||||||
|  |                         "15min" => ReminderType::Minutes15, | ||||||
|  |                         "30min" => ReminderType::Minutes30, | ||||||
|  |                         "1hour" => ReminderType::Hour1, | ||||||
|  |                         "1day" => ReminderType::Day1, | ||||||
|  |                         "2days" => ReminderType::Days2, | ||||||
|  |                         "1week" => ReminderType::Week1, | ||||||
|  |                         _ => ReminderType::None, | ||||||
|  |                     }; | ||||||
|  |                     data.set(event_data); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         }) | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     html! { | ||||||
|  |         <div class="tab-panel"> | ||||||
|  |             <div class="form-group"> | ||||||
|  |                 <label for="event-reminder-main">{"Primary Reminder"}</label> | ||||||
|  |                 <select | ||||||
|  |                     id="event-reminder-main" | ||||||
|  |                     class="form-input" | ||||||
|  |                     onchange={on_reminder_change} | ||||||
|  |                 > | ||||||
|  |                     <option value="none" selected={matches!(data.reminder, ReminderType::None)}>{"No reminder"}</option> | ||||||
|  |                     <option value="15min" selected={matches!(data.reminder, ReminderType::Minutes15)}>{"15 minutes before"}</option> | ||||||
|  |                     <option value="30min" selected={matches!(data.reminder, ReminderType::Minutes30)}>{"30 minutes before"}</option> | ||||||
|  |                     <option value="1hour" selected={matches!(data.reminder, ReminderType::Hour1)}>{"1 hour before"}</option> | ||||||
|  |                     <option value="1day" selected={matches!(data.reminder, ReminderType::Day1)}>{"1 day before"}</option> | ||||||
|  |                     <option value="2days" selected={matches!(data.reminder, ReminderType::Days2)}>{"2 days before"}</option> | ||||||
|  |                     <option value="1week" selected={matches!(data.reminder, ReminderType::Week1)}>{"1 week before"}</option> | ||||||
|  |                 </select> | ||||||
|  |                 <p class="form-help-text">{"Choose when you'd like to be reminded about this event"}</p> | ||||||
|  |             </div> | ||||||
|  |  | ||||||
|  |             <div class="reminder-types"> | ||||||
|  |                 <h5>{"Reminder & Alarm Types"}</h5> | ||||||
|  |                 <div class="alarm-examples"> | ||||||
|  |                     <div class="alarm-type"> | ||||||
|  |                         <strong>{"Display Alarm"}</strong> | ||||||
|  |                         <p>{"Pop-up notification on your device"}</p> | ||||||
|  |                     </div> | ||||||
|  |                     <div class="alarm-type"> | ||||||
|  |                         <strong>{"Email Reminder"}</strong> | ||||||
|  |                         <p>{"Email notification sent to your address"}</p> | ||||||
|  |                     </div> | ||||||
|  |                     <div class="alarm-type"> | ||||||
|  |                         <strong>{"Audio Alert"}</strong> | ||||||
|  |                         <p>{"Sound notification with custom audio"}</p> | ||||||
|  |                     </div> | ||||||
|  |                     <div class="alarm-type"> | ||||||
|  |                         <strong>{"SMS/Text"}</strong> | ||||||
|  |                         <p>{"Text message reminder (enterprise feature)"}</p> | ||||||
|  |                     </div> | ||||||
|  |                 </div> | ||||||
|  |                 <p class="form-help-text">{"Multiple alarm types follow RFC 5545 VALARM standards"}</p> | ||||||
|  |             </div> | ||||||
|  |  | ||||||
|  |             <div class="reminder-info"> | ||||||
|  |                 <h5>{"Advanced Reminder Features"}</h5> | ||||||
|  |                 <ul> | ||||||
|  |                     <li>{"Multiple reminders per event with different timing"}</li> | ||||||
|  |                     <li>{"Custom reminder messages and descriptions"}</li> | ||||||
|  |                     <li>{"Recurring reminders for recurring events"}</li> | ||||||
|  |                     <li>{"Snooze and dismiss functionality"}</li> | ||||||
|  |                     <li>{"Integration with system notifications"}</li> | ||||||
|  |                 </ul> | ||||||
|  |  | ||||||
|  |                 <div class="attachments-section"> | ||||||
|  |                     <h6>{"File Attachments & Documents"}</h6> | ||||||
|  |                     <p>{"Future attachment features will include:"}</p> | ||||||
|  |                     <ul> | ||||||
|  |                         <li>{"Drag-and-drop file uploads"}</li> | ||||||
|  |                         <li>{"Document preview and thumbnails"}</li> | ||||||
|  |                         <li>{"Cloud storage integration (Google Drive, OneDrive)"}</li> | ||||||
|  |                         <li>{"Version control for updated documents"}</li> | ||||||
|  |                         <li>{"Shared access permissions for attendees"}</li> | ||||||
|  |                     </ul> | ||||||
|  |                     <p class="form-help-text">{"Attachment functionality will be implemented in a future release."}</p> | ||||||
|  |                 </div> | ||||||
|  |             </div> | ||||||
|  |         </div> | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										225
									
								
								frontend/src/components/event_form/types.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										225
									
								
								frontend/src/components/event_form/types.rs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,225 @@ | |||||||
|  | use crate::services::calendar_service::CalendarInfo; | ||||||
|  | use chrono::{Local, NaiveDate, NaiveTime}; | ||||||
|  | use yew::prelude::*; | ||||||
|  |  | ||||||
|  | #[derive(Clone, PartialEq, Debug)] | ||||||
|  | pub enum EventStatus { | ||||||
|  |     Confirmed, | ||||||
|  |     Tentative, | ||||||
|  |     Cancelled, | ||||||
|  | } | ||||||
|  |  | ||||||
|  | impl Default for EventStatus { | ||||||
|  |     fn default() -> Self { | ||||||
|  |         EventStatus::Confirmed | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | #[derive(Clone, PartialEq, Debug)] | ||||||
|  | pub enum EventClass { | ||||||
|  |     Public, | ||||||
|  |     Private, | ||||||
|  |     Confidential, | ||||||
|  | } | ||||||
|  |  | ||||||
|  | impl Default for EventClass { | ||||||
|  |     fn default() -> Self { | ||||||
|  |         EventClass::Public | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | #[derive(Clone, PartialEq, Debug)] | ||||||
|  | pub enum ReminderType { | ||||||
|  |     None, | ||||||
|  |     Minutes15, | ||||||
|  |     Minutes30, | ||||||
|  |     Hour1, | ||||||
|  |     Day1, | ||||||
|  |     Days2, | ||||||
|  |     Week1, | ||||||
|  | } | ||||||
|  |  | ||||||
|  | impl Default for ReminderType { | ||||||
|  |     fn default() -> Self { | ||||||
|  |         ReminderType::None | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | #[derive(Clone, PartialEq, Debug)] | ||||||
|  | pub enum RecurrenceType { | ||||||
|  |     None, | ||||||
|  |     Daily, | ||||||
|  |     Weekly, | ||||||
|  |     Monthly, | ||||||
|  |     Yearly, | ||||||
|  | } | ||||||
|  |  | ||||||
|  | impl Default for RecurrenceType { | ||||||
|  |     fn default() -> Self { | ||||||
|  |         RecurrenceType::None | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | #[derive(Clone, PartialEq)] | ||||||
|  | pub enum ModalTab { | ||||||
|  |     BasicDetails, | ||||||
|  |     Advanced, | ||||||
|  |     People, | ||||||
|  |     Categories, | ||||||
|  |     Location, | ||||||
|  |     Reminders, | ||||||
|  | } | ||||||
|  |  | ||||||
|  | impl Default for ModalTab { | ||||||
|  |     fn default() -> Self { | ||||||
|  |         ModalTab::BasicDetails | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // EditAction is now imported from event_context_menu - this duplicate removed | ||||||
|  |  | ||||||
|  | #[derive(Clone, PartialEq, Debug)] | ||||||
|  | pub struct EventCreationData { | ||||||
|  |     // Basic event info | ||||||
|  |     pub title: String, | ||||||
|  |     pub description: String, | ||||||
|  |     pub location: String, | ||||||
|  |     pub all_day: bool, | ||||||
|  |      | ||||||
|  |     // Timing | ||||||
|  |     pub start_date: NaiveDate, | ||||||
|  |     pub end_date: NaiveDate, | ||||||
|  |     pub start_time: NaiveTime, | ||||||
|  |     pub end_time: NaiveTime, | ||||||
|  |      | ||||||
|  |     // Classification | ||||||
|  |     pub status: EventStatus, | ||||||
|  |     pub class: EventClass, | ||||||
|  |     pub priority: Option<u8>, | ||||||
|  |      | ||||||
|  |     // People | ||||||
|  |     pub organizer: String, | ||||||
|  |     pub attendees: String, | ||||||
|  |      | ||||||
|  |     // Categorization | ||||||
|  |     pub categories: String, | ||||||
|  |      | ||||||
|  |     // Reminders | ||||||
|  |     pub reminder: ReminderType, | ||||||
|  |      | ||||||
|  |     // Recurrence | ||||||
|  |     pub recurrence: RecurrenceType, | ||||||
|  |     pub recurrence_interval: u32, | ||||||
|  |     pub recurrence_until: Option<NaiveDate>, | ||||||
|  |     pub recurrence_count: Option<u32>, | ||||||
|  |     pub recurrence_days: Vec<bool>, // [Sun, Mon, Tue, Wed, Thu, Fri, Sat] | ||||||
|  |      | ||||||
|  |     // Advanced recurrence | ||||||
|  |     pub monthly_by_day: Option<String>, // e.g., "1MO" for first Monday | ||||||
|  |     pub monthly_by_monthday: Option<u8>, // e.g., 15 for 15th day of month | ||||||
|  |     pub yearly_by_month: Vec<bool>, // [Jan, Feb, Mar, ...]  | ||||||
|  |      | ||||||
|  |     // Calendar selection | ||||||
|  |     pub selected_calendar: Option<String>, | ||||||
|  |      | ||||||
|  |     // Edit tracking (for recurring events) | ||||||
|  |     pub edit_scope: Option<crate::components::EditAction>, | ||||||
|  |     pub changed_fields: Vec<String>, | ||||||
|  |     pub original_uid: Option<String>, // Set when editing existing events | ||||||
|  |     pub occurrence_date: Option<NaiveDate>, // The specific occurrence date being edited | ||||||
|  | } | ||||||
|  |  | ||||||
|  | impl EventCreationData { | ||||||
|  |     pub fn to_create_event_params(&self) -> ( | ||||||
|  |         String, // title | ||||||
|  |         String, // description | ||||||
|  |         String, // start_date | ||||||
|  |         String, // start_time | ||||||
|  |         String, // end_date | ||||||
|  |         String, // end_time | ||||||
|  |         String, // location | ||||||
|  |         bool,   // all_day | ||||||
|  |         String, // status | ||||||
|  |         String, // class | ||||||
|  |         Option<u8>, // priority | ||||||
|  |         String, // organizer | ||||||
|  |         String, // attendees | ||||||
|  |         String, // categories | ||||||
|  |         String, // reminder | ||||||
|  |         String, // recurrence | ||||||
|  |         Vec<bool>, // recurrence_days | ||||||
|  |         Option<String>, // calendar_path | ||||||
|  |         Option<u32>, // recurrence_count | ||||||
|  |         Option<String>, // recurrence_until | ||||||
|  |     ) { | ||||||
|  |         ( | ||||||
|  |             self.title.clone(), | ||||||
|  |             self.description.clone(), | ||||||
|  |             self.start_date.format("%Y-%m-%d").to_string(), | ||||||
|  |             self.start_time.format("%H:%M").to_string(), | ||||||
|  |             self.end_date.format("%Y-%m-%d").to_string(), | ||||||
|  |             self.end_time.format("%H:%M").to_string(), | ||||||
|  |             self.location.clone(), | ||||||
|  |             self.all_day, | ||||||
|  |             format!("{:?}", self.status).to_uppercase(), | ||||||
|  |             format!("{:?}", self.class).to_uppercase(), | ||||||
|  |             self.priority, | ||||||
|  |             self.organizer.clone(), | ||||||
|  |             self.attendees.clone(), | ||||||
|  |             self.categories.clone(), | ||||||
|  |             format!("{:?}", self.reminder), | ||||||
|  |             format!("{:?}", self.recurrence), | ||||||
|  |             self.recurrence_days.clone(), | ||||||
|  |             self.selected_calendar.clone(), | ||||||
|  |             self.recurrence_count, | ||||||
|  |             self.recurrence_until.map(|d| d.format("%Y-%m-%d").to_string()), | ||||||
|  |         ) | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | impl Default for EventCreationData { | ||||||
|  |     fn default() -> Self { | ||||||
|  |         let now_local = Local::now(); | ||||||
|  |         let start_date = now_local.date_naive(); | ||||||
|  |         let start_time = NaiveTime::from_hms_opt(9, 0, 0).unwrap_or_default(); | ||||||
|  |         let end_time = NaiveTime::from_hms_opt(10, 0, 0).unwrap_or_default(); | ||||||
|  |  | ||||||
|  |         Self { | ||||||
|  |             title: String::new(), | ||||||
|  |             description: String::new(), | ||||||
|  |             location: String::new(), | ||||||
|  |             all_day: false, | ||||||
|  |             start_date, | ||||||
|  |             end_date: start_date, | ||||||
|  |             start_time, | ||||||
|  |             end_time, | ||||||
|  |             status: EventStatus::default(), | ||||||
|  |             class: EventClass::default(), | ||||||
|  |             priority: None, | ||||||
|  |             organizer: String::new(), | ||||||
|  |             attendees: String::new(), | ||||||
|  |             categories: String::new(), | ||||||
|  |             reminder: ReminderType::default(), | ||||||
|  |             recurrence: RecurrenceType::default(), | ||||||
|  |             recurrence_interval: 1, | ||||||
|  |             recurrence_until: None, | ||||||
|  |             recurrence_count: None, | ||||||
|  |             recurrence_days: vec![false; 7], | ||||||
|  |             monthly_by_day: None, | ||||||
|  |             monthly_by_monthday: None, | ||||||
|  |             yearly_by_month: vec![false; 12], | ||||||
|  |             selected_calendar: None, | ||||||
|  |             edit_scope: None, | ||||||
|  |             changed_fields: vec![], | ||||||
|  |             original_uid: None, | ||||||
|  |             occurrence_date: None, | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // Common props for all tab components | ||||||
|  | #[derive(Properties, PartialEq)] | ||||||
|  | pub struct TabProps { | ||||||
|  |     pub data: UseStateHandle<EventCreationData>, | ||||||
|  |     pub available_calendars: Vec<CalendarInfo>, | ||||||
|  | } | ||||||
| @@ -63,7 +63,7 @@ pub fn EventModal(props: &EventModalProps) -> Html { | |||||||
|                                 html! { |                                 html! { | ||||||
|                                     <div class="event-detail"> |                                     <div class="event-detail"> | ||||||
|                                         <strong>{"End:"}</strong> |                                         <strong>{"End:"}</strong> | ||||||
|                                         <span>{format_datetime(end, event.all_day)}</span> |                                         <span>{format_datetime_end(end, event.all_day)}</span> | ||||||
|                                     </div> |                                     </div> | ||||||
|                                 } |                                 } | ||||||
|                             } else { |                             } else { | ||||||
| @@ -221,6 +221,17 @@ fn format_datetime(dt: &DateTime<Utc>, all_day: bool) -> String { | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | fn format_datetime_end(dt: &DateTime<Utc>, all_day: bool) -> String { | ||||||
|  |     if all_day { | ||||||
|  |         // For all-day events, subtract one day from end date for display | ||||||
|  |         // RFC-5545 uses exclusive end dates, but users expect inclusive display | ||||||
|  |         let display_date = *dt - chrono::Duration::days(1); | ||||||
|  |         display_date.format("%B %d, %Y").to_string() | ||||||
|  |     } else { | ||||||
|  |         dt.format("%B %d, %Y at %I:%M %p").to_string() | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
| fn format_recurrence_rule(rrule: &str) -> String { | fn format_recurrence_rule(rrule: &str) -> String { | ||||||
|     // Basic parsing of RRULE to display user-friendly text |     // Basic parsing of RRULE to display user-friendly text | ||||||
|     if rrule.contains("FREQ=DAILY") { |     if rrule.contains("FREQ=DAILY") { | ||||||
|   | |||||||
							
								
								
									
										222
									
								
								frontend/src/components/external_calendar_modal.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										222
									
								
								frontend/src/components/external_calendar_modal.rs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,222 @@ | |||||||
|  | use web_sys::HtmlInputElement; | ||||||
|  | use yew::prelude::*; | ||||||
|  |  | ||||||
|  | use crate::services::calendar_service::CalendarService; | ||||||
|  |  | ||||||
|  | #[derive(Properties, PartialEq)] | ||||||
|  | pub struct ExternalCalendarModalProps { | ||||||
|  |     pub is_open: bool, | ||||||
|  |     pub on_close: Callback<()>, | ||||||
|  |     pub on_success: Callback<i32>, // Pass the newly created calendar ID | ||||||
|  | } | ||||||
|  |  | ||||||
|  | #[function_component(ExternalCalendarModal)] | ||||||
|  | pub fn external_calendar_modal(props: &ExternalCalendarModalProps) -> Html { | ||||||
|  |     let name_ref = use_node_ref(); | ||||||
|  |     let url_ref = use_node_ref(); | ||||||
|  |     let color_ref = use_node_ref(); | ||||||
|  |     let is_loading = use_state(|| false); | ||||||
|  |     let error_message = use_state(|| None::<String>); | ||||||
|  |  | ||||||
|  |     let on_submit = { | ||||||
|  |         let name_ref = name_ref.clone(); | ||||||
|  |         let url_ref = url_ref.clone(); | ||||||
|  |         let color_ref = color_ref.clone(); | ||||||
|  |         let is_loading = is_loading.clone(); | ||||||
|  |         let error_message = error_message.clone(); | ||||||
|  |         let on_close = props.on_close.clone(); | ||||||
|  |         let on_success = props.on_success.clone(); | ||||||
|  |  | ||||||
|  |         Callback::from(move |e: SubmitEvent| { | ||||||
|  |             e.prevent_default(); | ||||||
|  |              | ||||||
|  |             let name = name_ref | ||||||
|  |                 .cast::<HtmlInputElement>() | ||||||
|  |                 .map(|input| input.value()) | ||||||
|  |                 .unwrap_or_default() | ||||||
|  |                 .trim() | ||||||
|  |                 .to_string(); | ||||||
|  |              | ||||||
|  |             let url = url_ref | ||||||
|  |                 .cast::<HtmlInputElement>() | ||||||
|  |                 .map(|input| input.value()) | ||||||
|  |                 .unwrap_or_default() | ||||||
|  |                 .trim() | ||||||
|  |                 .to_string(); | ||||||
|  |                  | ||||||
|  |             let color = color_ref | ||||||
|  |                 .cast::<HtmlInputElement>() | ||||||
|  |                 .map(|input| input.value()) | ||||||
|  |                 .unwrap_or_else(|| "#4285f4".to_string()); | ||||||
|  |  | ||||||
|  |             if name.is_empty() { | ||||||
|  |                 error_message.set(Some("Calendar name is required".to_string())); | ||||||
|  |                 return; | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             if url.is_empty() { | ||||||
|  |                 error_message.set(Some("Calendar URL is required".to_string())); | ||||||
|  |                 return; | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             // Basic URL validation | ||||||
|  |             if !url.starts_with("http://") && !url.starts_with("https://") { | ||||||
|  |                 error_message.set(Some("Please enter a valid HTTP or HTTPS URL".to_string())); | ||||||
|  |                 return; | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             error_message.set(None); | ||||||
|  |             is_loading.set(true); | ||||||
|  |  | ||||||
|  |             let is_loading = is_loading.clone(); | ||||||
|  |             let error_message = error_message.clone(); | ||||||
|  |             let on_close = on_close.clone(); | ||||||
|  |             let on_success = on_success.clone(); | ||||||
|  |  | ||||||
|  |             wasm_bindgen_futures::spawn_local(async move { | ||||||
|  |                 match CalendarService::create_external_calendar(&name, &url, &color).await { | ||||||
|  |                     Ok(new_calendar) => { | ||||||
|  |                         is_loading.set(false); | ||||||
|  |                         on_success.emit(new_calendar.id); | ||||||
|  |                         on_close.emit(()); | ||||||
|  |                     } | ||||||
|  |                     Err(e) => { | ||||||
|  |                         is_loading.set(false); | ||||||
|  |                         error_message.set(Some(format!("Failed to add calendar: {}", e))); | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |             }); | ||||||
|  |         }) | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     let on_cancel = { | ||||||
|  |         let on_close = props.on_close.clone(); | ||||||
|  |         Callback::from(move |_| { | ||||||
|  |             on_close.emit(()); | ||||||
|  |         }) | ||||||
|  |     }; | ||||||
|  |      | ||||||
|  |     let on_cancel_clone = on_cancel.clone(); | ||||||
|  |  | ||||||
|  |     if !props.is_open { | ||||||
|  |         return html! {}; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     html! { | ||||||
|  |         <div class="modal-backdrop" onclick={on_cancel_clone}> | ||||||
|  |             <div class="external-calendar-modal" onclick={Callback::from(|e: MouseEvent| e.stop_propagation())}> | ||||||
|  |                 <div class="modal-header"> | ||||||
|  |                     <h3>{"Add External Calendar"}</h3> | ||||||
|  |                     <button class="modal-close" onclick={on_cancel.clone()}>{"×"}</button> | ||||||
|  |                 </div> | ||||||
|  |                  | ||||||
|  |                 <form onsubmit={on_submit}> | ||||||
|  |                     <div class="modal-body"> | ||||||
|  |                         { | ||||||
|  |                             if let Some(error) = (*error_message).as_ref() { | ||||||
|  |                                 html! { | ||||||
|  |                                     <div class="error-message"> | ||||||
|  |                                         {error} | ||||||
|  |                                     </div> | ||||||
|  |                                 } | ||||||
|  |                             } else { | ||||||
|  |                                 html! {} | ||||||
|  |                             } | ||||||
|  |                         } | ||||||
|  |                          | ||||||
|  |                         <div class="form-help" style="margin-bottom: 1.5rem; padding: 1rem; background: #f8f9fa; border-radius: 8px; border-left: 4px solid #007bff;"> | ||||||
|  |                             <h4 style="margin: 0 0 0.5rem 0; font-size: 0.9rem; color: #495057;">{"Setting up External Calendars"}</h4> | ||||||
|  |                             <p style="margin: 0 0 0.5rem 0; font-size: 0.8rem; line-height: 1.4;"> | ||||||
|  |                                 {"Currently tested with Outlook 365 and Google Calendar. To get your calendar link:"} | ||||||
|  |                             </p> | ||||||
|  |                              | ||||||
|  |                             <div style="margin-bottom: 1rem;"> | ||||||
|  |                                 <strong style="font-size: 0.8rem; color: #495057;">{"Outlook 365:"}</strong> | ||||||
|  |                                 <ol style="margin: 0.3rem 0 0 0; padding-left: 1.2rem; font-size: 0.8rem; line-height: 1.3;"> | ||||||
|  |                                     <li>{"Go to Outlook Settings"}</li> | ||||||
|  |                                     <li>{"Navigate to Calendar → Shared Calendars"}</li> | ||||||
|  |                                     <li>{"Click \"Publish a calendar\""}</li> | ||||||
|  |                                     <li>{"Select your calendar and choose \"Can view all details\""}</li> | ||||||
|  |                                     <li>{"Copy the ICS link and paste it below"}</li> | ||||||
|  |                                 </ol> | ||||||
|  |                             </div> | ||||||
|  |                              | ||||||
|  |                             <div> | ||||||
|  |                                 <strong style="font-size: 0.8rem; color: #495057;">{"Google Calendar:"}</strong> | ||||||
|  |                                 <ol style="margin: 0.3rem 0 0 0; padding-left: 1.2rem; font-size: 0.8rem; line-height: 1.3;"> | ||||||
|  |                                     <li>{"Hover over your calendar name in the left sidebar"}</li> | ||||||
|  |                                     <li>{"Click the three dots that appear"}</li> | ||||||
|  |                                     <li>{"Select \"Settings and sharing\""}</li> | ||||||
|  |                                     <li>{"Scroll to \"Integrate calendar\""}</li> | ||||||
|  |                                     <li>{"Copy the \"Public address in iCal format\" link"}</li> | ||||||
|  |                                 </ol> | ||||||
|  |                             </div> | ||||||
|  |                         </div> | ||||||
|  |                          | ||||||
|  |                         <div class="form-group"> | ||||||
|  |                             <label for="external-calendar-name">{"Calendar Name"}</label> | ||||||
|  |                             <input | ||||||
|  |                                 ref={name_ref} | ||||||
|  |                                 id="external-calendar-name" | ||||||
|  |                                 type="text" | ||||||
|  |                                 placeholder="My External Calendar" | ||||||
|  |                                 disabled={*is_loading} | ||||||
|  |                                 required={true} | ||||||
|  |                             /> | ||||||
|  |                         </div> | ||||||
|  |  | ||||||
|  |                         <div class="form-group"> | ||||||
|  |                             <label for="external-calendar-url">{"ICS URL"}</label> | ||||||
|  |                             <input | ||||||
|  |                                 ref={url_ref} | ||||||
|  |                                 id="external-calendar-url" | ||||||
|  |                                 type="url" | ||||||
|  |                                 placeholder="https://example.com/calendar.ics" | ||||||
|  |                                 disabled={*is_loading} | ||||||
|  |                                 required={true} | ||||||
|  |                             /> | ||||||
|  |                             <small class="form-help"> | ||||||
|  |                                 {"Enter the public ICS URL for the calendar you want to add"} | ||||||
|  |                             </small> | ||||||
|  |                         </div> | ||||||
|  |  | ||||||
|  |                         <div class="form-group"> | ||||||
|  |                             <label for="external-calendar-color">{"Color"}</label> | ||||||
|  |                             <input | ||||||
|  |                                 ref={color_ref} | ||||||
|  |                                 id="external-calendar-color" | ||||||
|  |                                 type="color" | ||||||
|  |                                 value="#4285f4" | ||||||
|  |                                 disabled={*is_loading} | ||||||
|  |                             /> | ||||||
|  |                         </div> | ||||||
|  |                     </div> | ||||||
|  |  | ||||||
|  |                     <div class="modal-actions"> | ||||||
|  |                         <button | ||||||
|  |                             type="button" | ||||||
|  |                             class="btn btn-secondary" | ||||||
|  |                             onclick={on_cancel} | ||||||
|  |                             disabled={*is_loading} | ||||||
|  |                         > | ||||||
|  |                             {"Cancel"} | ||||||
|  |                         </button> | ||||||
|  |                         <button | ||||||
|  |                             type="submit" | ||||||
|  |                             class="btn btn-primary" | ||||||
|  |                             disabled={*is_loading} | ||||||
|  |                         > | ||||||
|  |                             { | ||||||
|  |                                 if *is_loading { | ||||||
|  |                                     "Adding..." | ||||||
|  |                                 } else { | ||||||
|  |                                     "Add Calendar" | ||||||
|  |                                 } | ||||||
|  |                             } | ||||||
|  |                         </button> | ||||||
|  |                     </div> | ||||||
|  |                 </form> | ||||||
|  |             </div> | ||||||
|  |         </div> | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -6,7 +6,9 @@ pub mod context_menu; | |||||||
| pub mod create_calendar_modal; | pub mod create_calendar_modal; | ||||||
| pub mod create_event_modal; | pub mod create_event_modal; | ||||||
| pub mod event_context_menu; | pub mod event_context_menu; | ||||||
|  | pub mod event_form; | ||||||
| pub mod event_modal; | pub mod event_modal; | ||||||
|  | pub mod external_calendar_modal; | ||||||
| pub mod login; | pub mod login; | ||||||
| pub mod month_view; | pub mod month_view; | ||||||
| pub mod recurring_edit_modal; | pub mod recurring_edit_modal; | ||||||
| @@ -20,11 +22,12 @@ pub use calendar_header::CalendarHeader; | |||||||
| pub use calendar_list_item::CalendarListItem; | pub use calendar_list_item::CalendarListItem; | ||||||
| pub use context_menu::ContextMenu; | pub use context_menu::ContextMenu; | ||||||
| pub use create_calendar_modal::CreateCalendarModal; | pub use create_calendar_modal::CreateCalendarModal; | ||||||
| pub use create_event_modal::{ | pub use create_event_modal::CreateEventModal; | ||||||
|     CreateEventModal, EventClass, EventCreationData, EventStatus, RecurrenceType, ReminderType, | // Re-export event form types for backwards compatibility | ||||||
| }; | pub use event_form::EventCreationData; | ||||||
| pub use event_context_menu::{DeleteAction, EditAction, EventContextMenu}; | pub use event_context_menu::{DeleteAction, EditAction, EventContextMenu}; | ||||||
| pub use event_modal::EventModal; | pub use event_modal::EventModal; | ||||||
|  | pub use external_calendar_modal::ExternalCalendarModal; | ||||||
| pub use login::Login; | pub use login::Login; | ||||||
| pub use month_view::MonthView; | pub use month_view::MonthView; | ||||||
| pub use recurring_edit_modal::{RecurringEditAction, RecurringEditModal}; | pub use recurring_edit_modal::{RecurringEditAction, RecurringEditModal}; | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| use crate::models::ical::VEvent; | use crate::models::ical::VEvent; | ||||||
| use crate::services::calendar_service::UserInfo; | use crate::services::calendar_service::{UserInfo, ExternalCalendar}; | ||||||
| use chrono::{Datelike, NaiveDate, Weekday}; | use chrono::{Datelike, NaiveDate, Weekday}; | ||||||
| use std::collections::HashMap; | use std::collections::HashMap; | ||||||
| use wasm_bindgen::{prelude::*, JsCast}; | use wasm_bindgen::{prelude::*, JsCast}; | ||||||
| @@ -17,6 +17,8 @@ pub struct MonthViewProps { | |||||||
|     #[prop_or_default] |     #[prop_or_default] | ||||||
|     pub user_info: Option<UserInfo>, |     pub user_info: Option<UserInfo>, | ||||||
|     #[prop_or_default] |     #[prop_or_default] | ||||||
|  |     pub external_calendars: Vec<ExternalCalendar>, | ||||||
|  |     #[prop_or_default] | ||||||
|     pub on_event_context_menu: Option<Callback<(web_sys::MouseEvent, VEvent)>>, |     pub on_event_context_menu: Option<Callback<(web_sys::MouseEvent, VEvent)>>, | ||||||
|     #[prop_or_default] |     #[prop_or_default] | ||||||
|     pub on_calendar_context_menu: Option<Callback<(web_sys::MouseEvent, NaiveDate)>>, |     pub on_calendar_context_menu: Option<Callback<(web_sys::MouseEvent, NaiveDate)>>, | ||||||
| @@ -85,8 +87,20 @@ pub fn month_view(props: &MonthViewProps) -> Html { | |||||||
|  |  | ||||||
|     // Helper function to get calendar color for an event |     // Helper function to get calendar color for an event | ||||||
|     let get_event_color = |event: &VEvent| -> String { |     let get_event_color = |event: &VEvent| -> String { | ||||||
|         if let Some(user_info) = &props.user_info { |  | ||||||
|         if let Some(calendar_path) = &event.calendar_path { |         if let Some(calendar_path) = &event.calendar_path { | ||||||
|  |             // Check external calendars first (path format: "external_{id}") | ||||||
|  |             if calendar_path.starts_with("external_") { | ||||||
|  |                 if let Ok(id_str) = calendar_path.strip_prefix("external_").unwrap_or("").parse::<i32>() { | ||||||
|  |                     if let Some(external_calendar) = props.external_calendars | ||||||
|  |                         .iter() | ||||||
|  |                         .find(|cal| cal.id == id_str) | ||||||
|  |                     { | ||||||
|  |                         return external_calendar.color.clone(); | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |             // Check regular calendars | ||||||
|  |             else if let Some(user_info) = &props.user_info { | ||||||
|                 if let Some(calendar) = user_info |                 if let Some(calendar) = user_info | ||||||
|                     .calendars |                     .calendars | ||||||
|                     .iter() |                     .iter() | ||||||
| @@ -194,6 +208,7 @@ pub fn month_view(props: &MonthViewProps) -> Html { | |||||||
|                                             <div |                                             <div | ||||||
|                                                 class={classes!("event-box", if is_refreshing { Some("refreshing") } else { None })} |                                                 class={classes!("event-box", if is_refreshing { Some("refreshing") } else { None })} | ||||||
|                                                 style={format!("background-color: {}", event_color)} |                                                 style={format!("background-color: {}", event_color)} | ||||||
|  |                                                 data-external={event.categories.contains(&"__EXTERNAL_CALENDAR__".to_string()).to_string()} | ||||||
|                                                 {onclick} |                                                 {onclick} | ||||||
|                                                 {oncontextmenu} |                                                 {oncontextmenu} | ||||||
|                                             > |                                             > | ||||||
|   | |||||||
| @@ -1,6 +1,6 @@ | |||||||
| use crate::components::{Login, ViewMode}; | use crate::components::{Login, ViewMode}; | ||||||
| use crate::models::ical::VEvent; | use crate::models::ical::VEvent; | ||||||
| use crate::services::calendar_service::UserInfo; | use crate::services::calendar_service::{UserInfo, ExternalCalendar}; | ||||||
| use yew::prelude::*; | use yew::prelude::*; | ||||||
| use yew_router::prelude::*; | use yew_router::prelude::*; | ||||||
|  |  | ||||||
| @@ -20,6 +20,10 @@ pub struct RouteHandlerProps { | |||||||
|     pub user_info: Option<UserInfo>, |     pub user_info: Option<UserInfo>, | ||||||
|     pub on_login: Callback<String>, |     pub on_login: Callback<String>, | ||||||
|     #[prop_or_default] |     #[prop_or_default] | ||||||
|  |     pub external_calendar_events: Vec<VEvent>, | ||||||
|  |     #[prop_or_default] | ||||||
|  |     pub external_calendars: Vec<ExternalCalendar>, | ||||||
|  |     #[prop_or_default] | ||||||
|     pub on_event_context_menu: Option<Callback<(web_sys::MouseEvent, VEvent)>>, |     pub on_event_context_menu: Option<Callback<(web_sys::MouseEvent, VEvent)>>, | ||||||
|     #[prop_or_default] |     #[prop_or_default] | ||||||
|     pub on_calendar_context_menu: Option<Callback<(web_sys::MouseEvent, chrono::NaiveDate)>>, |     pub on_calendar_context_menu: Option<Callback<(web_sys::MouseEvent, chrono::NaiveDate)>>, | ||||||
| @@ -48,6 +52,8 @@ pub fn route_handler(props: &RouteHandlerProps) -> Html { | |||||||
|     let auth_token = props.auth_token.clone(); |     let auth_token = props.auth_token.clone(); | ||||||
|     let user_info = props.user_info.clone(); |     let user_info = props.user_info.clone(); | ||||||
|     let on_login = props.on_login.clone(); |     let on_login = props.on_login.clone(); | ||||||
|  |     let external_calendar_events = props.external_calendar_events.clone(); | ||||||
|  |     let external_calendars = props.external_calendars.clone(); | ||||||
|     let on_event_context_menu = props.on_event_context_menu.clone(); |     let on_event_context_menu = props.on_event_context_menu.clone(); | ||||||
|     let on_calendar_context_menu = props.on_calendar_context_menu.clone(); |     let on_calendar_context_menu = props.on_calendar_context_menu.clone(); | ||||||
|     let view = props.view.clone(); |     let view = props.view.clone(); | ||||||
| @@ -60,6 +66,8 @@ pub fn route_handler(props: &RouteHandlerProps) -> Html { | |||||||
|             let auth_token = auth_token.clone(); |             let auth_token = auth_token.clone(); | ||||||
|             let user_info = user_info.clone(); |             let user_info = user_info.clone(); | ||||||
|             let on_login = on_login.clone(); |             let on_login = on_login.clone(); | ||||||
|  |             let external_calendar_events = external_calendar_events.clone(); | ||||||
|  |             let external_calendars = external_calendars.clone(); | ||||||
|             let on_event_context_menu = on_event_context_menu.clone(); |             let on_event_context_menu = on_event_context_menu.clone(); | ||||||
|             let on_calendar_context_menu = on_calendar_context_menu.clone(); |             let on_calendar_context_menu = on_calendar_context_menu.clone(); | ||||||
|             let view = view.clone(); |             let view = view.clone(); | ||||||
| @@ -87,6 +95,8 @@ pub fn route_handler(props: &RouteHandlerProps) -> Html { | |||||||
|                         html! { |                         html! { | ||||||
|                             <CalendarView |                             <CalendarView | ||||||
|                                 user_info={user_info} |                                 user_info={user_info} | ||||||
|  |                                 external_calendar_events={external_calendar_events} | ||||||
|  |                                 external_calendars={external_calendars} | ||||||
|                                 on_event_context_menu={on_event_context_menu} |                                 on_event_context_menu={on_event_context_menu} | ||||||
|                                 on_calendar_context_menu={on_calendar_context_menu} |                                 on_calendar_context_menu={on_calendar_context_menu} | ||||||
|                                 view={view} |                                 view={view} | ||||||
| @@ -108,6 +118,10 @@ pub fn route_handler(props: &RouteHandlerProps) -> Html { | |||||||
| pub struct CalendarViewProps { | pub struct CalendarViewProps { | ||||||
|     pub user_info: Option<UserInfo>, |     pub user_info: Option<UserInfo>, | ||||||
|     #[prop_or_default] |     #[prop_or_default] | ||||||
|  |     pub external_calendar_events: Vec<VEvent>, | ||||||
|  |     #[prop_or_default] | ||||||
|  |     pub external_calendars: Vec<ExternalCalendar>, | ||||||
|  |     #[prop_or_default] | ||||||
|     pub on_event_context_menu: Option<Callback<(web_sys::MouseEvent, VEvent)>>, |     pub on_event_context_menu: Option<Callback<(web_sys::MouseEvent, VEvent)>>, | ||||||
|     #[prop_or_default] |     #[prop_or_default] | ||||||
|     pub on_calendar_context_menu: Option<Callback<(web_sys::MouseEvent, chrono::NaiveDate)>>, |     pub on_calendar_context_menu: Option<Callback<(web_sys::MouseEvent, chrono::NaiveDate)>>, | ||||||
| @@ -139,6 +153,8 @@ pub fn calendar_view(props: &CalendarViewProps) -> Html { | |||||||
|         <div class="calendar-view"> |         <div class="calendar-view"> | ||||||
|             <Calendar |             <Calendar | ||||||
|                 user_info={props.user_info.clone()} |                 user_info={props.user_info.clone()} | ||||||
|  |                 external_calendar_events={props.external_calendar_events.clone()} | ||||||
|  |                 external_calendars={props.external_calendars.clone()} | ||||||
|                 on_event_context_menu={props.on_event_context_menu.clone()} |                 on_event_context_menu={props.on_event_context_menu.clone()} | ||||||
|                 on_calendar_context_menu={props.on_calendar_context_menu.clone()} |                 on_calendar_context_menu={props.on_calendar_context_menu.clone()} | ||||||
|                 view={props.view.clone()} |                 view={props.view.clone()} | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| use crate::components::CalendarListItem; | use crate::components::CalendarListItem; | ||||||
| use crate::services::calendar_service::UserInfo; | use crate::services::calendar_service::{UserInfo, ExternalCalendar}; | ||||||
| use web_sys::HtmlSelectElement; | use web_sys::HtmlSelectElement; | ||||||
| use yew::prelude::*; | use yew::prelude::*; | ||||||
| use yew_router::prelude::*; | use yew_router::prelude::*; | ||||||
| @@ -101,11 +101,17 @@ pub struct SidebarProps { | |||||||
|     pub user_info: Option<UserInfo>, |     pub user_info: Option<UserInfo>, | ||||||
|     pub on_logout: Callback<()>, |     pub on_logout: Callback<()>, | ||||||
|     pub on_create_calendar: Callback<()>, |     pub on_create_calendar: Callback<()>, | ||||||
|  |     pub on_create_external_calendar: Callback<()>, | ||||||
|  |     pub external_calendars: Vec<ExternalCalendar>, | ||||||
|  |     pub on_external_calendar_toggle: Callback<i32>, | ||||||
|  |     pub on_external_calendar_delete: Callback<i32>, | ||||||
|  |     pub on_external_calendar_refresh: Callback<i32>, | ||||||
|     pub color_picker_open: Option<String>, |     pub color_picker_open: Option<String>, | ||||||
|     pub on_color_change: Callback<(String, String)>, |     pub on_color_change: Callback<(String, String)>, | ||||||
|     pub on_color_picker_toggle: Callback<String>, |     pub on_color_picker_toggle: Callback<String>, | ||||||
|     pub available_colors: Vec<String>, |     pub available_colors: Vec<String>, | ||||||
|     pub on_calendar_context_menu: Callback<(MouseEvent, String)>, |     pub on_calendar_context_menu: Callback<(MouseEvent, String)>, | ||||||
|  |     pub on_calendar_visibility_toggle: Callback<String>, | ||||||
|     pub current_view: ViewMode, |     pub current_view: ViewMode, | ||||||
|     pub on_view_change: Callback<ViewMode>, |     pub on_view_change: Callback<ViewMode>, | ||||||
|     pub current_theme: Theme, |     pub current_theme: Theme, | ||||||
| @@ -116,6 +122,7 @@ pub struct SidebarProps { | |||||||
|  |  | ||||||
| #[function_component(Sidebar)] | #[function_component(Sidebar)] | ||||||
| pub fn sidebar(props: &SidebarProps) -> Html { | pub fn sidebar(props: &SidebarProps) -> Html { | ||||||
|  |     let external_context_menu_open = use_state(|| None::<i32>); | ||||||
|     let on_view_change = { |     let on_view_change = { | ||||||
|         let on_view_change = props.on_view_change.clone(); |         let on_view_change = props.on_view_change.clone(); | ||||||
|         Callback::from(move |e: Event| { |         Callback::from(move |e: Event| { | ||||||
| @@ -155,6 +162,30 @@ pub fn sidebar(props: &SidebarProps) -> Html { | |||||||
|         }) |         }) | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
|  |     let on_external_calendar_context_menu = { | ||||||
|  |         let external_context_menu_open = external_context_menu_open.clone(); | ||||||
|  |         Callback::from(move |(e, cal_id): (MouseEvent, i32)| { | ||||||
|  |             e.prevent_default(); | ||||||
|  |             external_context_menu_open.set(Some(cal_id)); | ||||||
|  |         }) | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     let on_external_calendar_delete = { | ||||||
|  |         let on_external_calendar_delete = props.on_external_calendar_delete.clone(); | ||||||
|  |         let external_context_menu_open = external_context_menu_open.clone(); | ||||||
|  |         Callback::from(move |cal_id: i32| { | ||||||
|  |             on_external_calendar_delete.emit(cal_id); | ||||||
|  |             external_context_menu_open.set(None); | ||||||
|  |         }) | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     let close_external_context_menu = { | ||||||
|  |         let external_context_menu_open = external_context_menu_open.clone(); | ||||||
|  |         Callback::from(move |_| { | ||||||
|  |             external_context_menu_open.set(None); | ||||||
|  |         }) | ||||||
|  |     }; | ||||||
|  |  | ||||||
|     html! { |     html! { | ||||||
|         <aside class="app-sidebar"> |         <aside class="app-sidebar"> | ||||||
|             <div class="sidebar-header"> |             <div class="sidebar-header"> | ||||||
| @@ -192,6 +223,7 @@ pub fn sidebar(props: &SidebarProps) -> Html { | |||||||
|                                                     on_color_picker_toggle={props.on_color_picker_toggle.clone()} |                                                     on_color_picker_toggle={props.on_color_picker_toggle.clone()} | ||||||
|                                                     available_colors={props.available_colors.clone()} |                                                     available_colors={props.available_colors.clone()} | ||||||
|                                                     on_context_menu={props.on_calendar_context_menu.clone()} |                                                     on_context_menu={props.on_calendar_context_menu.clone()} | ||||||
|  |                                                     on_visibility_toggle={props.on_calendar_visibility_toggle.clone()} | ||||||
|                                                 /> |                                                 /> | ||||||
|                                             } |                                             } | ||||||
|                                         }).collect::<Html>() |                                         }).collect::<Html>() | ||||||
| @@ -206,11 +238,128 @@ pub fn sidebar(props: &SidebarProps) -> Html { | |||||||
|                     html! {} |                     html! {} | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|  |              | ||||||
|  |             // External calendars section | ||||||
|  |             <div class="external-calendar-list"> | ||||||
|  |                 <h3>{"External Calendars"}</h3> | ||||||
|  |                 { | ||||||
|  |                     if !props.external_calendars.is_empty() { | ||||||
|  |                         html! { | ||||||
|  |                             <ul class="external-calendar-items"> | ||||||
|  |                                 { | ||||||
|  |                                     props.external_calendars.iter().map(|cal| { | ||||||
|  |                                         let on_toggle = { | ||||||
|  |                                             let on_external_calendar_toggle = props.on_external_calendar_toggle.clone(); | ||||||
|  |                                             let cal_id = cal.id; | ||||||
|  |                                             Callback::from(move |_| { | ||||||
|  |                                                 on_external_calendar_toggle.emit(cal_id); | ||||||
|  |                                             }) | ||||||
|  |                                         }; | ||||||
|  |                                          | ||||||
|  |                                         html! { | ||||||
|  |                                             <li class="external-calendar-item" style="position: relative;"> | ||||||
|  |                                                 <div  | ||||||
|  |                                                     class="external-calendar-info" | ||||||
|  |                                                     oncontextmenu={{ | ||||||
|  |                                                         let on_context_menu = on_external_calendar_context_menu.clone(); | ||||||
|  |                                                         let cal_id = cal.id; | ||||||
|  |                                                         Callback::from(move |e: MouseEvent| { | ||||||
|  |                                                             on_context_menu.emit((e, cal_id)); | ||||||
|  |                                                         }) | ||||||
|  |                                                     }} | ||||||
|  |                                                 > | ||||||
|  |                                                     <input | ||||||
|  |                                                         type="checkbox" | ||||||
|  |                                                         checked={cal.is_visible} | ||||||
|  |                                                         onchange={on_toggle} | ||||||
|  |                                                     /> | ||||||
|  |                                                     <span  | ||||||
|  |                                                         class="external-calendar-color"  | ||||||
|  |                                                         style={format!("background-color: {}", cal.color)} | ||||||
|  |                                                     /> | ||||||
|  |                                                     <span class="external-calendar-name">{&cal.name}</span> | ||||||
|  |                                                     <div class="external-calendar-actions"> | ||||||
|  |                                                         { | ||||||
|  |                                                             if let Some(last_fetched) = cal.last_fetched { | ||||||
|  |                                                                 let local_time = last_fetched.with_timezone(&chrono::Local); | ||||||
|  |                                                                 html! { | ||||||
|  |                                                                     <span class="last-updated" title={format!("Last updated: {}", local_time.format("%Y-%m-%d %H:%M"))}> | ||||||
|  |                                                                         {format!("{}", local_time.format("%H:%M"))} | ||||||
|  |                                                                     </span> | ||||||
|  |                                                                 } | ||||||
|  |                                                             } else { | ||||||
|  |                                                                 html! { | ||||||
|  |                                                                     <span class="last-updated">{"Never"}</span> | ||||||
|  |                                                                 } | ||||||
|  |                                                             } | ||||||
|  |                                                         } | ||||||
|  |                                                         <button  | ||||||
|  |                                                             class="external-calendar-refresh-btn"  | ||||||
|  |                                                             title="Refresh calendar" | ||||||
|  |                                                             onclick={{ | ||||||
|  |                                                                 let on_refresh = props.on_external_calendar_refresh.clone(); | ||||||
|  |                                                                 let cal_id = cal.id; | ||||||
|  |                                                                 Callback::from(move |e: MouseEvent| { | ||||||
|  |                                                                     e.stop_propagation(); | ||||||
|  |                                                                     on_refresh.emit(cal_id); | ||||||
|  |                                                                 }) | ||||||
|  |                                                             }} | ||||||
|  |                                                         > | ||||||
|  |                                                             {"🔄"} | ||||||
|  |                                                         </button> | ||||||
|  |                                                     </div> | ||||||
|  |                                                 </div> | ||||||
|  |                                                 { | ||||||
|  |                                                     if *external_context_menu_open == Some(cal.id) { | ||||||
|  |                                                         html! { | ||||||
|  |                                                             <> | ||||||
|  |                                                                 <div  | ||||||
|  |                                                                     class="context-menu-overlay"  | ||||||
|  |                                                                     onclick={close_external_context_menu.clone()} | ||||||
|  |                                                                     style="position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; z-index: 999;" | ||||||
|  |                                                                 /> | ||||||
|  |                                                                 <div class="context-menu" style="position: absolute; top: 0; right: 0; background: white; border: 1px solid #ccc; border-radius: 4px; box-shadow: 0 2px 8px rgba(0,0,0,0.15); z-index: 1000; min-width: 120px;"> | ||||||
|  |                                                                     <div  | ||||||
|  |                                                                         class="context-menu-item"  | ||||||
|  |                                                                         style="padding: 8px 12px; cursor: pointer; color: #d73a49;" | ||||||
|  |                                                                         onclick={{ | ||||||
|  |                                                                             let on_delete = on_external_calendar_delete.clone(); | ||||||
|  |                                                                             let cal_id = cal.id; | ||||||
|  |                                                                             Callback::from(move |_| { | ||||||
|  |                                                                                 on_delete.emit(cal_id); | ||||||
|  |                                                                             }) | ||||||
|  |                                                                         }} | ||||||
|  |                                                                     > | ||||||
|  |                                                                         {"Delete Calendar"} | ||||||
|  |                                                                     </div> | ||||||
|  |                                                                 </div> | ||||||
|  |                                                             </> | ||||||
|  |                                                         } | ||||||
|  |                                                     } else { | ||||||
|  |                                                         html! {} | ||||||
|  |                                                     } | ||||||
|  |                                                 } | ||||||
|  |                                             </li> | ||||||
|  |                                         } | ||||||
|  |                                     }).collect::<Html>() | ||||||
|  |                                 } | ||||||
|  |                             </ul> | ||||||
|  |                         } | ||||||
|  |                     } else { | ||||||
|  |                         html! {} | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |             </div> | ||||||
|  |              | ||||||
|             <div class="sidebar-footer"> |             <div class="sidebar-footer"> | ||||||
|                 <button onclick={props.on_create_calendar.reform(|_| ())} class="create-calendar-button"> |                 <button onclick={props.on_create_calendar.reform(|_| ())} class="create-calendar-button"> | ||||||
|                     {"+ Create Calendar"} |                     {"+ Create Calendar"} | ||||||
|                 </button> |                 </button> | ||||||
|                  |                  | ||||||
|  |                 <button onclick={props.on_create_external_calendar.reform(|_| ())} class="create-external-calendar-button"> | ||||||
|  |                     {"+ Add External Calendar"} | ||||||
|  |                 </button> | ||||||
|  |  | ||||||
|                 <div class="view-selector"> |                 <div class="view-selector"> | ||||||
|                     <select class="view-selector-dropdown" onchange={on_view_change}> |                     <select class="view-selector-dropdown" onchange={on_view_change}> | ||||||
|                         <option value="month" selected={matches!(props.current_view, ViewMode::Month)}>{"Month"}</option> |                         <option value="month" selected={matches!(props.current_view, ViewMode::Month)}>{"Month"}</option> | ||||||
|   | |||||||
| @@ -1,6 +1,6 @@ | |||||||
| use crate::components::{EventCreationData, RecurringEditAction, RecurringEditModal}; | use crate::components::{EventCreationData, RecurringEditAction, RecurringEditModal}; | ||||||
| use crate::models::ical::VEvent; | use crate::models::ical::VEvent; | ||||||
| use crate::services::calendar_service::UserInfo; | use crate::services::calendar_service::{UserInfo, ExternalCalendar}; | ||||||
| use chrono::{Datelike, Duration, Local, NaiveDate, NaiveDateTime, NaiveTime, Timelike, Weekday}; | use chrono::{Datelike, Duration, Local, NaiveDate, NaiveDateTime, NaiveTime, Timelike, Weekday}; | ||||||
| use std::collections::HashMap; | use std::collections::HashMap; | ||||||
| use web_sys::MouseEvent; | use web_sys::MouseEvent; | ||||||
| @@ -17,6 +17,8 @@ pub struct WeekViewProps { | |||||||
|     #[prop_or_default] |     #[prop_or_default] | ||||||
|     pub user_info: Option<UserInfo>, |     pub user_info: Option<UserInfo>, | ||||||
|     #[prop_or_default] |     #[prop_or_default] | ||||||
|  |     pub external_calendars: Vec<ExternalCalendar>, | ||||||
|  |     #[prop_or_default] | ||||||
|     pub on_event_context_menu: Option<Callback<(web_sys::MouseEvent, VEvent)>>, |     pub on_event_context_menu: Option<Callback<(web_sys::MouseEvent, VEvent)>>, | ||||||
|     #[prop_or_default] |     #[prop_or_default] | ||||||
|     pub on_calendar_context_menu: Option<Callback<(web_sys::MouseEvent, NaiveDate)>>, |     pub on_calendar_context_menu: Option<Callback<(web_sys::MouseEvent, NaiveDate)>>, | ||||||
| @@ -81,8 +83,20 @@ pub fn week_view(props: &WeekViewProps) -> Html { | |||||||
|  |  | ||||||
|     // Helper function to get calendar color for an event |     // Helper function to get calendar color for an event | ||||||
|     let get_event_color = |event: &VEvent| -> String { |     let get_event_color = |event: &VEvent| -> String { | ||||||
|         if let Some(user_info) = &props.user_info { |  | ||||||
|         if let Some(calendar_path) = &event.calendar_path { |         if let Some(calendar_path) = &event.calendar_path { | ||||||
|  |             // Check external calendars first (path format: "external_{id}") | ||||||
|  |             if calendar_path.starts_with("external_") { | ||||||
|  |                 if let Ok(id_str) = calendar_path.strip_prefix("external_").unwrap_or("").parse::<i32>() { | ||||||
|  |                     if let Some(external_calendar) = props.external_calendars | ||||||
|  |                         .iter() | ||||||
|  |                         .find(|cal| cal.id == id_str) | ||||||
|  |                     { | ||||||
|  |                         return external_calendar.color.clone(); | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |             // Check regular calendars | ||||||
|  |             else if let Some(user_info) = &props.user_info { | ||||||
|                 if let Some(calendar) = user_info |                 if let Some(calendar) = user_info | ||||||
|                     .calendars |                     .calendars | ||||||
|                     .iter() |                     .iter() | ||||||
| @@ -95,8 +109,8 @@ pub fn week_view(props: &WeekViewProps) -> Html { | |||||||
|         "#3B82F6".to_string() |         "#3B82F6".to_string() | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
|     // Generate time labels - 24 hours plus the final midnight boundary |     // Generate time labels - 24 hours | ||||||
|     let mut time_labels: Vec<String> = (0..24) |     let time_labels: Vec<String> = (0..24) | ||||||
|         .map(|hour| { |         .map(|hour| { | ||||||
|             if hour == 0 { |             if hour == 0 { | ||||||
|                 "12 AM".to_string() |                 "12 AM".to_string() | ||||||
| @@ -110,9 +124,6 @@ pub fn week_view(props: &WeekViewProps) -> Html { | |||||||
|         }) |         }) | ||||||
|         .collect(); |         .collect(); | ||||||
|  |  | ||||||
|     // Add the final midnight boundary to show where the day ends |  | ||||||
|     time_labels.push("12 AM".to_string()); |  | ||||||
|  |  | ||||||
|     // Handlers for recurring event modification modal |     // Handlers for recurring event modification modal | ||||||
|     let on_recurring_choice = { |     let on_recurring_choice = { | ||||||
|         let pending_recurring_edit = pending_recurring_edit.clone(); |         let pending_recurring_edit = pending_recurring_edit.clone(); | ||||||
| @@ -319,10 +330,19 @@ pub fn week_view(props: &WeekViewProps) -> Html { | |||||||
|                     week_days.iter().map(|date| { |                     week_days.iter().map(|date| { | ||||||
|                         let is_today = *date == props.today; |                         let is_today = *date == props.today; | ||||||
|                         let weekday_name = get_weekday_name(date.weekday()); |                         let weekday_name = get_weekday_name(date.weekday()); | ||||||
|                         let day_events = props.events.get(date).cloned().unwrap_or_default(); |  | ||||||
|                          |                          | ||||||
|                         // Filter for all-day events only |                         // Collect all-day events that span this date (from any day in the week) | ||||||
|                         let all_day_events: Vec<_> = day_events.iter().filter(|event| event.all_day).collect(); |                         let mut all_day_events: Vec<&VEvent> = Vec::new(); | ||||||
|  |                         for events_list in props.events.values() { | ||||||
|  |                             for event in events_list { | ||||||
|  |                                 if event.all_day && event_spans_date(event, *date) { | ||||||
|  |                                     all_day_events.push(event); | ||||||
|  |                                 } | ||||||
|  |                             } | ||||||
|  |                         } | ||||||
|  |                         // Remove duplicates (same event might appear in multiple day buckets) | ||||||
|  |                         all_day_events.sort_by_key(|e| &e.uid); | ||||||
|  |                         all_day_events.dedup_by_key(|e| &e.uid); | ||||||
|  |  | ||||||
|                         html! { |                         html! { | ||||||
|                             <div class={classes!("week-day-header", if is_today { Some("today") } else { None })}> |                             <div class={classes!("week-day-header", if is_today { Some("today") } else { None })}> | ||||||
| @@ -347,11 +367,27 @@ pub fn week_view(props: &WeekViewProps) -> Html { | |||||||
|                                                         }) |                                                         }) | ||||||
|                                                     }; |                                                     }; | ||||||
|                                                      |                                                      | ||||||
|  |                                                     let oncontextmenu = { | ||||||
|  |                                                         if let Some(callback) = &props.on_event_context_menu { | ||||||
|  |                                                             let callback = callback.clone(); | ||||||
|  |                                                             let event = (*event).clone(); | ||||||
|  |                                                             Some(Callback::from(move |e: web_sys::MouseEvent| { | ||||||
|  |                                                                 e.prevent_default(); | ||||||
|  |                                                                 e.stop_propagation(); // Prevent calendar context menu from also triggering | ||||||
|  |                                                                 callback.emit((e, event.clone())); | ||||||
|  |                                                             })) | ||||||
|  |                                                         } else { | ||||||
|  |                                                             None | ||||||
|  |                                                         } | ||||||
|  |                                                     }; | ||||||
|  |                                                      | ||||||
|                                                     html! { |                                                     html! { | ||||||
|                                                         <div  |                                                         <div  | ||||||
|                                                             class="all-day-event" |                                                             class="all-day-event" | ||||||
|                                                             style={format!("background-color: {}", event_color)} |                                                             style={format!("background-color: {}", event_color)} | ||||||
|  |                                                             data-external={event.categories.contains(&"__EXTERNAL_CALENDAR__".to_string()).to_string()} | ||||||
|                                                             {onclick} |                                                             {onclick} | ||||||
|  |                                                             {oncontextmenu} | ||||||
|                                                         > |                                                         > | ||||||
|                                                             <span class="all-day-event-title"> |                                                             <span class="all-day-event-title"> | ||||||
|                                                                 {event.summary.as_ref().unwrap_or(&"Untitled".to_string())} |                                                                 {event.summary.as_ref().unwrap_or(&"Untitled".to_string())} | ||||||
| @@ -373,14 +409,17 @@ pub fn week_view(props: &WeekViewProps) -> Html { | |||||||
|  |  | ||||||
|             // Scrollable content area with time grid |             // Scrollable content area with time grid | ||||||
|             <div class="week-content"> |             <div class="week-content"> | ||||||
|                 <div class="time-grid"> |                 <div class={classes!("time-grid", if props.time_increment == 15 { Some("quarter-mode") } else { None })}> | ||||||
|                     // Time labels |                     // Time labels | ||||||
|                     <div class="time-labels"> |                     <div class={classes!("time-labels", if props.time_increment == 15 { Some("quarter-mode") } else { None })}> | ||||||
|                         { |                         { | ||||||
|                             time_labels.iter().enumerate().map(|(index, time)| { |                             time_labels.iter().map(|time| { | ||||||
|                                 let is_final = index == time_labels.len() - 1; |                                 let is_quarter_mode = props.time_increment == 15; | ||||||
|                                 html! { |                                 html! { | ||||||
|                                     <div class={classes!("time-label", if is_final { Some("final-boundary") } else { None })}> |                                     <div class={classes!( | ||||||
|  |                                         "time-label", | ||||||
|  |                                         if is_quarter_mode { Some("quarter-mode") } else { None } | ||||||
|  |                                     )}> | ||||||
|                                         {time} |                                         {time} | ||||||
|                                     </div> |                                     </div> | ||||||
|                                 } |                                 } | ||||||
| @@ -389,12 +428,12 @@ pub fn week_view(props: &WeekViewProps) -> Html { | |||||||
|                     </div> |                     </div> | ||||||
|  |  | ||||||
|                     // Day columns |                     // Day columns | ||||||
|                     <div class="week-days-grid"> |                     <div class={classes!("week-days-grid", if props.time_increment == 15 { Some("quarter-mode") } else { None })}> | ||||||
|                         { |                         { | ||||||
|                             week_days.iter().enumerate().map(|(_column_index, date)| { |                             week_days.iter().enumerate().map(|(_column_index, date)| { | ||||||
|                                 let is_today = *date == props.today; |                                 let is_today = *date == props.today; | ||||||
|                                 let day_events = props.events.get(date).cloned().unwrap_or_default(); |                                 let day_events = props.events.get(date).cloned().unwrap_or_default(); | ||||||
|                                 let event_layouts = calculate_event_layout(&day_events, *date); |                                 let event_layouts = calculate_event_layout(&day_events, *date, props.time_increment); | ||||||
|  |  | ||||||
|                                 // Drag event handlers |                                 // Drag event handlers | ||||||
|                                 let drag_state_clone = drag_state.clone(); |                                 let drag_state_clone = drag_state.clone(); | ||||||
| @@ -485,8 +524,8 @@ pub fn week_view(props: &WeekViewProps) -> Html { | |||||||
|                                                 match ¤t_drag.drag_type { |                                                 match ¤t_drag.drag_type { | ||||||
|                                                     DragType::CreateEvent => { |                                                     DragType::CreateEvent => { | ||||||
|                                                         // Calculate start and end times |                                                         // Calculate start and end times | ||||||
|                                                         let start_time = pixels_to_time(current_drag.start_y); |                                                         let start_time = pixels_to_time(current_drag.start_y, time_increment); | ||||||
|                                                         let end_time = pixels_to_time(current_drag.current_y); |                                                         let end_time = pixels_to_time(current_drag.current_y, time_increment); | ||||||
|  |  | ||||||
|                                                         // Ensure start is before end |                                                         // Ensure start is before end | ||||||
|                                                         let (actual_start, actual_end) = if start_time <= end_time { |                                                         let (actual_start, actual_end) = if start_time <= end_time { | ||||||
| @@ -514,7 +553,7 @@ pub fn week_view(props: &WeekViewProps) -> Html { | |||||||
|                                                         let unsnapped_position = current_drag.current_y - current_drag.offset_y; |                                                         let unsnapped_position = current_drag.current_y - current_drag.offset_y; | ||||||
|                                                         // Snap the final position to maintain time increment alignment |                                                         // Snap the final position to maintain time increment alignment | ||||||
|                                                         let event_top_position = snap_to_increment(unsnapped_position, time_increment); |                                                         let event_top_position = snap_to_increment(unsnapped_position, time_increment); | ||||||
|                                                         let new_start_time = pixels_to_time(event_top_position); |                                                         let new_start_time = pixels_to_time(event_top_position, time_increment); | ||||||
|  |  | ||||||
|                                                         // Calculate duration from original event |                                                         // Calculate duration from original event | ||||||
|                                                         let original_duration = if let Some(end) = event.dtend { |                                                         let original_duration = if let Some(end) = event.dtend { | ||||||
| @@ -543,7 +582,7 @@ pub fn week_view(props: &WeekViewProps) -> Html { | |||||||
|                                                     }, |                                                     }, | ||||||
|                                                     DragType::ResizeEventStart(event) => { |                                                     DragType::ResizeEventStart(event) => { | ||||||
|                                                         // Calculate new start time based on drag position |                                                         // Calculate new start time based on drag position | ||||||
|                                                         let new_start_time = pixels_to_time(current_drag.current_y); |                                                         let new_start_time = pixels_to_time(current_drag.current_y, time_increment); | ||||||
|  |  | ||||||
|                                                         // Keep the original end time |                                                         // Keep the original end time | ||||||
|                                                         let original_end = if let Some(end) = event.dtend { |                                                         let original_end = if let Some(end) = event.dtend { | ||||||
| @@ -579,7 +618,7 @@ pub fn week_view(props: &WeekViewProps) -> Html { | |||||||
|                                                     }, |                                                     }, | ||||||
|                                                     DragType::ResizeEventEnd(event) => { |                                                     DragType::ResizeEventEnd(event) => { | ||||||
|                                                         // Calculate new end time based on drag position |                                                         // Calculate new end time based on drag position | ||||||
|                                                         let new_end_time = pixels_to_time(current_drag.current_y); |                                                         let new_end_time = pixels_to_time(current_drag.current_y, time_increment); | ||||||
|  |  | ||||||
|                                                         // Keep the original start time |                                                         // Keep the original start time | ||||||
|                                                         let original_start = event.dtstart.with_timezone(&chrono::Local).naive_local(); |                                                         let original_start = event.dtstart.with_timezone(&chrono::Local).naive_local(); | ||||||
| @@ -628,7 +667,8 @@ pub fn week_view(props: &WeekViewProps) -> Html { | |||||||
|                                         class={classes!( |                                         class={classes!( | ||||||
|                                             "week-day-column", |                                             "week-day-column", | ||||||
|                                             if is_today { Some("today") } else { None }, |                                             if is_today { Some("today") } else { None }, | ||||||
|                                             if is_creating_event { Some("creating-event") } else { None } |                                             if is_creating_event { Some("creating-event") } else { None }, | ||||||
|  |                                             if props.time_increment == 15 { Some("quarter-mode") } else { None } | ||||||
|                                         )} |                                         )} | ||||||
|                                         {onmousedown} |                                         {onmousedown} | ||||||
|                                         {onmousemove} |                                         {onmousemove} | ||||||
| @@ -637,10 +677,21 @@ pub fn week_view(props: &WeekViewProps) -> Html { | |||||||
|                                         // Time slot backgrounds - 24 hour slots to represent full day |                                         // Time slot backgrounds - 24 hour slots to represent full day | ||||||
|                                         { |                                         { | ||||||
|                                             (0..24).map(|_hour| { |                                             (0..24).map(|_hour| { | ||||||
|  |                                                 let slots_per_hour = 60 / props.time_increment; | ||||||
|                                                 html! { |                                                 html! { | ||||||
|                                                     <div class="time-slot"> |                                                     <div class={classes!("time-slot", if props.time_increment == 15 { Some("quarter-mode") } else { None })}> | ||||||
|                                                         <div class="time-slot-half"></div> |                                                         { | ||||||
|                                                         <div class="time-slot-half"></div> |                                                             (0..slots_per_hour).map(|_slot| { | ||||||
|  |                                                                 let slot_class = if props.time_increment == 15 { | ||||||
|  |                                                                     "time-slot-quarter" | ||||||
|  |                                                                 } else { | ||||||
|  |                                                                     "time-slot-half" | ||||||
|  |                                                                 }; | ||||||
|  |                                                                 html! { | ||||||
|  |                                                                     <div class={slot_class}></div> | ||||||
|  |                                                                 } | ||||||
|  |                                                             }).collect::<Html>() | ||||||
|  |                                                         } | ||||||
|                                                     </div> |                                                     </div> | ||||||
|                                                 } |                                                 } | ||||||
|                                             }).collect::<Html>() |                                             }).collect::<Html>() | ||||||
| @@ -650,7 +701,7 @@ pub fn week_view(props: &WeekViewProps) -> Html { | |||||||
|                                         <div class="events-container"> |                                         <div class="events-container"> | ||||||
|                                             { |                                             { | ||||||
|                                                 day_events.iter().enumerate().filter_map(|(event_idx, event)| { |                                                 day_events.iter().enumerate().filter_map(|(event_idx, event)| { | ||||||
|                                                     let (start_pixels, duration_pixels, is_all_day) = calculate_event_position(event, *date); |                                                     let (start_pixels, duration_pixels, is_all_day) = calculate_event_position(event, *date, props.time_increment); | ||||||
|  |  | ||||||
|                                                     // Skip all-day events (they're rendered in the header) |                                                     // Skip all-day events (they're rendered in the header) | ||||||
|                                                     if is_all_day { |                                                     if is_all_day { | ||||||
| @@ -678,7 +729,7 @@ pub fn week_view(props: &WeekViewProps) -> Html { | |||||||
|                                                         let drag_state = drag_state.clone(); |                                                         let drag_state = drag_state.clone(); | ||||||
|                                                         let event_for_drag = event.clone(); |                                                         let event_for_drag = event.clone(); | ||||||
|                                                         let date_for_drag = *date; |                                                         let date_for_drag = *date; | ||||||
|                                                         let _time_increment = props.time_increment; |                                                         let time_increment = props.time_increment; | ||||||
|                                                         Callback::from(move |e: MouseEvent| { |                                                         Callback::from(move |e: MouseEvent| { | ||||||
|                                                             e.stop_propagation(); // Prevent drag-to-create from starting on event clicks |                                                             e.stop_propagation(); // Prevent drag-to-create from starting on event clicks | ||||||
|  |  | ||||||
| @@ -692,7 +743,7 @@ pub fn week_view(props: &WeekViewProps) -> Html { | |||||||
|                                                             let click_y_relative = if click_y_relative > 0.0 { click_y_relative } else { e.offset_y() as f64 }; |                                                             let click_y_relative = if click_y_relative > 0.0 { click_y_relative } else { e.offset_y() as f64 }; | ||||||
|  |  | ||||||
|                                                             // Get event's current position in day column coordinates |                                                             // Get event's current position in day column coordinates | ||||||
|                                                             let (event_start_pixels, _, _) = calculate_event_position(&event_for_drag, date_for_drag); |                                                             let (event_start_pixels, _, _) = calculate_event_position(&event_for_drag, date_for_drag, time_increment); | ||||||
|                                                             let event_start_pixels = event_start_pixels as f64; |                                                             let event_start_pixels = event_start_pixels as f64; | ||||||
|  |  | ||||||
|                                                             // Convert click position to day column coordinates |                                                             // Convert click position to day column coordinates | ||||||
| @@ -869,6 +920,7 @@ pub fn week_view(props: &WeekViewProps) -> Html { | |||||||
|                                                                         column_width |                                                                         column_width | ||||||
|                                                                     ) |                                                                     ) | ||||||
|                                                                 } |                                                                 } | ||||||
|  |                                                                 data-external={event.categories.contains(&"__EXTERNAL_CALENDAR__".to_string()).to_string()} | ||||||
|                                                                 {onclick} |                                                                 {onclick} | ||||||
|                                                                 {oncontextmenu} |                                                                 {oncontextmenu} | ||||||
|                                                                 onmousedown={onmousedown_event} |                                                                 onmousedown={onmousedown_event} | ||||||
| @@ -888,7 +940,7 @@ pub fn week_view(props: &WeekViewProps) -> Html { | |||||||
|                                                                 // Event content |                                                                 // Event content | ||||||
|                                                                 <div class="event-content"> |                                                                 <div class="event-content"> | ||||||
|                                                                     <div class="event-title">{event.summary.as_ref().unwrap_or(&"Untitled".to_string())}</div> |                                                                     <div class="event-title">{event.summary.as_ref().unwrap_or(&"Untitled".to_string())}</div> | ||||||
|                                                                     {if !is_all_day { |                                                                     {if !is_all_day && duration_pixels > 30.0 { | ||||||
|                                                                         html! { <div class="event-time">{time_display}</div> } |                                                                         html! { <div class="event-time">{time_display}</div> } | ||||||
|                                                                     } else { |                                                                     } else { | ||||||
|                                                                         html! {} |                                                                         html! {} | ||||||
| @@ -924,8 +976,8 @@ pub fn week_view(props: &WeekViewProps) -> Html { | |||||||
|                                                             let height = (drag.current_y - drag.start_y).abs().max(20.0); |                                                             let height = (drag.current_y - drag.start_y).abs().max(20.0); | ||||||
|  |  | ||||||
|                                                             // Convert pixels to times for display |                                                             // Convert pixels to times for display | ||||||
|                                                             let start_time = pixels_to_time(start_y); |                                                             let start_time = pixels_to_time(start_y, props.time_increment); | ||||||
|                                                             let end_time = pixels_to_time(end_y); |                                                             let end_time = pixels_to_time(end_y, props.time_increment); | ||||||
|  |  | ||||||
|                                                             html! { |                                                             html! { | ||||||
|                                                                 <div |                                                                 <div | ||||||
| @@ -941,7 +993,7 @@ pub fn week_view(props: &WeekViewProps) -> Html { | |||||||
|                                                             let unsnapped_position = drag.current_y - drag.offset_y; |                                                             let unsnapped_position = drag.current_y - drag.offset_y; | ||||||
|                                                             // Snap the final position to maintain time increment alignment |                                                             // Snap the final position to maintain time increment alignment | ||||||
|                                                             let preview_position = snap_to_increment(unsnapped_position, props.time_increment); |                                                             let preview_position = snap_to_increment(unsnapped_position, props.time_increment); | ||||||
|                                                             let new_start_time = pixels_to_time(preview_position); |                                                             let new_start_time = pixels_to_time(preview_position, props.time_increment); | ||||||
|                                                             let original_duration = if let Some(end) = event.dtend { |                                                             let original_duration = if let Some(end) = event.dtend { | ||||||
|                                                                 end.signed_duration_since(event.dtstart) |                                                                 end.signed_duration_since(event.dtstart) | ||||||
|                                                             } else { |                                                             } else { | ||||||
| @@ -956,15 +1008,20 @@ pub fn week_view(props: &WeekViewProps) -> Html { | |||||||
|                                                                 <div |                                                                 <div | ||||||
|                                                                     class="temp-event-box moving-event" |                                                                     class="temp-event-box moving-event" | ||||||
|                                                                     style={format!("top: {}px; height: {}px; background-color: {}; opacity: 0.7;", preview_position, duration_pixels, event_color)} |                                                                     style={format!("top: {}px; height: {}px; background-color: {}; opacity: 0.7;", preview_position, duration_pixels, event_color)} | ||||||
|  |                                                                     data-external={event.categories.contains(&"__EXTERNAL_CALENDAR__".to_string()).to_string()} | ||||||
|                                                                 > |                                                                 > | ||||||
|                                                                     <div class="event-title">{event.summary.as_ref().unwrap_or(&"Untitled".to_string())}</div> |                                                                     <div class="event-title">{event.summary.as_ref().unwrap_or(&"Untitled".to_string())}</div> | ||||||
|                                                                     <div class="event-time">{format!("{} - {}", new_start_time.format("%I:%M %p"), new_end_time.format("%I:%M %p"))}</div> |                                                                     {if duration_pixels > 30.0 { | ||||||
|  |                                                                         html! { <div class="event-time">{format!("{} - {}", new_start_time.format("%I:%M %p"), new_end_time.format("%I:%M %p"))}</div> } | ||||||
|  |                                                                     } else { | ||||||
|  |                                                                         html! {} | ||||||
|  |                                                                     }} | ||||||
|                                                                 </div> |                                                                 </div> | ||||||
|                                                             } |                                                             } | ||||||
|                                                         }, |                                                         }, | ||||||
|                                                         DragType::ResizeEventStart(event) => { |                                                         DragType::ResizeEventStart(event) => { | ||||||
|                                                             // Show the event being resized from the start |                                                             // Show the event being resized from the start | ||||||
|                                                             let new_start_time = pixels_to_time(drag.current_y); |                                                             let new_start_time = pixels_to_time(drag.current_y, props.time_increment); | ||||||
|                                                             let original_end = if let Some(end) = event.dtend { |                                                             let original_end = if let Some(end) = event.dtend { | ||||||
|                                                                 end.with_timezone(&chrono::Local).naive_local() |                                                                 end.with_timezone(&chrono::Local).naive_local() | ||||||
|                                                             } else { |                                                             } else { | ||||||
| @@ -972,7 +1029,7 @@ pub fn week_view(props: &WeekViewProps) -> Html { | |||||||
|                                                             }; |                                                             }; | ||||||
|  |  | ||||||
|                                                             // Calculate positions for the preview |                                                             // Calculate positions for the preview | ||||||
|                                                             let (original_start_pixels, _, _) = calculate_event_position(event, drag.start_date); |                                                             let (original_start_pixels, _, _) = calculate_event_position(event, drag.start_date, props.time_increment); | ||||||
|                                                             let original_duration = original_end.signed_duration_since(event.dtstart.with_timezone(&chrono::Local).naive_local()); |                                                             let original_duration = original_end.signed_duration_since(event.dtstart.with_timezone(&chrono::Local).naive_local()); | ||||||
|                                                             let original_end_pixels = original_start_pixels + (original_duration.num_minutes() as f32); |                                                             let original_end_pixels = original_start_pixels + (original_duration.num_minutes() as f32); | ||||||
|  |  | ||||||
| @@ -985,19 +1042,24 @@ pub fn week_view(props: &WeekViewProps) -> Html { | |||||||
|                                                                 <div |                                                                 <div | ||||||
|                                                                     class="temp-event-box resizing-event" |                                                                     class="temp-event-box resizing-event" | ||||||
|                                                                     style={format!("top: {}px; height: {}px; background-color: {}; opacity: 0.7;", new_start_pixels, new_height, event_color)} |                                                                     style={format!("top: {}px; height: {}px; background-color: {}; opacity: 0.7;", new_start_pixels, new_height, event_color)} | ||||||
|  |                                                                     data-external={event.categories.contains(&"__EXTERNAL_CALENDAR__".to_string()).to_string()} | ||||||
|                                                                 > |                                                                 > | ||||||
|                                                                     <div class="event-title">{event.summary.as_ref().unwrap_or(&"Untitled".to_string())}</div> |                                                                     <div class="event-title">{event.summary.as_ref().unwrap_or(&"Untitled".to_string())}</div> | ||||||
|                                                                     <div class="event-time">{format!("{} - {}", new_start_time.format("%I:%M %p"), original_end.time().format("%I:%M %p"))}</div> |                                                                     {if new_height > 30.0 { | ||||||
|  |                                                                         html! { <div class="event-time">{format!("{} - {}", new_start_time.format("%I:%M %p"), original_end.time().format("%I:%M %p"))}</div> } | ||||||
|  |                                                                     } else { | ||||||
|  |                                                                         html! {} | ||||||
|  |                                                                     }} | ||||||
|                                                                 </div> |                                                                 </div> | ||||||
|                                                             } |                                                             } | ||||||
|                                                         }, |                                                         }, | ||||||
|                                                         DragType::ResizeEventEnd(event) => { |                                                         DragType::ResizeEventEnd(event) => { | ||||||
|                                                             // Show the event being resized from the end |                                                             // Show the event being resized from the end | ||||||
|                                                             let new_end_time = pixels_to_time(drag.current_y); |                                                             let new_end_time = pixels_to_time(drag.current_y, props.time_increment); | ||||||
|                                                             let original_start = event.dtstart.with_timezone(&chrono::Local).naive_local(); |                                                             let original_start = event.dtstart.with_timezone(&chrono::Local).naive_local(); | ||||||
|  |  | ||||||
|                                                             // Calculate positions for the preview |                                                             // Calculate positions for the preview | ||||||
|                                                             let (original_start_pixels, _, _) = calculate_event_position(event, drag.start_date); |                                                             let (original_start_pixels, _, _) = calculate_event_position(event, drag.start_date, props.time_increment); | ||||||
|  |  | ||||||
|                                                             let new_end_pixels = drag.current_y; |                                                             let new_end_pixels = drag.current_y; | ||||||
|                                                             let new_height = (new_end_pixels - original_start_pixels as f64).max(20.0); |                                                             let new_height = (new_end_pixels - original_start_pixels as f64).max(20.0); | ||||||
| @@ -1008,9 +1070,14 @@ pub fn week_view(props: &WeekViewProps) -> Html { | |||||||
|                                                                 <div |                                                                 <div | ||||||
|                                                                     class="temp-event-box resizing-event" |                                                                     class="temp-event-box resizing-event" | ||||||
|                                                                     style={format!("top: {}px; height: {}px; background-color: {}; opacity: 0.7;", original_start_pixels, new_height, event_color)} |                                                                     style={format!("top: {}px; height: {}px; background-color: {}; opacity: 0.7;", original_start_pixels, new_height, event_color)} | ||||||
|  |                                                                     data-external={event.categories.contains(&"__EXTERNAL_CALENDAR__".to_string()).to_string()} | ||||||
|                                                                 > |                                                                 > | ||||||
|                                                                     <div class="event-title">{event.summary.as_ref().unwrap_or(&"Untitled".to_string())}</div> |                                                                     <div class="event-title">{event.summary.as_ref().unwrap_or(&"Untitled".to_string())}</div> | ||||||
|                                                                     <div class="event-time">{format!("{} - {}", original_start.time().format("%I:%M %p"), new_end_time.format("%I:%M %p"))}</div> |                                                                     {if new_height > 30.0 { | ||||||
|  |                                                                         html! { <div class="event-time">{format!("{} - {}", original_start.time().format("%I:%M %p"), new_end_time.format("%I:%M %p"))}</div> } | ||||||
|  |                                                                     } else { | ||||||
|  |                                                                         html! {} | ||||||
|  |                                                                     }} | ||||||
|                                                                 </div> |                                                                 </div> | ||||||
|                                                             } |                                                             } | ||||||
|                                                         } |                                                         } | ||||||
| @@ -1074,22 +1141,25 @@ fn get_weekday_name(weekday: Weekday) -> &'static str { | |||||||
| } | } | ||||||
|  |  | ||||||
| // Calculate the pixel position of an event based on its time | // Calculate the pixel position of an event based on its time | ||||||
| // Each hour is 60px, so we convert time to pixels | // Snap pixel position based on time increment and grid scaling | ||||||
| // Snap pixel position to 15-minute increments (15px = 15 minutes since 60px = 60 minutes) | // In 30-minute mode: 60px per hour (1px = 1 minute) | ||||||
|  | // In 15-minute mode: 120px per hour (2px = 1 minute) | ||||||
| fn snap_to_increment(pixels: f64, increment: u32) -> f64 { | fn snap_to_increment(pixels: f64, increment: u32) -> f64 { | ||||||
|     let increment_px = increment as f64; // Convert to pixels (1px = 1 minute) |     let pixels_per_minute = if increment == 15 { 2.0 } else { 1.0 }; | ||||||
|  |     let increment_px = increment as f64 * pixels_per_minute; | ||||||
|     (pixels / increment_px).round() * increment_px |     (pixels / increment_px).round() * increment_px | ||||||
| } | } | ||||||
|  |  | ||||||
| // Convert pixel position to time (inverse of time to pixels) | // Convert pixel position to time (inverse of time to pixels) | ||||||
| fn pixels_to_time(pixels: f64) -> NaiveTime { | fn pixels_to_time(pixels: f64, time_increment: u32) -> NaiveTime { | ||||||
|     // Since 60px = 1 hour, pixels directly represent minutes |     let pixels_per_minute = if time_increment == 15 { 2.0 } else { 1.0 }; | ||||||
|     let total_minutes = pixels; // 1px = 1 minute |     let total_minutes = pixels / pixels_per_minute; | ||||||
|     let hours = (total_minutes / 60.0) as u32; |     let hours = (total_minutes / 60.0) as u32; | ||||||
|     let minutes = (total_minutes % 60.0) as u32; |     let minutes = (total_minutes % 60.0) as u32; | ||||||
|  |  | ||||||
|     // Handle midnight boundary - if we're at exactly 1440 pixels (24:00), return midnight |     // Handle midnight boundary - check against scaled boundary | ||||||
|     if total_minutes >= 1440.0 { |     let max_pixels = 1440.0 * pixels_per_minute; // 24 hours in pixels | ||||||
|  |     if pixels >= max_pixels { | ||||||
|         return NaiveTime::from_hms_opt(0, 0, 0).unwrap(); |         return NaiveTime::from_hms_opt(0, 0, 0).unwrap(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -1100,7 +1170,7 @@ fn pixels_to_time(pixels: f64) -> NaiveTime { | |||||||
|     NaiveTime::from_hms_opt(hours, minutes, 0).unwrap_or(NaiveTime::from_hms_opt(0, 0, 0).unwrap()) |     NaiveTime::from_hms_opt(hours, minutes, 0).unwrap_or(NaiveTime::from_hms_opt(0, 0, 0).unwrap()) | ||||||
| } | } | ||||||
|  |  | ||||||
| fn calculate_event_position(event: &VEvent, date: NaiveDate) -> (f32, f32, bool) { | fn calculate_event_position(event: &VEvent, date: NaiveDate, time_increment: u32) -> (f32, f32, bool) { | ||||||
|     // Convert UTC times to local time for display |     // Convert UTC times to local time for display | ||||||
|     let local_start = event.dtstart.with_timezone(&Local); |     let local_start = event.dtstart.with_timezone(&Local); | ||||||
|     let event_date = local_start.date_naive(); |     let event_date = local_start.date_naive(); | ||||||
| @@ -1123,7 +1193,8 @@ fn calculate_event_position(event: &VEvent, date: NaiveDate) -> (f32, f32, bool) | |||||||
|     // Calculate start position in pixels from midnight |     // Calculate start position in pixels from midnight | ||||||
|     let start_hour = local_start.hour() as f32; |     let start_hour = local_start.hour() as f32; | ||||||
|     let start_minute = local_start.minute() as f32; |     let start_minute = local_start.minute() as f32; | ||||||
|     let start_pixels = (start_hour + start_minute / 60.0) * 60.0; // 60px per hour |     let pixels_per_hour = if time_increment == 15 { 120.0 } else { 60.0 }; | ||||||
|  |     let start_pixels = (start_hour + start_minute / 60.0) * pixels_per_hour; | ||||||
|  |  | ||||||
|     // Calculate duration and height |     // Calculate duration and height | ||||||
|     let duration_pixels = if let Some(end) = event.dtend { |     let duration_pixels = if let Some(end) = event.dtend { | ||||||
| @@ -1132,16 +1203,17 @@ fn calculate_event_position(event: &VEvent, date: NaiveDate) -> (f32, f32, bool) | |||||||
|  |  | ||||||
|         // Handle events that span multiple days by capping at midnight |         // Handle events that span multiple days by capping at midnight | ||||||
|         if end_date > date { |         if end_date > date { | ||||||
|             // Event continues past midnight, cap at 24:00 (1440px) |             // Event continues past midnight, cap at 24:00  | ||||||
|             1440.0 - start_pixels |             let max_pixels = 24.0 * pixels_per_hour; | ||||||
|  |             max_pixels - start_pixels | ||||||
|         } else { |         } else { | ||||||
|             let end_hour = local_end.hour() as f32; |             let end_hour = local_end.hour() as f32; | ||||||
|             let end_minute = local_end.minute() as f32; |             let end_minute = local_end.minute() as f32; | ||||||
|             let end_pixels = (end_hour + end_minute / 60.0) * 60.0; |             let end_pixels = (end_hour + end_minute / 60.0) * pixels_per_hour; | ||||||
|             (end_pixels - start_pixels).max(20.0) // Minimum 20px height |             (end_pixels - start_pixels).max(20.0) // Minimum 20px height | ||||||
|         } |         } | ||||||
|     } else { |     } else { | ||||||
|         60.0 // Default 1 hour if no end time |         pixels_per_hour // Default 1 hour if no end time | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
|     (start_pixels, duration_pixels, false) // is_all_day = false |     (start_pixels, duration_pixels, false) // is_all_day = false | ||||||
| @@ -1149,6 +1221,11 @@ fn calculate_event_position(event: &VEvent, date: NaiveDate) -> (f32, f32, bool) | |||||||
|  |  | ||||||
| // Check if two events overlap in time | // Check if two events overlap in time | ||||||
| fn events_overlap(event1: &VEvent, event2: &VEvent) -> bool { | fn events_overlap(event1: &VEvent, event2: &VEvent) -> bool { | ||||||
|  |     // All-day events don't overlap with timed events for width calculation purposes | ||||||
|  |     if event1.all_day || event2.all_day { | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  |      | ||||||
|     let start1 = event1.dtstart.with_timezone(&Local).naive_local(); |     let start1 = event1.dtstart.with_timezone(&Local).naive_local(); | ||||||
|     let end1 = if let Some(end) = event1.dtend { |     let end1 = if let Some(end) = event1.dtend { | ||||||
|         end.with_timezone(&Local).naive_local() |         end.with_timezone(&Local).naive_local() | ||||||
| @@ -1168,13 +1245,18 @@ fn events_overlap(event1: &VEvent, event2: &VEvent) -> bool { | |||||||
| } | } | ||||||
|  |  | ||||||
| // Calculate layout columns for overlapping events | // Calculate layout columns for overlapping events | ||||||
| fn calculate_event_layout(events: &[VEvent], date: NaiveDate) -> Vec<(usize, usize)> { | fn calculate_event_layout(events: &[VEvent], date: NaiveDate, time_increment: u32) -> Vec<(usize, usize)> { | ||||||
|      |      | ||||||
|     // Filter and sort events that should appear on this date |     // Filter and sort events that should appear on this date (excluding all-day events) | ||||||
|     let mut day_events: Vec<_> = events.iter() |     let mut day_events: Vec<_> = events.iter() | ||||||
|         .enumerate() |         .enumerate() | ||||||
|         .filter_map(|(idx, event)| { |         .filter_map(|(idx, event)| { | ||||||
|             let (_, _, _) = calculate_event_position(event, date); |             // Skip all-day events as they don't participate in timed event overlap calculations | ||||||
|  |             if event.all_day { | ||||||
|  |                 return None; | ||||||
|  |             } | ||||||
|  |              | ||||||
|  |             let (_, _, _) = calculate_event_position(event, date, time_increment); | ||||||
|             let local_start = event.dtstart.with_timezone(&Local); |             let local_start = event.dtstart.with_timezone(&Local); | ||||||
|             let event_date = local_start.date_naive(); |             let event_date = local_start.date_naive(); | ||||||
|             if event_date == date ||  |             if event_date == date ||  | ||||||
| @@ -1254,3 +1336,31 @@ fn calculate_event_layout(events: &[VEvent], date: NaiveDate) -> Vec<(usize, usi | |||||||
|      |      | ||||||
|     event_columns |     event_columns | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // Check if an all-day event spans the given date | ||||||
|  | fn event_spans_date(event: &VEvent, date: NaiveDate) -> bool { | ||||||
|  |     let start_date = if event.all_day { | ||||||
|  |         // For all-day events, extract date directly from UTC without timezone conversion | ||||||
|  |         // since all-day events are stored at noon UTC to avoid timezone boundary issues | ||||||
|  |         event.dtstart.date_naive() | ||||||
|  |     } else { | ||||||
|  |         event.dtstart.with_timezone(&Local).date_naive() | ||||||
|  |     }; | ||||||
|  |      | ||||||
|  |     let end_date = if let Some(dtend) = event.dtend { | ||||||
|  |         if event.all_day { | ||||||
|  |             // For all-day events, dtend is set to the day after the last day (RFC 5545) | ||||||
|  |             // Extract date directly from UTC and subtract a day to get actual last day | ||||||
|  |             dtend.date_naive() - chrono::Duration::days(1) | ||||||
|  |         } else { | ||||||
|  |             // For timed events, use timezone conversion | ||||||
|  |             dtend.with_timezone(&Local).date_naive() | ||||||
|  |         } | ||||||
|  |     } else { | ||||||
|  |         // Single day event | ||||||
|  |         start_date | ||||||
|  |     }; | ||||||
|  |      | ||||||
|  |     // Check if the given date falls within the event's date range | ||||||
|  |     date >= start_date && date <= end_date | ||||||
|  | } | ||||||
|   | |||||||
| @@ -1,4 +1,5 @@ | |||||||
| use chrono::{DateTime, Datelike, Duration, NaiveDate, TimeZone, Utc, Weekday}; | use chrono::{DateTime, Datelike, Duration, NaiveDate, TimeZone, Utc, Weekday}; | ||||||
|  | use gloo_storage::{LocalStorage, Storage}; | ||||||
| use serde::{Deserialize, Serialize}; | use serde::{Deserialize, Serialize}; | ||||||
| use std::collections::HashMap; | use std::collections::HashMap; | ||||||
| use wasm_bindgen::JsCast; | use wasm_bindgen::JsCast; | ||||||
| @@ -43,6 +44,7 @@ pub struct CalendarInfo { | |||||||
|     pub path: String, |     pub path: String, | ||||||
|     pub display_name: String, |     pub display_name: String, | ||||||
|     pub color: String, |     pub color: String, | ||||||
|  |     pub is_visible: bool, | ||||||
| } | } | ||||||
|  |  | ||||||
| // CalendarEvent, EventStatus, and EventClass are now imported from shared library | // CalendarEvent, EventStatus, and EventClass are now imported from shared library | ||||||
| @@ -271,8 +273,8 @@ impl CalendarService { | |||||||
|     pub fn expand_recurring_events(events: Vec<VEvent>) -> Vec<VEvent> { |     pub fn expand_recurring_events(events: Vec<VEvent>) -> Vec<VEvent> { | ||||||
|         let mut expanded_events = Vec::new(); |         let mut expanded_events = Vec::new(); | ||||||
|         let today = chrono::Utc::now().date_naive(); |         let today = chrono::Utc::now().date_naive(); | ||||||
|         let start_range = today - Duration::days(30); // Show past 30 days |         let start_range = today - Duration::days(36500); // Show past 100 years (to catch any historical yearly events) | ||||||
|         let end_range = today + Duration::days(365); // Show next 365 days |         let end_range = today + Duration::days(36500); // Show next 100 years | ||||||
|  |  | ||||||
|         for event in events { |         for event in events { | ||||||
|             if let Some(ref rrule) = event.rrule { |             if let Some(ref rrule) = event.rrule { | ||||||
| @@ -440,8 +442,16 @@ impl CalendarService { | |||||||
|                     occurrence_event.dtstart = occurrence_datetime; |                     occurrence_event.dtstart = occurrence_datetime; | ||||||
|                     occurrence_event.dtstamp = chrono::Utc::now(); // Update DTSTAMP for each occurrence |                     occurrence_event.dtstamp = chrono::Utc::now(); // Update DTSTAMP for each occurrence | ||||||
|                      |                      | ||||||
|                     if let Some(end) = base_event.dtend { |  | ||||||
|                         occurrence_event.dtend = Some(end + Duration::days(days_diff)); |                     if let Some(base_end) = base_event.dtend { | ||||||
|  |                         if base_event.all_day { | ||||||
|  |                             // For all-day events, maintain the RFC-5545 end date pattern | ||||||
|  |                             // End date should always be exactly one day after start date | ||||||
|  |                             occurrence_event.dtend = Some(occurrence_datetime + Duration::days(1)); | ||||||
|  |                         } else { | ||||||
|  |                             // For timed events, preserve the original duration | ||||||
|  |                             occurrence_event.dtend = Some(base_end + Duration::days(days_diff)); | ||||||
|  |                         } | ||||||
|                     } |                     } | ||||||
|  |  | ||||||
|                     occurrences.push(occurrence_event); |                     occurrences.push(occurrence_event); | ||||||
| @@ -1241,6 +1251,8 @@ impl CalendarService { | |||||||
|         reminder: String, |         reminder: String, | ||||||
|         recurrence: String, |         recurrence: String, | ||||||
|         recurrence_days: Vec<bool>, |         recurrence_days: Vec<bool>, | ||||||
|  |         recurrence_count: Option<u32>, | ||||||
|  |         recurrence_until: Option<String>, | ||||||
|         calendar_path: Option<String>, |         calendar_path: Option<String>, | ||||||
|     ) -> Result<(), String> { |     ) -> Result<(), String> { | ||||||
|         let window = web_sys::window().ok_or("No global window exists")?; |         let window = web_sys::window().ok_or("No global window exists")?; | ||||||
| @@ -1273,8 +1285,8 @@ impl CalendarService { | |||||||
|                 "recurrence": recurrence, |                 "recurrence": recurrence, | ||||||
|                 "recurrence_days": recurrence_days, |                 "recurrence_days": recurrence_days, | ||||||
|                 "recurrence_interval": 1_u32, // Default interval |                 "recurrence_interval": 1_u32, // Default interval | ||||||
|                 "recurrence_end_date": None as Option<String>, // No end date by default |                 "recurrence_end_date": recurrence_until, | ||||||
|                 "recurrence_count": None as Option<u32>, // No count limit by default |                 "recurrence_count": recurrence_count, | ||||||
|                 "calendar_path": calendar_path |                 "calendar_path": calendar_path | ||||||
|             }); |             }); | ||||||
|             let url = format!("{}/calendar/events/series/create", self.base_url); |             let url = format!("{}/calendar/events/series/create", self.base_url); | ||||||
| @@ -1668,6 +1680,9 @@ impl CalendarService { | |||||||
|         categories: String, |         categories: String, | ||||||
|         reminder: String, |         reminder: String, | ||||||
|         recurrence: String, |         recurrence: String, | ||||||
|  |         recurrence_days: Vec<bool>, | ||||||
|  |         recurrence_count: Option<u32>, | ||||||
|  |         recurrence_until: Option<String>, | ||||||
|         calendar_path: Option<String>, |         calendar_path: Option<String>, | ||||||
|         update_scope: String, |         update_scope: String, | ||||||
|         occurrence_date: Option<String>, |         occurrence_date: Option<String>, | ||||||
| @@ -1696,10 +1711,10 @@ impl CalendarService { | |||||||
|             "categories": categories, |             "categories": categories, | ||||||
|             "reminder": reminder, |             "reminder": reminder, | ||||||
|             "recurrence": recurrence, |             "recurrence": recurrence, | ||||||
|             "recurrence_days": vec![false; 7], // Default - could be enhanced |             "recurrence_days": recurrence_days, | ||||||
|             "recurrence_interval": 1_u32, // Default interval |             "recurrence_interval": 1_u32, // Default interval - could be enhanced to be a parameter | ||||||
|             "recurrence_end_date": None as Option<String>, // No end date by default |             "recurrence_end_date": recurrence_until, | ||||||
|             "recurrence_count": None as Option<u32>, // No count limit by default |             "recurrence_count": recurrence_count, | ||||||
|             "calendar_path": calendar_path, |             "calendar_path": calendar_path, | ||||||
|             "update_scope": update_scope, |             "update_scope": update_scope, | ||||||
|             "occurrence_date": occurrence_date |             "occurrence_date": occurrence_date | ||||||
| @@ -1841,4 +1856,257 @@ impl CalendarService { | |||||||
|  |  | ||||||
|         None |         None | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     // ==================== EXTERNAL CALENDAR METHODS ==================== | ||||||
|  |  | ||||||
|  |     pub async fn get_external_calendars() -> Result<Vec<ExternalCalendar>, String> { | ||||||
|  |         let token = LocalStorage::get::<String>("auth_token") | ||||||
|  |             .map_err(|_| "No authentication token found".to_string())?; | ||||||
|  |  | ||||||
|  |         let window = web_sys::window().ok_or("No global window exists")?; | ||||||
|  |  | ||||||
|  |         let opts = RequestInit::new(); | ||||||
|  |         opts.set_method("GET"); | ||||||
|  |         opts.set_mode(RequestMode::Cors); | ||||||
|  |  | ||||||
|  |         let service = Self::new(); | ||||||
|  |         let url = format!("{}/external-calendars", service.base_url); | ||||||
|  |         let request = Request::new_with_str_and_init(&url, &opts) | ||||||
|  |             .map_err(|e| format!("Request creation failed: {:?}", e))?; | ||||||
|  |  | ||||||
|  |         request | ||||||
|  |             .headers() | ||||||
|  |             .set("Authorization", &format!("Bearer {}", token)) | ||||||
|  |             .map_err(|e| format!("Authorization header setting failed: {:?}", e))?; | ||||||
|  |  | ||||||
|  |         let resp_value = JsFuture::from(window.fetch_with_request(&request)) | ||||||
|  |             .await | ||||||
|  |             .map_err(|e| format!("Request failed: {:?}", e))?; | ||||||
|  |  | ||||||
|  |         let resp: Response = resp_value | ||||||
|  |             .dyn_into() | ||||||
|  |             .map_err(|e| format!("Response casting failed: {:?}", e))?; | ||||||
|  |  | ||||||
|  |         if !resp.ok() { | ||||||
|  |             return Err(format!("HTTP error: {}", resp.status())); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         let json = JsFuture::from(resp.json().unwrap()) | ||||||
|  |             .await | ||||||
|  |             .map_err(|e| format!("JSON parsing failed: {:?}", e))?; | ||||||
|  |  | ||||||
|  |         let external_calendars: Vec<ExternalCalendar> = serde_wasm_bindgen::from_value(json) | ||||||
|  |             .map_err(|e| format!("Deserialization failed: {:?}", e))?; | ||||||
|  |  | ||||||
|  |         Ok(external_calendars) | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     pub async fn create_external_calendar(name: &str, url: &str, color: &str) -> Result<ExternalCalendar, String> { | ||||||
|  |         let token = LocalStorage::get::<String>("auth_token") | ||||||
|  |             .map_err(|_| "No authentication token found".to_string())?; | ||||||
|  |  | ||||||
|  |         let window = web_sys::window().ok_or("No global window exists")?; | ||||||
|  |  | ||||||
|  |         let opts = RequestInit::new(); | ||||||
|  |         opts.set_method("POST"); | ||||||
|  |         opts.set_mode(RequestMode::Cors); | ||||||
|  |  | ||||||
|  |         let body = serde_json::json!({ | ||||||
|  |             "name": name, | ||||||
|  |             "url": url, | ||||||
|  |             "color": color | ||||||
|  |         }); | ||||||
|  |  | ||||||
|  |         let service = Self::new(); | ||||||
|  |         let body_string = serde_json::to_string(&body) | ||||||
|  |             .map_err(|e| format!("JSON serialization failed: {}", e))?; | ||||||
|  |         opts.set_body(&body_string.into()); | ||||||
|  |  | ||||||
|  |         let url = format!("{}/external-calendars", service.base_url); | ||||||
|  |         let request = Request::new_with_str_and_init(&url, &opts) | ||||||
|  |             .map_err(|e| format!("Request creation failed: {:?}", e))?; | ||||||
|  |  | ||||||
|  |         request | ||||||
|  |             .headers() | ||||||
|  |             .set("Authorization", &format!("Bearer {}", token)) | ||||||
|  |             .map_err(|e| format!("Authorization header setting failed: {:?}", e))?; | ||||||
|  |  | ||||||
|  |         request | ||||||
|  |             .headers() | ||||||
|  |             .set("Content-Type", "application/json") | ||||||
|  |             .map_err(|e| format!("Content-Type header setting failed: {:?}", e))?; | ||||||
|  |  | ||||||
|  |         let resp_value = JsFuture::from(window.fetch_with_request(&request)) | ||||||
|  |             .await | ||||||
|  |             .map_err(|e| format!("Request failed: {:?}", e))?; | ||||||
|  |  | ||||||
|  |         let resp: Response = resp_value | ||||||
|  |             .dyn_into() | ||||||
|  |             .map_err(|e| format!("Response casting failed: {:?}", e))?; | ||||||
|  |  | ||||||
|  |         if !resp.ok() { | ||||||
|  |             return Err(format!("HTTP error: {}", resp.status())); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         let json = JsFuture::from(resp.json().unwrap()) | ||||||
|  |             .await | ||||||
|  |             .map_err(|e| format!("JSON parsing failed: {:?}", e))?; | ||||||
|  |  | ||||||
|  |         let external_calendar: ExternalCalendar = serde_wasm_bindgen::from_value(json) | ||||||
|  |             .map_err(|e| format!("Deserialization failed: {:?}", e))?; | ||||||
|  |  | ||||||
|  |         Ok(external_calendar) | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     pub async fn update_external_calendar( | ||||||
|  |         id: i32, | ||||||
|  |         name: &str, | ||||||
|  |         url: &str, | ||||||
|  |         color: &str, | ||||||
|  |         is_visible: bool, | ||||||
|  |     ) -> Result<(), String> { | ||||||
|  |         let token = LocalStorage::get::<String>("auth_token") | ||||||
|  |             .map_err(|_| "No authentication token found".to_string())?; | ||||||
|  |  | ||||||
|  |         let window = web_sys::window().ok_or("No global window exists")?; | ||||||
|  |  | ||||||
|  |         let opts = RequestInit::new(); | ||||||
|  |         opts.set_method("POST"); | ||||||
|  |         opts.set_mode(RequestMode::Cors); | ||||||
|  |  | ||||||
|  |         let body = serde_json::json!({ | ||||||
|  |             "name": name, | ||||||
|  |             "url": url, | ||||||
|  |             "color": color, | ||||||
|  |             "is_visible": is_visible | ||||||
|  |         }); | ||||||
|  |  | ||||||
|  |         let service = Self::new(); | ||||||
|  |         let body_string = serde_json::to_string(&body) | ||||||
|  |             .map_err(|e| format!("JSON serialization failed: {}", e))?; | ||||||
|  |         opts.set_body(&body_string.into()); | ||||||
|  |  | ||||||
|  |         let url = format!("{}/external-calendars/{}", service.base_url, id); | ||||||
|  |         let request = Request::new_with_str_and_init(&url, &opts) | ||||||
|  |             .map_err(|e| format!("Request creation failed: {:?}", e))?; | ||||||
|  |  | ||||||
|  |         request | ||||||
|  |             .headers() | ||||||
|  |             .set("Authorization", &format!("Bearer {}", token)) | ||||||
|  |             .map_err(|e| format!("Authorization header setting failed: {:?}", e))?; | ||||||
|  |  | ||||||
|  |         request | ||||||
|  |             .headers() | ||||||
|  |             .set("Content-Type", "application/json") | ||||||
|  |             .map_err(|e| format!("Content-Type header setting failed: {:?}", e))?; | ||||||
|  |  | ||||||
|  |         let resp_value = JsFuture::from(window.fetch_with_request(&request)) | ||||||
|  |             .await | ||||||
|  |             .map_err(|e| format!("Request failed: {:?}", e))?; | ||||||
|  |  | ||||||
|  |         let resp: Response = resp_value | ||||||
|  |             .dyn_into() | ||||||
|  |             .map_err(|e| format!("Response casting failed: {:?}", e))?; | ||||||
|  |  | ||||||
|  |         if !resp.ok() { | ||||||
|  |             return Err(format!("HTTP error: {}", resp.status())); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         Ok(()) | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     pub async fn delete_external_calendar(id: i32) -> Result<(), String> { | ||||||
|  |         let token = LocalStorage::get::<String>("auth_token") | ||||||
|  |             .map_err(|_| "No authentication token found".to_string())?; | ||||||
|  |  | ||||||
|  |         let window = web_sys::window().ok_or("No global window exists")?; | ||||||
|  |  | ||||||
|  |         let opts = RequestInit::new(); | ||||||
|  |         opts.set_method("DELETE"); | ||||||
|  |         opts.set_mode(RequestMode::Cors); | ||||||
|  |  | ||||||
|  |         let service = Self::new(); | ||||||
|  |         let url = format!("{}/external-calendars/{}", service.base_url, id); | ||||||
|  |         let request = Request::new_with_str_and_init(&url, &opts) | ||||||
|  |             .map_err(|e| format!("Request creation failed: {:?}", e))?; | ||||||
|  |  | ||||||
|  |         request | ||||||
|  |             .headers() | ||||||
|  |             .set("Authorization", &format!("Bearer {}", token)) | ||||||
|  |             .map_err(|e| format!("Authorization header setting failed: {:?}", e))?; | ||||||
|  |  | ||||||
|  |         let resp_value = JsFuture::from(window.fetch_with_request(&request)) | ||||||
|  |             .await | ||||||
|  |             .map_err(|e| format!("Request failed: {:?}", e))?; | ||||||
|  |  | ||||||
|  |         let resp: Response = resp_value | ||||||
|  |             .dyn_into() | ||||||
|  |             .map_err(|e| format!("Response casting failed: {:?}", e))?; | ||||||
|  |  | ||||||
|  |         if !resp.ok() { | ||||||
|  |             return Err(format!("HTTP error: {}", resp.status())); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         Ok(()) | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     pub async fn fetch_external_calendar_events(id: i32) -> Result<Vec<VEvent>, String> { | ||||||
|  |         let token = LocalStorage::get::<String>("auth_token") | ||||||
|  |             .map_err(|_| "No authentication token found".to_string())?; | ||||||
|  |  | ||||||
|  |         let window = web_sys::window().ok_or("No global window exists")?; | ||||||
|  |  | ||||||
|  |         let opts = RequestInit::new(); | ||||||
|  |         opts.set_method("GET"); | ||||||
|  |         opts.set_mode(RequestMode::Cors); | ||||||
|  |  | ||||||
|  |         let service = Self::new(); | ||||||
|  |         let url = format!("{}/external-calendars/{}/events", service.base_url, id); | ||||||
|  |         let request = Request::new_with_str_and_init(&url, &opts) | ||||||
|  |             .map_err(|e| format!("Request creation failed: {:?}", e))?; | ||||||
|  |  | ||||||
|  |         request | ||||||
|  |             .headers() | ||||||
|  |             .set("Authorization", &format!("Bearer {}", token)) | ||||||
|  |             .map_err(|e| format!("Authorization header setting failed: {:?}", e))?; | ||||||
|  |  | ||||||
|  |         let resp_value = JsFuture::from(window.fetch_with_request(&request)) | ||||||
|  |             .await | ||||||
|  |             .map_err(|e| format!("Request failed: {:?}", e))?; | ||||||
|  |  | ||||||
|  |         let resp: Response = resp_value | ||||||
|  |             .dyn_into() | ||||||
|  |             .map_err(|e| format!("Response casting failed: {:?}", e))?; | ||||||
|  |  | ||||||
|  |         if !resp.ok() { | ||||||
|  |             return Err(format!("HTTP error: {}", resp.status())); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         let json = JsFuture::from(resp.json().unwrap()) | ||||||
|  |             .await | ||||||
|  |             .map_err(|e| format!("JSON parsing failed: {:?}", e))?; | ||||||
|  |  | ||||||
|  |         #[derive(Deserialize)] | ||||||
|  |         struct ExternalCalendarEventsResponse { | ||||||
|  |             events: Vec<VEvent>, | ||||||
|  |             last_fetched: chrono::DateTime<chrono::Utc>, | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         let response: ExternalCalendarEventsResponse = serde_wasm_bindgen::from_value(json) | ||||||
|  |             .map_err(|e| format!("Deserialization failed: {:?}", e))?; | ||||||
|  |  | ||||||
|  |         Ok(response.events) | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] | ||||||
|  | pub struct ExternalCalendar { | ||||||
|  |     pub id: i32, | ||||||
|  |     pub name: String, | ||||||
|  |     pub url: String, | ||||||
|  |     pub color: String, | ||||||
|  |     pub is_visible: bool, | ||||||
|  |     pub created_at: chrono::DateTime<chrono::Utc>, | ||||||
|  |     pub updated_at: chrono::DateTime<chrono::Utc>, | ||||||
|  |     pub last_fetched: Option<chrono::DateTime<chrono::Utc>>, | ||||||
| } | } | ||||||
|   | |||||||
| @@ -12,6 +12,7 @@ pub struct UserPreferences { | |||||||
|     pub calendar_view_mode: Option<String>, |     pub calendar_view_mode: Option<String>, | ||||||
|     pub calendar_theme: Option<String>, |     pub calendar_theme: Option<String>, | ||||||
|     pub calendar_colors: Option<String>, |     pub calendar_colors: Option<String>, | ||||||
|  |     pub last_used_calendar: Option<String>, | ||||||
| } | } | ||||||
|  |  | ||||||
| #[derive(Debug, Serialize)] | #[derive(Debug, Serialize)] | ||||||
| @@ -22,6 +23,7 @@ pub struct UpdatePreferencesRequest { | |||||||
|     pub calendar_view_mode: Option<String>, |     pub calendar_view_mode: Option<String>, | ||||||
|     pub calendar_theme: Option<String>, |     pub calendar_theme: Option<String>, | ||||||
|     pub calendar_colors: Option<String>, |     pub calendar_colors: Option<String>, | ||||||
|  |     pub last_used_calendar: Option<String>, | ||||||
| } | } | ||||||
|  |  | ||||||
| #[allow(dead_code)] | #[allow(dead_code)] | ||||||
| @@ -61,6 +63,7 @@ impl PreferencesService { | |||||||
|             calendar_view_mode: None, |             calendar_view_mode: None, | ||||||
|             calendar_theme: None, |             calendar_theme: None, | ||||||
|             calendar_colors: None, |             calendar_colors: None, | ||||||
|  |             last_used_calendar: None, | ||||||
|         }); |         }); | ||||||
|          |          | ||||||
|         // Update the specific field |         // Update the specific field | ||||||
| @@ -95,6 +98,7 @@ impl PreferencesService { | |||||||
|             calendar_view_mode: preferences.calendar_view_mode.clone(), |             calendar_view_mode: preferences.calendar_view_mode.clone(), | ||||||
|             calendar_theme: preferences.calendar_theme.clone(), |             calendar_theme: preferences.calendar_theme.clone(), | ||||||
|             calendar_colors: preferences.calendar_colors.clone(), |             calendar_colors: preferences.calendar_colors.clone(), | ||||||
|  |             last_used_calendar: preferences.last_used_calendar.clone(), | ||||||
|         }; |         }; | ||||||
|          |          | ||||||
|         self.sync_preferences(&session_token, &request).await |         self.sync_preferences(&session_token, &request).await | ||||||
| @@ -156,6 +160,7 @@ impl PreferencesService { | |||||||
|             calendar_view_mode: LocalStorage::get::<String>("calendar_view_mode").ok(), |             calendar_view_mode: LocalStorage::get::<String>("calendar_view_mode").ok(), | ||||||
|             calendar_theme: LocalStorage::get::<String>("calendar_theme").ok(), |             calendar_theme: LocalStorage::get::<String>("calendar_theme").ok(), | ||||||
|             calendar_colors: LocalStorage::get::<String>("calendar_colors").ok(), |             calendar_colors: LocalStorage::get::<String>("calendar_colors").ok(), | ||||||
|  |             last_used_calendar: LocalStorage::get::<String>("last_used_calendar").ok(), | ||||||
|         }; |         }; | ||||||
|          |          | ||||||
|         // Only migrate if we have some preferences to migrate |         // Only migrate if we have some preferences to migrate | ||||||
| @@ -164,6 +169,7 @@ impl PreferencesService { | |||||||
|             || request.calendar_view_mode.is_some() |             || request.calendar_view_mode.is_some() | ||||||
|             || request.calendar_theme.is_some() |             || request.calendar_theme.is_some() | ||||||
|             || request.calendar_colors.is_some() |             || request.calendar_colors.is_some() | ||||||
|  |             || request.last_used_calendar.is_some() | ||||||
|         { |         { | ||||||
|             self.sync_preferences(&session_token, &request).await?; |             self.sync_preferences(&session_token, &request).await?; | ||||||
|              |              | ||||||
| @@ -177,4 +183,24 @@ impl PreferencesService { | |||||||
|          |          | ||||||
|         Ok(()) |         Ok(()) | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /// Update the last used calendar and sync with backend | ||||||
|  |     pub async fn update_last_used_calendar(&self, calendar_path: &str) -> Result<(), String> { | ||||||
|  |         // Get session token | ||||||
|  |         let session_token = LocalStorage::get::<String>("session_token") | ||||||
|  |             .map_err(|_| "No session token found".to_string())?; | ||||||
|  |          | ||||||
|  |         // Create minimal update request with only the last used calendar | ||||||
|  |         let request = UpdatePreferencesRequest { | ||||||
|  |             calendar_selected_date: None, | ||||||
|  |             calendar_time_increment: None, | ||||||
|  |             calendar_view_mode: None, | ||||||
|  |             calendar_theme: None, | ||||||
|  |             calendar_colors: None, | ||||||
|  |             last_used_calendar: Some(calendar_path.to_string()), | ||||||
|  |         }; | ||||||
|  |          | ||||||
|  |         // Sync to backend | ||||||
|  |         self.sync_preferences(&session_token, &request).await | ||||||
|  |     } | ||||||
| } | } | ||||||
| @@ -733,7 +733,11 @@ body { | |||||||
| .time-grid { | .time-grid { | ||||||
|     display: grid; |     display: grid; | ||||||
|     grid-template-columns: 80px 1fr; |     grid-template-columns: 80px 1fr; | ||||||
|     min-height: 1530px; |     min-height: 1530px; /* 30-minute mode */ | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .time-grid.quarter-mode { | ||||||
|  |     min-height: 2970px; /* 15-minute mode */ | ||||||
| } | } | ||||||
|  |  | ||||||
| /* Time Labels */ | /* Time Labels */ | ||||||
| @@ -743,9 +747,15 @@ body { | |||||||
|     position: sticky; |     position: sticky; | ||||||
|     left: 0; |     left: 0; | ||||||
|     z-index: 5; |     z-index: 5; | ||||||
|     min-height: 1440px; /* Match the time slots height */ |     min-height: 1530px; /* 30-minute mode */ | ||||||
| } | } | ||||||
|  |  | ||||||
|  | /* Scale time labels container for 15-minute mode */ | ||||||
|  | .time-labels.quarter-mode { | ||||||
|  |     min-height: 2970px; /* 15-minute mode */ | ||||||
|  | } | ||||||
|  |  | ||||||
|  | /* Default time label height for 30-minute mode */ | ||||||
| .time-label { | .time-label { | ||||||
|     height: 60px; |     height: 60px; | ||||||
|     display: flex; |     display: flex; | ||||||
| @@ -758,24 +768,31 @@ body { | |||||||
|     font-weight: 500; |     font-weight: 500; | ||||||
| } | } | ||||||
|  |  | ||||||
| .time-label.final-boundary { | /* Time label height for 15-minute mode - double height */ | ||||||
|     height: 60px; /* Keep same height but this marks the end boundary */ | .time-label.quarter-mode { | ||||||
|     border-bottom: 2px solid #e9ecef; /* Stronger border to show day end */ |     height: 120px; | ||||||
|     color: #999; /* Lighter color to indicate it's the boundary */ |  | ||||||
|     font-size: 0.7rem; |  | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| /* Week Days Grid */ | /* Week Days Grid */ | ||||||
| .week-days-grid { | .week-days-grid { | ||||||
|     display: grid; |     display: grid; | ||||||
|     grid-template-columns: repeat(7, 1fr); |     grid-template-columns: repeat(7, 1fr); | ||||||
|     min-height: 1440px; /* Ensure grid is tall enough for 24 time slots */ |     min-height: 1530px; /* 30-minute mode */ | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .week-days-grid.quarter-mode { | ||||||
|  |     min-height: 2970px; /* 15-minute mode */ | ||||||
| } | } | ||||||
|  |  | ||||||
| .week-day-column { | .week-day-column { | ||||||
|     position: relative; |     position: relative; | ||||||
|     border-right: 1px solid var(--time-label-border, #e9ecef); |     border-right: 1px solid var(--time-label-border, #e9ecef); | ||||||
|     min-height: 1440px; /* 24 time slots × 60px = 1440px total */ |     min-height: 1530px; /* 30-minute mode */ | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .week-day-column.quarter-mode { | ||||||
|  |     min-height: 2970px; /* 15-minute mode */ | ||||||
| } | } | ||||||
|  |  | ||||||
| .week-day-column:last-child { | .week-day-column:last-child { | ||||||
| @@ -788,12 +805,16 @@ body { | |||||||
|  |  | ||||||
| /* Time Slots */ | /* Time Slots */ | ||||||
| .time-slot { | .time-slot { | ||||||
|     height: 60px; |     height: 60px; /* 30-minute mode: 2 slots × 30px = 60px */ | ||||||
|     border-bottom: 1px solid var(--calendar-border, #f0f0f0); |     border-bottom: 1px solid var(--calendar-border, #f0f0f0); | ||||||
|     position: relative; |     position: relative; | ||||||
|     pointer-events: none; /* Don't capture mouse events */ |     pointer-events: none; /* Don't capture mouse events */ | ||||||
| } | } | ||||||
|  |  | ||||||
|  | .time-slot.quarter-mode { | ||||||
|  |     height: 120px; /* 15-minute mode: 4 slots × 30px = 120px */ | ||||||
|  | } | ||||||
|  |  | ||||||
| .time-slot-half { | .time-slot-half { | ||||||
|     height: 30px; |     height: 30px; | ||||||
|     border-bottom: 1px dotted var(--calendar-border, #f5f5f5); |     border-bottom: 1px dotted var(--calendar-border, #f5f5f5); | ||||||
| @@ -804,13 +825,17 @@ body { | |||||||
|     border-bottom: none; |     border-bottom: none; | ||||||
| } | } | ||||||
|  |  | ||||||
| .time-slot.boundary-slot { | .time-slot-quarter { | ||||||
|     height: 60px; /* Match the final time label height */ |     height: 30px; | ||||||
|     border-bottom: 2px solid #e9ecef; /* Strong border to match final boundary */ |     border-bottom: 1px dotted var(--calendar-border-light, #f8f8f8); | ||||||
|     background: rgba(0,0,0,0.02); /* Slightly different background to indicate boundary */ |  | ||||||
|     pointer-events: none; /* Don't capture mouse events */ |     pointer-events: none; /* Don't capture mouse events */ | ||||||
| } | } | ||||||
|  |  | ||||||
|  | .time-slot-quarter:last-child { | ||||||
|  |     border-bottom: none; | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
| /* Events Container */ | /* Events Container */ | ||||||
| .events-container { | .events-container { | ||||||
|     position: absolute; |     position: absolute; | ||||||
| @@ -3242,6 +3267,7 @@ body { | |||||||
|     --accent-color: #667eea; |     --accent-color: #667eea; | ||||||
|     --calendar-bg: white; |     --calendar-bg: white; | ||||||
|     --calendar-border: #f0f0f0; |     --calendar-border: #f0f0f0; | ||||||
|  |     --calendar-border-light: #f8f8f8; | ||||||
|     --calendar-day-bg: white; |     --calendar-day-bg: white; | ||||||
|     --calendar-day-hover: #f8f9ff; |     --calendar-day-hover: #f8f9ff; | ||||||
|     --calendar-day-prev-next: #fafafa; |     --calendar-day-prev-next: #fafafa; | ||||||
| @@ -3275,6 +3301,7 @@ body { | |||||||
|     --accent-color: #2196F3; |     --accent-color: #2196F3; | ||||||
|     --calendar-bg: #ffffff; |     --calendar-bg: #ffffff; | ||||||
|     --calendar-border: #bbdefb; |     --calendar-border: #bbdefb; | ||||||
|  |     --calendar-border-light: #e3f2fd; | ||||||
|     --calendar-day-bg: #ffffff; |     --calendar-day-bg: #ffffff; | ||||||
|     --calendar-day-hover: #e1f5fe; |     --calendar-day-hover: #e1f5fe; | ||||||
|     --calendar-day-prev-next: #f3f8ff; |     --calendar-day-prev-next: #f3f8ff; | ||||||
| @@ -3317,6 +3344,7 @@ body { | |||||||
|     --accent-color: #4CAF50; |     --accent-color: #4CAF50; | ||||||
|     --calendar-bg: #ffffff; |     --calendar-bg: #ffffff; | ||||||
|     --calendar-border: #c8e6c9; |     --calendar-border: #c8e6c9; | ||||||
|  |     --calendar-border-light: #e8f5e8; | ||||||
|     --calendar-day-bg: #ffffff; |     --calendar-day-bg: #ffffff; | ||||||
|     --calendar-day-hover: #f1f8e9; |     --calendar-day-hover: #f1f8e9; | ||||||
|     --calendar-day-prev-next: #f9fbe7; |     --calendar-day-prev-next: #f9fbe7; | ||||||
| @@ -3359,6 +3387,7 @@ body { | |||||||
|     --accent-color: #FF9800; |     --accent-color: #FF9800; | ||||||
|     --calendar-bg: #ffffff; |     --calendar-bg: #ffffff; | ||||||
|     --calendar-border: #ffe0b2; |     --calendar-border: #ffe0b2; | ||||||
|  |     --calendar-border-light: #fff3e0; | ||||||
|     --calendar-day-bg: #ffffff; |     --calendar-day-bg: #ffffff; | ||||||
|     --calendar-day-hover: #fff8e1; |     --calendar-day-hover: #fff8e1; | ||||||
|     --calendar-day-prev-next: #fffde7; |     --calendar-day-prev-next: #fffde7; | ||||||
| @@ -3401,6 +3430,7 @@ body { | |||||||
|     --accent-color: #9C27B0; |     --accent-color: #9C27B0; | ||||||
|     --calendar-bg: #ffffff; |     --calendar-bg: #ffffff; | ||||||
|     --calendar-border: #ce93d8; |     --calendar-border: #ce93d8; | ||||||
|  |     --calendar-border-light: #f3e5f5; | ||||||
|     --calendar-day-bg: #ffffff; |     --calendar-day-bg: #ffffff; | ||||||
|     --calendar-day-hover: #f8e9fc; |     --calendar-day-hover: #f8e9fc; | ||||||
|     --calendar-day-prev-next: #fce4ec; |     --calendar-day-prev-next: #fce4ec; | ||||||
| @@ -3443,6 +3473,7 @@ body { | |||||||
|     --accent-color: #666666; |     --accent-color: #666666; | ||||||
|     --calendar-bg: #1f1f1f; |     --calendar-bg: #1f1f1f; | ||||||
|     --calendar-border: #333333; |     --calendar-border: #333333; | ||||||
|  |     --calendar-border-light: #2a2a2a; | ||||||
|     --calendar-day-bg: #1f1f1f; |     --calendar-day-bg: #1f1f1f; | ||||||
|     --calendar-day-hover: #2a2a2a; |     --calendar-day-hover: #2a2a2a; | ||||||
|     --calendar-day-prev-next: #1a1a1a; |     --calendar-day-prev-next: #1a1a1a; | ||||||
| @@ -3495,6 +3526,7 @@ body { | |||||||
|     --accent-color: #E91E63; |     --accent-color: #E91E63; | ||||||
|     --calendar-bg: #ffffff; |     --calendar-bg: #ffffff; | ||||||
|     --calendar-border: #f8bbd9; |     --calendar-border: #f8bbd9; | ||||||
|  |     --calendar-border-light: #fce4ec; | ||||||
|     --calendar-day-bg: #ffffff; |     --calendar-day-bg: #ffffff; | ||||||
|     --calendar-day-hover: #fdf2f8; |     --calendar-day-hover: #fdf2f8; | ||||||
|     --calendar-day-prev-next: #fef7ff; |     --calendar-day-prev-next: #fef7ff; | ||||||
| @@ -3537,6 +3569,7 @@ body { | |||||||
|     --accent-color: #26A69A; |     --accent-color: #26A69A; | ||||||
|     --calendar-bg: #ffffff; |     --calendar-bg: #ffffff; | ||||||
|     --calendar-border: #b2dfdb; |     --calendar-border: #b2dfdb; | ||||||
|  |     --calendar-border-light: #e0f2f1; | ||||||
|     --calendar-day-bg: #ffffff; |     --calendar-day-bg: #ffffff; | ||||||
|     --calendar-day-hover: #f0fdfc; |     --calendar-day-hover: #f0fdfc; | ||||||
|     --calendar-day-prev-next: #f7ffff; |     --calendar-day-prev-next: #f7ffff; | ||||||
| @@ -3712,3 +3745,383 @@ body { | |||||||
|         grid-template-columns: repeat(2, 1fr); |         grid-template-columns: repeat(2, 1fr); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | /* ==================== EXTERNAL CALENDARS STYLES ==================== */ | ||||||
|  |  | ||||||
|  | /* External Calendar Section in Sidebar */ | ||||||
|  | .external-calendar-list { | ||||||
|  |     margin-bottom: 2rem; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .external-calendar-list h3 { | ||||||
|  |     color: rgba(255, 255, 255, 0.9); | ||||||
|  |     font-size: 0.9rem; | ||||||
|  |     font-weight: 600; | ||||||
|  |     margin-bottom: 1rem; | ||||||
|  |     text-transform: uppercase; | ||||||
|  |     letter-spacing: 0.5px; | ||||||
|  |     padding-left: 0.5rem; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .external-calendar-items { | ||||||
|  |     list-style: none; | ||||||
|  |     margin: 0; | ||||||
|  |     padding: 0; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .external-calendar-item { | ||||||
|  |     margin-bottom: 0.5rem; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .external-calendar-info { | ||||||
|  |     display: flex; | ||||||
|  |     align-items: center; | ||||||
|  |     gap: 0.75rem; | ||||||
|  |     padding: 0.75rem; | ||||||
|  |     border-radius: 8px; | ||||||
|  |     transition: all 0.2s ease; | ||||||
|  |     cursor: pointer; | ||||||
|  |     background: rgba(255, 255, 255, 0.05); | ||||||
|  |     border: 1px solid rgba(255, 255, 255, 0.1); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .external-calendar-info:hover { | ||||||
|  |     background: rgba(255, 255, 255, 0.1); | ||||||
|  |     border-color: rgba(255, 255, 255, 0.2); | ||||||
|  |     transform: translateX(2px); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .external-calendar-info input[type="checkbox"] { | ||||||
|  |     width: 16px; | ||||||
|  |     height: 16px; | ||||||
|  |     accent-color: rgba(255, 255, 255, 0.8); | ||||||
|  |     cursor: pointer; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .external-calendar-color { | ||||||
|  |     width: 12px; | ||||||
|  |     height: 12px; | ||||||
|  |     border-radius: 50%; | ||||||
|  |     border: 1px solid rgba(255, 255, 255, 0.3); | ||||||
|  |     flex-shrink: 0; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .external-calendar-name { | ||||||
|  |     color: rgba(255, 255, 255, 0.9); | ||||||
|  |     font-size: 0.85rem; | ||||||
|  |     font-weight: 500; | ||||||
|  |     flex: 1; | ||||||
|  |     overflow: hidden; | ||||||
|  |     text-overflow: ellipsis; | ||||||
|  |     white-space: nowrap; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .external-calendar-actions { | ||||||
|  |     display: flex; | ||||||
|  |     align-items: center; | ||||||
|  |     gap: 0.5rem; | ||||||
|  |     flex-shrink: 0; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .last-updated { | ||||||
|  |     font-size: 0.7rem; | ||||||
|  |     color: rgba(255, 255, 255, 0.6); | ||||||
|  |     opacity: 0.8; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .external-calendar-refresh-btn { | ||||||
|  |     background: none; | ||||||
|  |     border: none; | ||||||
|  |     color: rgba(255, 255, 255, 0.7); | ||||||
|  |     cursor: pointer; | ||||||
|  |     font-size: 0.8rem; | ||||||
|  |     padding: 2px 4px; | ||||||
|  |     border-radius: 3px; | ||||||
|  |     transition: all 0.2s ease; | ||||||
|  |     line-height: 1; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .external-calendar-refresh-btn:hover { | ||||||
|  |     color: rgba(255, 255, 255, 0.9); | ||||||
|  |     background: rgba(255, 255, 255, 0.1); | ||||||
|  |     transform: rotate(180deg); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .external-calendar-indicator { | ||||||
|  |     font-size: 0.8rem; | ||||||
|  |     opacity: 0.7; | ||||||
|  |     flex-shrink: 0; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | /* CalDAV Calendar Styles */ | ||||||
|  | .calendar-info { | ||||||
|  |     display: flex; | ||||||
|  |     align-items: center; | ||||||
|  |     gap: 0.75rem; | ||||||
|  |     padding: 0.75rem; | ||||||
|  |     border-radius: 8px; | ||||||
|  |     transition: all 0.2s ease; | ||||||
|  |     cursor: pointer; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .calendar-info:hover { | ||||||
|  |     background: rgba(255, 255, 255, 0.1); | ||||||
|  |     transform: translateX(2px); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .calendar-info input[type="checkbox"] { | ||||||
|  |     width: 16px; | ||||||
|  |     height: 16px; | ||||||
|  |     accent-color: rgba(255, 255, 255, 0.8); | ||||||
|  |     cursor: pointer; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | /* Create External Calendar Button */ | ||||||
|  | .create-external-calendar-button { | ||||||
|  |     background: rgba(255, 255, 255, 0.15); | ||||||
|  |     border: 1px solid rgba(255, 255, 255, 0.25); | ||||||
|  |     color: rgba(255, 255, 255, 0.9); | ||||||
|  |     padding: 0.75rem 1rem; | ||||||
|  |     border-radius: 8px; | ||||||
|  |     cursor: pointer; | ||||||
|  |     transition: all 0.2s ease; | ||||||
|  |     margin-bottom: 1rem; | ||||||
|  |     font-size: 0.85rem; | ||||||
|  |     font-weight: 500; | ||||||
|  |     backdrop-filter: blur(10px); | ||||||
|  |     width: 100%; | ||||||
|  |     position: relative; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .create-external-calendar-button::before { | ||||||
|  |     content: ""; | ||||||
|  |     position: absolute; | ||||||
|  |     left: 1rem; | ||||||
|  |     font-size: 0.8rem; | ||||||
|  |     opacity: 0.8; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .create-external-calendar-button { | ||||||
|  |     padding-left: 2.5rem; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .create-external-calendar-button:hover { | ||||||
|  |     background: rgba(255, 255, 255, 0.25); | ||||||
|  |     border-color: rgba(255, 255, 255, 0.4); | ||||||
|  |     transform: translateY(-1px); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .create-external-calendar-button:active { | ||||||
|  |     transform: translateY(0); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | /* External Calendar Modal */ | ||||||
|  | .external-calendar-modal { | ||||||
|  |     background: white; | ||||||
|  |     border-radius: 12px; | ||||||
|  |     box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3); | ||||||
|  |     max-width: 500px; | ||||||
|  |     width: 100%; | ||||||
|  |     max-height: 90vh; | ||||||
|  |     overflow-y: auto; | ||||||
|  |     animation: modalSlideIn 0.3s ease; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .external-calendar-modal .modal-header { | ||||||
|  |     display: flex; | ||||||
|  |     align-items: center; | ||||||
|  |     justify-content: space-between; | ||||||
|  |     padding: 2rem 2rem 1rem; | ||||||
|  |     border-bottom: 1px solid #e9ecef; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .external-calendar-modal .modal-header h3 { | ||||||
|  |     margin: 0; | ||||||
|  |     color: #495057; | ||||||
|  |     font-size: 1.5rem; | ||||||
|  |     font-weight: 600; | ||||||
|  |     display: flex; | ||||||
|  |     align-items: center; | ||||||
|  |     gap: 0.5rem; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .external-calendar-modal .modal-header h3::before { | ||||||
|  |     content: "📅"; | ||||||
|  |     font-size: 1.2rem; | ||||||
|  |     opacity: 0.8; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .external-calendar-modal .modal-close { | ||||||
|  |     background: none; | ||||||
|  |     border: none; | ||||||
|  |     font-size: 1.5rem; | ||||||
|  |     color: #6c757d; | ||||||
|  |     cursor: pointer; | ||||||
|  |     padding: 0.5rem; | ||||||
|  |     border-radius: 50%; | ||||||
|  |     width: 2.5rem; | ||||||
|  |     height: 2.5rem; | ||||||
|  |     display: flex; | ||||||
|  |     align-items: center; | ||||||
|  |     justify-content: center; | ||||||
|  |     transition: all 0.2s ease; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .external-calendar-modal .modal-close:hover { | ||||||
|  |     background: #f8f9fa; | ||||||
|  |     color: #495057; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .external-calendar-modal .modal-body { | ||||||
|  |     padding: 1.5rem 2rem 2rem; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .external-calendar-modal .form-group { | ||||||
|  |     margin-bottom: 1.5rem; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .external-calendar-modal .form-group label { | ||||||
|  |     display: block; | ||||||
|  |     margin-bottom: 0.5rem; | ||||||
|  |     font-weight: 600; | ||||||
|  |     color: #495057; | ||||||
|  |     font-size: 0.9rem; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .external-calendar-modal .form-group input[type="text"], | ||||||
|  | .external-calendar-modal .form-group input[type="url"] { | ||||||
|  |     width: 100%; | ||||||
|  |     padding: 0.75rem; | ||||||
|  |     border: 1px solid #ced4da; | ||||||
|  |     border-radius: 8px; | ||||||
|  |     font-size: 0.9rem; | ||||||
|  |     transition: all 0.2s ease; | ||||||
|  |     background: white; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .external-calendar-modal .form-group input[type="text"]:focus, | ||||||
|  | .external-calendar-modal .form-group input[type="url"]:focus { | ||||||
|  |     outline: none; | ||||||
|  |     border-color: var(--primary-color, #667eea); | ||||||
|  |     box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.1); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .external-calendar-modal .form-group input[type="color"] { | ||||||
|  |     width: 80px; | ||||||
|  |     height: 40px; | ||||||
|  |     padding: 0; | ||||||
|  |     border: 1px solid #ced4da; | ||||||
|  |     border-radius: 8px; | ||||||
|  |     cursor: pointer; | ||||||
|  |     background: none; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .external-calendar-modal .form-help { | ||||||
|  |     display: block; | ||||||
|  |     margin-top: 0.5rem; | ||||||
|  |     font-size: 0.8rem; | ||||||
|  |     color: #6c757d; | ||||||
|  |     font-style: italic; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .external-calendar-modal .modal-actions { | ||||||
|  |     display: flex; | ||||||
|  |     gap: 1rem; | ||||||
|  |     justify-content: flex-end; | ||||||
|  |     padding: 1.5rem 2rem; | ||||||
|  |     border-top: 1px solid #e9ecef; | ||||||
|  |     background: #f8f9fa; | ||||||
|  |     border-radius: 0 0 12px 12px; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .external-calendar-modal .btn { | ||||||
|  |     padding: 0.75rem 1.5rem; | ||||||
|  |     border-radius: 8px; | ||||||
|  |     font-size: 0.9rem; | ||||||
|  |     font-weight: 600; | ||||||
|  |     cursor: pointer; | ||||||
|  |     transition: all 0.2s ease; | ||||||
|  |     border: none; | ||||||
|  |     min-width: 100px; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .external-calendar-modal .btn-secondary { | ||||||
|  |     background: #6c757d; | ||||||
|  |     color: white; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .external-calendar-modal .btn-secondary:hover:not(:disabled) { | ||||||
|  |     background: #5a6268; | ||||||
|  |     transform: translateY(-1px); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .external-calendar-modal .btn-primary { | ||||||
|  |     background: var(--primary-gradient, linear-gradient(135deg, #667eea 0%, #764ba2 100%)); | ||||||
|  |     color: white; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .external-calendar-modal .btn-primary:hover:not(:disabled) { | ||||||
|  |     filter: brightness(1.1); | ||||||
|  |     transform: translateY(-1px); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .external-calendar-modal .btn:disabled { | ||||||
|  |     opacity: 0.6; | ||||||
|  |     cursor: not-allowed; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .external-calendar-modal .error-message { | ||||||
|  |     background: #f8d7da; | ||||||
|  |     color: #721c24; | ||||||
|  |     padding: 0.75rem 1rem; | ||||||
|  |     border-radius: 8px; | ||||||
|  |     margin-bottom: 1rem; | ||||||
|  |     font-size: 0.9rem; | ||||||
|  |     border: 1px solid #f5c6cb; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | /* External Calendar Events (Visual Distinction) */ | ||||||
|  | .event[data-external="true"] { | ||||||
|  |     position: relative; | ||||||
|  |     border-style: dashed !important; | ||||||
|  |     opacity: 0.85; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .event[data-external="true"]::before { | ||||||
|  |     content: "📅"; | ||||||
|  |     position: absolute; | ||||||
|  |     top: 2px; | ||||||
|  |     right: 2px; | ||||||
|  |     font-size: 0.7rem; | ||||||
|  |     opacity: 0.7; | ||||||
|  |     z-index: 1; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | /* Mobile Responsive */ | ||||||
|  | @media (max-width: 768px) { | ||||||
|  |     .external-calendar-modal { | ||||||
|  |         max-height: 95vh; | ||||||
|  |         margin: 1rem; | ||||||
|  |         width: calc(100% - 2rem); | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     .external-calendar-modal .modal-header, | ||||||
|  |     .external-calendar-modal .modal-body, | ||||||
|  |     .external-calendar-modal .modal-actions { | ||||||
|  |         padding-left: 1.5rem; | ||||||
|  |         padding-right: 1.5rem; | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     .external-calendar-info { | ||||||
|  |         padding: 0.5rem; | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     .external-calendar-name { | ||||||
|  |         font-size: 0.8rem; | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     .create-external-calendar-button { | ||||||
|  |         font-size: 0.8rem; | ||||||
|  |         padding: 0.5rem 1rem 0.5rem 2rem; | ||||||
|  |     } | ||||||
|  | } | ||||||
|   | |||||||
| @@ -648,6 +648,16 @@ body { | |||||||
|     border-bottom: none; |     border-bottom: none; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | .time-slot-quarter { | ||||||
|  |     height: 30px; | ||||||
|  |     border-bottom: 1px dotted var(--calendar-border-light, #f8f8f8); | ||||||
|  |     pointer-events: none; /* Don't capture mouse events */ | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .time-slot-quarter:last-child { | ||||||
|  |     border-bottom: none; | ||||||
|  | } | ||||||
|  |  | ||||||
| .time-slot.boundary-slot { | .time-slot.boundary-slot { | ||||||
|     height: 60px; /* Match the final time label height */ |     height: 60px; /* Match the final time label height */ | ||||||
|     border-bottom: 2px solid #e9ecef; /* Strong border to match final boundary */ |     border-bottom: 2px solid #e9ecef; /* Strong border to match final boundary */ | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user