init
This commit is contained in:
@@ -30,7 +30,6 @@ The goal of this task is to add an "Add Server" button and creation functionalit
|
||||
- Cancel and Create buttons with loading state handling.
|
||||
- **Store Integration:** `useServerStore` must provide a `createServer` action that performs `POST /servers` with the appropriate payload (`{ name, password, is_default }`).
|
||||
|
||||
|
||||
# Technical Design
|
||||
|
||||
### Current Implementation
|
||||
@@ -80,7 +79,6 @@ graph LR
|
||||
ServerStore -->|Updates servers list| AppLayout
|
||||
```
|
||||
|
||||
|
||||
# Testing
|
||||
|
||||
### Validation Approach
|
||||
@@ -97,10 +95,9 @@ graph LR
|
||||
- **Validation Error:** Empty server name disables the create button or shows an alert.
|
||||
- **API Error Handling:** Catch and log API failures gracefully.
|
||||
|
||||
|
||||
# Delivery Steps
|
||||
|
||||
### Step 1: Extend server Pinia store with createServer action
|
||||
### * Step 1: Extend server Pinia store with createServer action
|
||||
Extend the server Pinia store with createServer action.
|
||||
- Update `frontend/src/stores/server.ts` to include `createServer(payload: { name: string; password?: string | null; is_default?: boolean })`.
|
||||
- Handle error states, API POST requests to `/servers`, and state updates to push the newly created server to `this.servers`.
|
||||
|
||||
@@ -5,66 +5,36 @@ sessionId: session-260727-090636-1x6i
|
||||
# Requirements
|
||||
|
||||
### Overview & Goals
|
||||
The goal of this task is to adapt the frontend data-loading policy for channels and categories. Previously, all channels and categories were fetched globally once upon initial load. Now, whenever the user swaps servers (or enters a server view), channels and categories should be reloaded specifically for that active server using the backend query parameters (`server_id`) implemented in the previous backend task.
|
||||
The goal of this task is to add an "Add Server" button and creation modal on the frontend (leveraging existing backend server creation endpoints), and investigate/address any server scoping issues with channels and categories when multiple servers exist.
|
||||
|
||||
### Scope
|
||||
- **In Scope**:
|
||||
- Updating `useChannelStore` and `useCategoryStore` in Pinia to accept a `serverId` query parameter when fetching channels and categories.
|
||||
- Updating `src/pages/server/index.vue` (and/or router navigation / lifecycle hooks) to trigger fetching of channels and categories filtered by the current `serverId` whenever the active server changes.
|
||||
- Resetting or clearing channel and category state appropriately when switching servers.
|
||||
- Adding an "Add Server" button in the frontend layout/navigation (e.g. in `AppLayout.vue` or sidebar) with a creation dialog supporting server name, password, and default flags.
|
||||
- Verifying and ensuring that channel and category queries correctly filter and isolate data per server.
|
||||
- **Out of Scope**:
|
||||
- Backend changes (already completed in previous task).
|
||||
- Changes to other entities (servers, messages, etc.) unless directly related to channel/category scoping.
|
||||
- Major backend restructuring (existing CRUD and filter endpoints are already fully implemented).
|
||||
|
||||
### User Stories
|
||||
- **As a user**, when I switch from one server to another, I want the channels and categories list to be reloaded automatically for the newly selected server so that I only see relevant content.
|
||||
- **As a user**, I want an "Add Server" button in the UI so that I can easily create a new server.
|
||||
- **As a user**, when I switch between servers, I want to ensure that channels and categories are strictly scoped to the active server.
|
||||
|
||||
### Functional Requirements
|
||||
1. **Store Actions (`fetchChannels`, `fetchCategories`)**:
|
||||
- Both actions must accept an optional `serverId?: string`.
|
||||
- When `serverId` is provided, requests must be made to `/channels?server_id=...` and `/categories?server_id=...`.
|
||||
2. **Server View Component (`/src/pages/server/index.vue`)**:
|
||||
- On component mount or when `serverId` route parameter changes (e.g. via `watch(() => route.params.serverId, ...)`), trigger fetching of channels and categories for the new `serverId`.
|
||||
- Clear existing channels/categories or show loading states during the fetch transition.
|
||||
1. **Add Server UI (`AppLayout.vue`)**:
|
||||
- Provide a prominent button in the sidebar to open the "Create Server" dialog.
|
||||
- Collect server details (`name`, optional `password`, `is_default`) and call `serverStore.createServer`.
|
||||
- On successful creation, navigate to the new server's view (`/server/${newServer.id}`).
|
||||
2. **Server Scoping Verification**:
|
||||
- Ensure channels and categories fetched for a server correctly correspond to that server ID.
|
||||
|
||||
# Technical Design
|
||||
|
||||
### Current Implementation
|
||||
- Currently, `useSessionStore.loadInitialData()` calls `serverStore.fetchServers()`, `categoryStore.fetchCategories()`, and `channelStore.fetchChannels()` without parameters, retrieving all records from `/channels` and `/categories`.
|
||||
- `src/pages/server/index.vue` displays `channels` from `useChannelStore`, but does not trigger refetching when switching between different servers.
|
||||
|
||||
### Key Decisions
|
||||
- **Query Parameter Usage**: Leverage the backend endpoints `/channels?server_id=<id>` and `/categories?server_id=<id>` that were created previously.
|
||||
- **Store & Lifecycle Integration**: Use Vue router route watchers in `src/pages/server/index.vue` (or a dedicated composable/watcher) to detect `serverId` changes and invoke store fetch actions.
|
||||
- Backend server creation (`POST /servers`) and listing (`GET /servers`) are fully implemented.
|
||||
- Frontend `useServerStore` has `createServer` and `fetchServers`.
|
||||
- `AppLayout.vue` already includes a dialog structure for creating servers triggered by an `mdi-plus` icon in the navigation drawer.
|
||||
|
||||
### Proposed Changes
|
||||
1. **`src/stores/channel.ts`**:
|
||||
- Modify `fetchChannels(serverId?: string)` to build query string `?server_id=${serverId}` if `serverId` is provided.
|
||||
2. **`src/stores/category.ts`**:
|
||||
- Modify `fetchCategories(serverId?: string)` to build query string `?server_id=${serverId}` if `serverId` is provided.
|
||||
3. **`src/pages/server/index.vue`**:
|
||||
- Add a watcher on `route.params.serverId` (or `serverId` prop).
|
||||
- On mount and when `serverId` changes, call `channelStore.fetchChannels(serverId)` and `categoryStore.fetchCategories(serverId)`.
|
||||
|
||||
### File Structure
|
||||
- **Modified Files**:
|
||||
- `frontend/src/stores/channel.ts`
|
||||
- `frontend/src/stores/category.ts`
|
||||
- `frontend/src/pages/server/index.vue`
|
||||
|
||||
### Risks & Mitigations
|
||||
- **Race conditions during rapid server switching**: Mitigated by handling loading states or canceling/ignoring stale promises if necessary, or simply allowing the latest fetch response to overwrite the store state.
|
||||
|
||||
# Delivery Steps
|
||||
|
||||
### ✓ Step 1: Update channel and category stores to support server-scoped fetching
|
||||
Update Pinia stores for channels and categories to support filtered fetching by server_id.
|
||||
- Update `useChannelStore.fetchChannels(serverId?: string)` to accept an optional `serverId` and pass it as a query parameter (`/channels?server_id=...`).
|
||||
- Update `useCategoryStore.fetchCategories(serverId?: string)` to accept an optional `serverId` and pass it as a query parameter (`/categories?server_id=...`).
|
||||
- Clear channels and categories when no server is selected or when swapping servers.
|
||||
|
||||
### ✓ Step 2: Integrate server-scoped data loading into server view and router navigation
|
||||
Integrate server-scoped loading into the server view lifecycle and route changes.
|
||||
- Update `/src/pages/server/index.vue` to watch `serverId` (or trigger on route parameter change / component mount) and fetch channels and categories specifically for the active `serverId`.
|
||||
- Clear channels and categories when switching between servers or leaving the server view.
|
||||
- Ensure proper loading states and error handling during server switching.
|
||||
1. **`frontend/src/layouts/AppLayout.vue`**:
|
||||
- Ensure the server creation dialog and form bindings are fully wired up and intuitive.
|
||||
2. **Review Channel & Category Scoping**:
|
||||
- Verify that `useChannelStore.fetchChannels(serverId)` and `useCategoryStore.fetchCategories(serverId)` correctly pass `server_id` and that the backend filters properly.
|
||||
Reference in New Issue
Block a user