-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f2a0e3d
commit 97c939c
Showing
23 changed files
with
151 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,7 @@ function App() { | |
} | ||
/> | ||
<Route | ||
path="/:id" | ||
path="documents/:id" | ||
element={ | ||
<> | ||
<Sidebar /> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,32 @@ | ||
import { HttpCommunication } from '@/services/communication/http/httpCommunication'; | ||
import { DocumentResource } from '@notespace/shared/src/workspace/types/resource.ts'; | ||
import { DocumentResource, ResourceInputModel, ResourceType } from '@notespace/shared/src/workspace/types/resource.ts'; | ||
|
||
async function getDocument(http: HttpCommunication, id: string): Promise<DocumentResource> { | ||
return await http.get(`/documents/${id}`); | ||
} | ||
function documentServices(http: HttpCommunication, wid: string) { | ||
async function getDocument(id: string): Promise<DocumentResource> { | ||
return await http.get(`/workspaces/${wid}/${id}`); | ||
} | ||
|
||
async function createDocument(http: HttpCommunication): Promise<string> { | ||
const { id } = await http.post('/documents'); | ||
return id; | ||
} | ||
async function createDocument(name: string): Promise<string> { | ||
const resource: ResourceInputModel = { name, type: ResourceType.DOCUMENT }; | ||
const { id } = await http.post(`/workspaces/${wid}`, resource); | ||
return id; | ||
} | ||
|
||
async function deleteDocument(id: string) { | ||
await http.delete(`/workspace/${wid}/${id}`); | ||
} | ||
|
||
async function updateDocument(id: string, name: string) { | ||
const resource: Partial<ResourceInputModel> = { name }; | ||
await http.put(`/workspaces/${wid}/${id}`, resource); | ||
} | ||
|
||
async function deleteDocument(http: HttpCommunication, id: string) { | ||
await http.delete(`/documents/${id}`); | ||
return { | ||
getDocument, | ||
createDocument, | ||
deleteDocument, | ||
updateDocument, | ||
}; | ||
} | ||
|
||
export default { | ||
getDocument, | ||
createDocument, | ||
deleteDocument, | ||
}; | ||
export default documentServices; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,13 @@ | ||
import { HttpCommunication } from '@/services/communication/http/httpCommunication'; | ||
import documentServices from '@/services/documentServices'; | ||
import { useMemo } from 'react'; | ||
import { useCommunication } from '@/services/communication/context/useCommunication.ts'; | ||
import { useParams } from 'react-router-dom'; | ||
|
||
function useDocumentServices(http: HttpCommunication) { | ||
return useMemo( | ||
() => ({ | ||
getDocument: (id: string) => documentServices.getDocument(http, id), | ||
createDocument: () => documentServices.createDocument(http), | ||
deleteDocument: (id: string) => documentServices.deleteDocument(http, id), | ||
}), | ||
[http] | ||
); | ||
function useDocumentServices() { | ||
const { http } = useCommunication(); | ||
const { wid } = useParams(); | ||
if (!wid) throw new Error('Cannot use document services outside of a workspace'); | ||
return useMemo(() => documentServices(http, wid), [http, wid]); | ||
} | ||
|
||
export default useDocumentServices; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.dialog { | ||
.button { | ||
margin: 0 !important; | ||
padding: 0 !important; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
code/client/src/ui/components/sidebar/hooks/useSidebarState.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { useState } from 'react'; | ||
|
||
function useSidebarState() { | ||
const [isOpen, setIsOpen] = useState(false); | ||
const [isLocked, setIsLocked] = useState(false); | ||
const [justClosed, setJustClosed] = useState(false); | ||
|
||
const handleMouseEnter = () => { | ||
if (justClosed) return; | ||
setIsOpen(true); | ||
}; | ||
|
||
const handleClick = () => { | ||
setIsLocked(!isLocked && isOpen); | ||
setIsOpen(!isLocked && !isOpen); | ||
setJustClosed(isLocked); | ||
}; | ||
|
||
const handleMouseLeave = () => { | ||
if (isLocked) return; | ||
setIsOpen(false); | ||
setJustClosed(false); | ||
}; | ||
|
||
return { | ||
isOpen, | ||
isLocked, | ||
handleMouseEnter, | ||
handleClick, | ||
handleMouseLeave, | ||
}; | ||
} | ||
|
||
export default useSidebarState; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +0,0 @@ | ||
.not-found { | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
font-size: 2rem; | ||
font-weight: bold; | ||
text-align: center; | ||
padding: 1rem; | ||
margin: 0; | ||
|
||
:not(:first-child) { | ||
background: black; | ||
color: white; | ||
padding: 1vh 2vh 1vh 2vh; | ||
border-radius: 5px; | ||
} | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.