bipinkrish commited on
Commit
1d9a971
·
1 Parent(s): c0addbd
Files changed (3) hide show
  1. src/components/api.ts +12 -12
  2. src/components/types.ts +19 -19
  3. src/lib/utils.ts +3 -3
src/components/api.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { ChatMessage, FileAttachment } from './types'
2
- import { mockFetchChatHistory, mockSendMessage } from './dummy-data'
3
 
4
- const API_BASE_URL = 'https://api.webzero.com'
5
 
6
  export const fetchChatHistory = mockFetchChatHistory;
7
  export const sendMessage = mockSendMessage;
@@ -17,7 +17,7 @@ export const sendMessage = mockSendMessage;
17
  // export async function sendMessage(content: string, files?: File[]): Promise<ChatMessage> {
18
  // const formData = new FormData()
19
  // formData.append('content', content)
20
-
21
  // if (files?.length) {
22
  // files.forEach(file => formData.append('files', file))
23
  // }
@@ -26,7 +26,7 @@ export const sendMessage = mockSendMessage;
26
  // method: 'POST',
27
  // body: formData,
28
  // })
29
-
30
  // if (!response.ok) {
31
  // throw new Error('Failed to send message')
32
  // }
@@ -34,16 +34,16 @@ export const sendMessage = mockSendMessage;
34
  // }
35
 
36
  export async function uploadFile(file: File): Promise<FileAttachment> {
37
- const formData = new FormData()
38
- formData.append('file', file)
39
 
40
  const response = await fetch(`${API_BASE_URL}/upload`, {
41
- method: 'POST',
42
  body: formData,
43
- })
44
 
45
  if (!response.ok) {
46
- throw new Error('Failed to upload file')
47
  }
48
- return response.json()
49
- }
 
1
+ import { ChatMessage, FileAttachment } from "./types";
2
+ import { mockFetchChatHistory, mockSendMessage } from "./dummy-data";
3
 
4
+ const API_BASE_URL = "https://api.webzero.com";
5
 
6
  export const fetchChatHistory = mockFetchChatHistory;
7
  export const sendMessage = mockSendMessage;
 
17
  // export async function sendMessage(content: string, files?: File[]): Promise<ChatMessage> {
18
  // const formData = new FormData()
19
  // formData.append('content', content)
20
+
21
  // if (files?.length) {
22
  // files.forEach(file => formData.append('files', file))
23
  // }
 
26
  // method: 'POST',
27
  // body: formData,
28
  // })
29
+
30
  // if (!response.ok) {
31
  // throw new Error('Failed to send message')
32
  // }
 
34
  // }
35
 
36
  export async function uploadFile(file: File): Promise<FileAttachment> {
37
+ const formData = new FormData();
38
+ formData.append("file", file);
39
 
40
  const response = await fetch(`${API_BASE_URL}/upload`, {
41
+ method: "POST",
42
  body: formData,
43
+ });
44
 
45
  if (!response.ok) {
46
+ throw new Error("Failed to upload file");
47
  }
48
+ return response.json();
49
+ }
src/components/types.ts CHANGED
@@ -1,27 +1,27 @@
1
  export interface ChatMessage {
2
- id: string
3
- content: string
4
- sender: 'user' | 'assistant'
5
- timestamp: string
6
- files?: FileAttachment[]
7
- preview?: string
8
  code?: {
9
- content: string
10
- language: string
11
- version?: string
12
- }
13
- hasPreview?: boolean
14
  }
15
 
16
  export interface FileAttachment {
17
- id: string
18
- name: string
19
- type: string
20
- url: string
21
- size: number
22
  }
23
 
24
  export interface PreviewState {
25
- isFullscreen: boolean
26
- isOpen: boolean
27
- }
 
1
  export interface ChatMessage {
2
+ id: string;
3
+ content: string;
4
+ sender: "user" | "assistant";
5
+ timestamp: string;
6
+ files?: FileAttachment[];
7
+ preview?: string;
8
  code?: {
9
+ content: string;
10
+ language: string;
11
+ version?: string;
12
+ };
13
+ hasPreview?: boolean;
14
  }
15
 
16
  export interface FileAttachment {
17
+ id: string;
18
+ name: string;
19
+ type: string;
20
+ url: string;
21
+ size: number;
22
  }
23
 
24
  export interface PreviewState {
25
+ isFullscreen: boolean;
26
+ isOpen: boolean;
27
+ }
src/lib/utils.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { clsx, type ClassValue } from "clsx"
2
- import { twMerge } from "tailwind-merge"
3
 
4
  export function cn(...inputs: ClassValue[]) {
5
- return twMerge(clsx(inputs))
6
  }
 
1
+ import { clsx, type ClassValue } from "clsx";
2
+ import { twMerge } from "tailwind-merge";
3
 
4
  export function cn(...inputs: ClassValue[]) {
5
+ return twMerge(clsx(inputs));
6
  }