diff --git a/src/lib/api.ts b/src/lib/api.ts index bcbe8e9..e07fb17 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -3,8 +3,8 @@ import { toast } from 'sonner'; import { getToken, clearToken } from './auth'; // Set up API base URLs -const USER_DATA_API_URL = 'https://io-userdata.monasefloadbalancer.ir'; -const DATA_API_URL = 'https://io-data.monasefloadbalancer.ir/api'; +const USER_DATA_API_URL = 'http://127.0.0.1:5001'; +const DATA_API_URL = 'http://127.0.0.1:5002/api'; // Create axios instances const userDataApi = axios.create({ @@ -87,43 +87,32 @@ export const getAllFeeds = async () => { } }; -export const updateFeed = async (feedId: string, name: string, isPublic: boolean) => { - const token = getToken(); - if (!token) throw new Error('Authentication required'); - - const response = await userDataApi.patch('/api/updatefeed', { - feedId, - Name: name, - IsPublic: isPublic, - }, { - headers: { - Authorization: `Bearer ${token}` - } - }); - - return response.data; -}; - export const addNewFeed = async (name: string, isPublic: boolean) => { - const token = getToken(); - if (!token) throw new Error('Authentication required'); - try { - const response = await userDataApi.post('/api/addnewfeed', { - Name: name, - IsPublic: isPublic - }, { - headers: { - Authorization: `Bearer ${token}`, - 'Content-Type': 'application/json' + const token = getToken(); + if (!token) { + throw new Error('Authentication required'); + } + + const response = await userDataApi.post( + '/api/addnewfeed', + { + Name: name, + IsPublic: isPublic, + }, + { + headers: { + Authorization: `Bearer ${token}`, + }, } - }); + ); return response.data; } catch (error: any) { throw error.response?.data || { success: false, message: 'Network error' }; } }; + export const deleteFeed = async (feedId: string) => { try { const response = await userDataApi.delete('/api/deletefeed', { diff --git a/src/lib/types.ts b/src/lib/types.ts index 4887307..3a21c3d 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -25,7 +25,7 @@ export interface ApiKeyResponse { apiKey: string; } -// New ApiKey Typez +// New ApiKey Type export interface ApiKey { createdAt: string; key: string; @@ -37,11 +37,17 @@ export interface Feed { createdAt: string; } +export interface AddFeedRequest { + Name: string; + IsPublic: boolean; +} + export interface AddFeedResponse { success: boolean; feedId: string; } + export interface FeedDataPoint { timestamp: string; data: string; diff --git a/src/pages/DashboardPage.tsx b/src/pages/DashboardPage.tsx index 56fb084..6f950e5 100644 --- a/src/pages/DashboardPage.tsx +++ b/src/pages/DashboardPage.tsx @@ -61,7 +61,9 @@ export function DashboardPage() { // Handle add new feed const handleAddNewFeed = async () => { try { - const response = await addNewFeed(); + const defaultName = `Untitled Feed ${new Date().toLocaleString()}`; + const response = await addNewFeed(defaultName); + if (response.success) { toast.success("New feed created successfully"); fetchFeeds(); @@ -122,9 +124,9 @@ export function DashboardPage() {
- + + + ) : ( + "Select a feed to view data" + )} + + +
- {/* Flex container for the select box and button */} -
- + {/* Flex container for the select box and button */} +
+ - {/* Button to refresh feed data */} - -
- + onClick={() => selectedFeed && refreshCurrentFeedData()} + disabled={isLoading || !selectedFeed} + > + + +
+ - - {isLoading ? ( - - ) : !selectedFeed ? ( -
- -

No feed selected

-

- Select a feed from the sidebar to view its data -

-
- ) : feedData.length === 0 ? ( -
- -

No data available

-

- This feed has no data for the selected time range -

-
- ) : ( - - )} -
- + + {isLoading ? ( + + ) : !selectedFeed ? ( +
+ +

No feed selected

+

+ Select a feed from the sidebar to view its data +

+
+ ) : feedData.length === 0 ? ( +
+ +

No data available

+

+ This feed has no data for the selected time range +

+
+ ) : ( + + )} +
+ );