-
Notifications
You must be signed in to change notification settings - Fork 60
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
Showing
13 changed files
with
176 additions
and
64 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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use server' | ||
|
||
import { isCommitDraft } from '@latitude-data/core' | ||
import { z } from 'zod' | ||
|
||
import { authProcedure } from '../procedures' | ||
|
||
export const checkCommitEditableAction = authProcedure | ||
.createServerAction() | ||
.input( | ||
z.object({ | ||
commitUuid: z.string(), | ||
}), | ||
{ type: 'json' }, | ||
) | ||
.handler(async ({ input }) => { | ||
const res = await isCommitDraft({ uuid: input.commitUuid }) | ||
return res.unwrap() | ||
}) |
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,11 @@ | ||
import { DocumentEditor } from '@latitude-data/web-ui' | ||
|
||
export const dynamic = 'force-dynamic' | ||
|
||
export default async function Editor() { | ||
return ( | ||
<div className='w-full h-full relative'> | ||
<DocumentEditor document='' /> | ||
</div> | ||
) | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { | ||
createContext, | ||
ReactNode, | ||
useContext, | ||
useEffect, | ||
useState, | ||
} from 'react' | ||
|
||
import { checkCommitEditableAction } from '$/actions/commits' | ||
|
||
interface CommitContextType { | ||
currentCommit?: string | ||
isCommitEditable: boolean | ||
setCurrentCommit: ({ | ||
commitUuid, | ||
isEditable, | ||
}: { | ||
commitUuid?: string | ||
isEditable: boolean | ||
}) => void | ||
} | ||
|
||
const CommitContext = createContext<CommitContextType>({ | ||
currentCommit: undefined, | ||
isCommitEditable: false, | ||
setCurrentCommit: () => {}, | ||
}) | ||
|
||
export const CommitProvider = ({ children }: { children: ReactNode }) => { | ||
const [currentCommit, setCurrentCommit] = useState<string | undefined>() | ||
const [isCommitEditable, setIsCommitEditable] = useState<boolean>(false) | ||
|
||
useEffect(() => { | ||
const storedCommit = localStorage.getItem('commit') | ||
if (!storedCommit) { | ||
setCurrentCommit(undefined) | ||
setIsCommitEditable(false) | ||
return | ||
} | ||
|
||
setCurrentCommit(storedCommit) | ||
checkCommitEditableAction({ commitUuid: storedCommit }).then((res) => { | ||
setIsCommitEditable(res[0]!) | ||
}) | ||
}, []) | ||
|
||
const updateCurrentCommit = ({ | ||
commitUuid, | ||
isEditable, | ||
}: { | ||
commitUuid?: string | ||
isEditable: boolean | ||
}) => { | ||
setCurrentCommit(commitUuid) | ||
setIsCommitEditable(isEditable) | ||
|
||
if (commitUuid) { | ||
localStorage.setItem('commit', commitUuid) | ||
} else { | ||
localStorage.removeItem('commit') | ||
} | ||
} | ||
|
||
return ( | ||
<CommitContext.Provider | ||
value={{ | ||
currentCommit, | ||
isCommitEditable, | ||
setCurrentCommit: updateCurrentCommit, | ||
}} | ||
> | ||
{children} | ||
</CommitContext.Provider> | ||
) | ||
} | ||
|
||
export const useCurrentCommit = () => { | ||
const { currentCommit, isCommitEditable, setCurrentCommit } = | ||
useContext(CommitContext) | ||
return { currentCommit, isCommitEditable, setCurrentCommit } | ||
} |
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
10 changes: 1 addition & 9 deletions
10
packages/core/src/services/documentVersions/materializeAtCommit.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