-
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.
Implemented Simple Version Control System
- Loading branch information
1 parent
6821a73
commit 425238b
Showing
32 changed files
with
493 additions
and
39 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
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 was deleted.
Oops, something went wrong.
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,13 @@ | ||
import { useMemo } from 'react'; | ||
import { useCommunication } from '@/contexts/communication/useCommunication'; | ||
import { useParams } from 'react-router-dom'; | ||
import resourcesService from '@services/resource/resourcesService'; | ||
|
||
function useResourcesService() { | ||
const { http } = useCommunication(); | ||
const { wid } = useParams(); | ||
if (!wid) throw new Error('Cannot use document service outside of a workspace'); | ||
return useMemo(() => resourcesService(http, wid), [http, wid]); | ||
} | ||
|
||
export default useResourcesService; |
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,13 @@ | ||
import { useMemo } from 'react'; | ||
import { useCommunication } from '@/contexts/communication/useCommunication'; | ||
import { useParams } from 'react-router-dom'; | ||
import versionsService from '@services/versions/versionsService'; | ||
|
||
function useVersionsService() { | ||
const { http } = useCommunication(); | ||
const { wid, id } = useParams(); | ||
if (!wid || !id) throw new Error('Cannot use version service outside of a document'); | ||
return useMemo(() => versionsService(http, wid, id), [http, wid, id]); | ||
} | ||
|
||
export default useVersionsService; |
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,29 @@ | ||
import { HttpCommunication } from '@services/communication/http/httpCommunication'; | ||
import { DocumentVersion } from '@notespace/shared/src/document/types/versions'; | ||
|
||
function versionsService(http: HttpCommunication, wid: string, id: string) { | ||
async function commitVersion() { | ||
return await http.post(`/workspaces/${wid}/${id}/commit`); | ||
} | ||
|
||
async function getVersions(): Promise<DocumentVersion[]> { | ||
return await http.get(`/workspaces/${wid}/${id}/versions`); | ||
} | ||
|
||
async function rollbackVersion(versionId: string) { | ||
return await http.post(`/workspaces/${wid}/${id}/rollback`, { versionId }); | ||
} | ||
|
||
async function forkVersion(versionId: string) { | ||
return await http.post(`/workspaces/${wid}/${id}/fork`, { versionId }); | ||
} | ||
|
||
return { | ||
commitVersion, | ||
getVersions, | ||
rollbackVersion, | ||
forkVersion, | ||
}; | ||
} | ||
|
||
export default versionsService; |
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 |
---|---|---|
|
@@ -110,7 +110,7 @@ | |
gap: 4px; | ||
} | ||
|
||
.folder svg { | ||
.folder-resource svg { | ||
color: darkgray; | ||
} | ||
|
||
|
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,2 @@ | ||
.document { | ||
} |
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
29 changes: 29 additions & 0 deletions
29
code/client/src/ui/pages/document/components/history/DocumentCommits.scss
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,29 @@ | ||
.document-commits { | ||
.commit { | ||
padding: 0.5vh 8vh; | ||
border-radius: 10px; | ||
background-color: black; | ||
color: white; | ||
|
||
display: flex; | ||
flex-direction: row; | ||
justify-content: space-between; | ||
width: 100%; | ||
|
||
.commit-actions { | ||
display: flex; | ||
flex-direction: row; | ||
justify-content: space-between; | ||
align-items: center; | ||
gap: 2vh; | ||
|
||
button { | ||
gap: 2vh; | ||
} | ||
} | ||
|
||
a { | ||
color: white; | ||
} | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
code/client/src/ui/pages/document/components/history/DocumentCommits.tsx
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,73 @@ | ||
import './DocumentCommits.scss'; | ||
import useVersionsService from '@services/versions/useVersionsService'; | ||
import { Link, useParams } from 'react-router-dom'; | ||
import useResourcesService from '@services/resource/useResourcesService'; | ||
import { useEffect, useState } from 'react'; | ||
import useLoading from '@ui/hooks/useLoading'; | ||
import { DocumentResource } from '@notespace/shared/src/workspace/types/resource'; | ||
import { DocumentVersion } from '@notespace/shared/src/document/types/versions'; | ||
import { formatTimePassed } from '@/utils/utils'; | ||
import { FaCodeFork } from 'react-icons/fa6'; | ||
import { FaUndo } from 'react-icons/fa'; | ||
|
||
function DocumentCommits() { | ||
const [document, setDocument] = useState<DocumentResource>(); | ||
const [versions, setVersions] = useState<DocumentVersion[]>([]); | ||
const { loading, spinner, startLoading, stopLoading } = useLoading(); | ||
const { id } = useParams(); | ||
const { getResource } = useResourcesService(); | ||
const { getVersions, forkVersion, rollbackVersion } = useVersionsService(); | ||
|
||
useEffect(() => { | ||
async function fetchDocument() { | ||
const document = (await getResource(id!)) as DocumentResource; | ||
setDocument(document); | ||
} | ||
async function fetchVersions() { | ||
const versions = await getVersions(); | ||
setVersions(versions); | ||
} | ||
startLoading(); | ||
Promise.all([fetchDocument(), fetchVersions()]) | ||
.then(() => stopLoading()) | ||
.catch(() => stopLoading()); | ||
}, [getResource, getVersions, id, startLoading, stopLoading]); | ||
|
||
return ( | ||
<div className="document-commits"> | ||
{loading ? ( | ||
spinner | ||
) : ( | ||
<> | ||
<h2>Commits from "{document?.name}"</h2> | ||
<div className="commits-list"> | ||
{versions.length > 0 ? ( | ||
versions.map(version => ( | ||
<div key={version.id} className="commit"> | ||
<p> | ||
<Link to={''}>John Doe</Link> committed{' '} | ||
{formatTimePassed(new Date(version.timestamp).toLocaleString())} | ||
</p> | ||
<div className="commit-actions"> | ||
<button onClick={() => rollbackVersion(version.id)}> | ||
<FaUndo /> | ||
Rollback | ||
</button> | ||
<button onClick={() => forkVersion(version.id)}> | ||
<FaCodeFork /> | ||
Fork | ||
</button> | ||
</div> | ||
</div> | ||
)) | ||
) : ( | ||
<p>No commits yet</p> | ||
)} | ||
</div> | ||
</> | ||
)} | ||
</div> | ||
); | ||
} | ||
|
||
export default DocumentCommits; |
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
40 changes: 40 additions & 0 deletions
40
code/client/src/ui/pages/document/components/version/Version.scss
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,40 @@ | ||
.version { | ||
position: fixed; | ||
bottom: 0; | ||
right: 0; | ||
padding: 4vh; | ||
display: flex; | ||
flex-direction: row; | ||
gap: 2vh; | ||
|
||
button { | ||
background-color: black; | ||
color: white; | ||
border: none; | ||
border-radius: 50%; | ||
width: 50px; | ||
height: 50px; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); | ||
transition: background-color 0.2s; | ||
font-size: 22px; | ||
|
||
&:hover { | ||
background-color: rgba(0, 0, 0, 0.7); | ||
} | ||
|
||
&:focus { | ||
outline: none; | ||
} | ||
} | ||
} | ||
|
||
.commits-dialog { | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: space-evenly; | ||
align-items: start; | ||
padding: 1vh; | ||
} |
21 changes: 21 additions & 0 deletions
21
code/client/src/ui/pages/document/components/version/Version.tsx
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,21 @@ | ||
import './Version.scss'; | ||
import VersionControlDialog from '@ui/pages/document/components/version/VersionControlDialog'; | ||
import useVersionsService from '@services/versions/useVersionsService'; | ||
import { useNavigate, useParams } from 'react-router-dom'; | ||
import { MdHistory } from 'react-icons/md'; | ||
|
||
function Version() { | ||
const { wid, id } = useParams(); | ||
const { commitVersion } = useVersionsService(); | ||
const navigate = useNavigate(); | ||
return ( | ||
<div className="version"> | ||
<VersionControlDialog onCommit={commitVersion} /> | ||
<button onClick={() => navigate(`/workspaces/${wid}/${id}/commits`)}> | ||
<MdHistory /> | ||
</button> | ||
</div> | ||
); | ||
} | ||
|
||
export default Version; |
33 changes: 33 additions & 0 deletions
33
code/client/src/ui/pages/document/components/version/VersionControlDialog.tsx
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,33 @@ | ||
import Dialog from '@ui/components/dialog/Dialog'; | ||
import { useParams } from 'react-router-dom'; | ||
import { FaCodeCommit } from 'react-icons/fa6'; | ||
import { useAuth } from '@/contexts/auth/useAuth'; | ||
|
||
type VersionControlDialogProps = { | ||
onCommit: () => void; | ||
}; | ||
|
||
function VersionControlDialog({ onCommit }: VersionControlDialogProps) { | ||
const { wid, id } = useParams(); | ||
const { currentUser } = useAuth(); | ||
if (!wid || !id) throw new Error('Cannot use version dialog outside of a document'); | ||
return ( | ||
<Dialog | ||
title="New Commit" | ||
fields={[]} | ||
onSubmit={onCommit} | ||
submitText="Commit" | ||
extraContent={ | ||
<div className="commits-dialog"> | ||
<p> | ||
Committing as <strong>{currentUser!.displayName}</strong> | ||
</p> | ||
</div> | ||
} | ||
> | ||
<FaCodeCommit /> | ||
</Dialog> | ||
); | ||
} | ||
|
||
export default VersionControlDialog; |
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,2 +1,5 @@ | ||
.home { | ||
hr { | ||
width: 50%; | ||
} | ||
} |
Oops, something went wrong.