- Added @tailwindcss/typography dependency to package.json and tailwind.config.js. - Updated FolderPicker.vue to include additional properties (isGitRepo, hasDocuments) for directories. - Enhanced Sidebar.vue with folder creation and document handling features, including drag-and-drop functionality. - Implemented createFolder and moveDocument mutations in gql.ts for managing folder and document operations. - Added logic to handle folder creation and document creation prompts in Sidebar.vue. - Updated the layout and interactions in Sidebar.vue to improve user experience.
47 lines
1.4 KiB
TypeScript
47 lines
1.4 KiB
TypeScript
// Minimal GraphQL client — swap for graphql-request if preferred.
|
|
|
|
const API_URL = import.meta.env.VITE_API_URL ?? '/graphql'
|
|
|
|
export async function gql<T = unknown>(
|
|
query: string,
|
|
variables?: Record<string, unknown>,
|
|
): Promise<T> {
|
|
const token = localStorage.getItem('token')
|
|
const res = await fetch(API_URL, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
...(token ? { Authorization: `Bearer ${token}` } : {}),
|
|
},
|
|
body: JSON.stringify({ query, variables }),
|
|
})
|
|
|
|
const json = await res.json()
|
|
if (json.errors?.length) {
|
|
if (json.errors[0].message === 'UNAUTHORIZED') {
|
|
localStorage.removeItem('token')
|
|
localStorage.removeItem('username')
|
|
window.location.href = '/'
|
|
}
|
|
throw new Error(json.errors[0].message)
|
|
}
|
|
return json.data as T
|
|
}
|
|
|
|
export async function createFolder(path: string): Promise<{ createFolder: boolean }> {
|
|
const query = `mutation CreateFolder($path: String!) { createFolder(path: $path) }`
|
|
return gql(query, { path })
|
|
}
|
|
|
|
export async function moveDocument(oldSlug: string, newSlug: string): Promise<{ moveDocument: boolean }> {
|
|
const query = `mutation MoveDocument($oldSlug: String!, $newSlug: String!) { moveDocument(oldSlug: $oldSlug, newSlug: $newSlug) }`
|
|
return gql(query, { oldSlug, newSlug })
|
|
}
|
|
|
|
export async function getFolders(): Promise<{ folders: string[] }> {
|
|
const query = `query GetFolders { folders }`
|
|
return gql(query)
|
|
}
|
|
|
|
|