mirror of
https://github.com/Dvorinka/excalidraw-full.git
synced 2026-07-29 15:43:47 +00:00
feat: full project sync - CI fixes, frontend, workspace API, and all changes
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
export { useAuth } from './useAuth';
|
||||
export { useDrawings } from './useDrawings';
|
||||
export { useTeams } from './useTeams';
|
||||
@@ -0,0 +1,42 @@
|
||||
import { useEffect } from 'react';
|
||||
import { useAuthStore } from '@/stores';
|
||||
import { api } from '@/services';
|
||||
|
||||
export function useAuth() {
|
||||
const { setUser, setSession, setLoading, logout, isAuthenticated } = useAuthStore();
|
||||
|
||||
useEffect(() => {
|
||||
const init = async () => {
|
||||
try {
|
||||
const user = await api.auth.me();
|
||||
setUser(user);
|
||||
} catch {
|
||||
// Not logged in
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
init();
|
||||
}, [setUser, setLoading]);
|
||||
|
||||
const login = async (email: string, password: string) => {
|
||||
const { user, session } = await api.auth.login(email, password);
|
||||
setUser(user);
|
||||
setSession(session);
|
||||
return user;
|
||||
};
|
||||
|
||||
const signup = async (name: string, email: string, password: string) => {
|
||||
const { user, session } = await api.auth.signup(name, email, password);
|
||||
setUser(user);
|
||||
setSession(session);
|
||||
return user;
|
||||
};
|
||||
|
||||
const doLogout = async () => {
|
||||
await api.auth.logout();
|
||||
logout();
|
||||
};
|
||||
|
||||
return { login, signup, logout: doLogout, isAuthenticated };
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import { useEffect, useCallback } from 'react';
|
||||
import { useDrawingStore, useTeamStore } from '@/stores';
|
||||
import { api } from '@/services';
|
||||
|
||||
export function useDrawings() {
|
||||
const { drawings, recentDrawings, setDrawings, setRecentDrawings, setLoading, addDrawing, updateDrawing } = useDrawingStore();
|
||||
const { currentTeam } = useTeamStore();
|
||||
|
||||
const fetchDrawings = useCallback(async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const data = await api.drawings.list(currentTeam?.id);
|
||||
setDrawings(data);
|
||||
setRecentDrawings(data.slice(0, 10));
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [currentTeam?.id, setDrawings, setRecentDrawings, setLoading]);
|
||||
|
||||
useEffect(() => {
|
||||
fetchDrawings();
|
||||
}, [fetchDrawings]);
|
||||
|
||||
const createDrawing = async (title: string, folderId?: string) => {
|
||||
const drawing = await api.drawings.create({
|
||||
title,
|
||||
folder_id: folderId,
|
||||
team_id: currentTeam?.id,
|
||||
});
|
||||
addDrawing(drawing);
|
||||
return drawing;
|
||||
};
|
||||
|
||||
return { drawings, recentDrawings, fetchDrawings, createDrawing, updateDrawing };
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import { useEffect, useCallback } from 'react';
|
||||
import { useTeamStore } from '@/stores';
|
||||
import { api } from '@/services';
|
||||
|
||||
export function useTeams() {
|
||||
const { teams, members, setTeams, setMembers, setLoading, setCurrentTeam } = useTeamStore();
|
||||
|
||||
const fetchTeams = useCallback(async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const data = await api.teams.list();
|
||||
setTeams(data);
|
||||
if (data.length > 0 && !useTeamStore.getState().currentTeam) {
|
||||
setCurrentTeam(data[0]);
|
||||
}
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [setTeams, setCurrentTeam, setLoading]);
|
||||
|
||||
const fetchMembers = useCallback(async (teamId: string) => {
|
||||
const data = await api.teams.members(teamId);
|
||||
setMembers(data);
|
||||
}, [setMembers]);
|
||||
|
||||
useEffect(() => {
|
||||
fetchTeams();
|
||||
}, [fetchTeams]);
|
||||
|
||||
return { teams, members, fetchTeams, fetchMembers, setCurrentTeam };
|
||||
}
|
||||
Reference in New Issue
Block a user