This repository has been archived by the owner on Sep 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added add file component UI * Fix prettier and linter --------- Co-authored-by: Kamil Stasiak <kamilstasiaknew@gmail.com>
- Loading branch information
1 parent
701c092
commit 3ec2261
Showing
2 changed files
with
65 additions
and
0 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,59 @@ | ||
import React, { FC } from "react"; | ||
import { useServerSdk } from "./ServerSdkContext"; | ||
import { useAtom } from "jotai"; | ||
import { atomWithStorage } from "jotai/utils"; | ||
|
||
type Props = { | ||
roomId: string; | ||
refetchIfNeeded: () => void; | ||
hasFileComponent: boolean; | ||
}; | ||
|
||
const urlAtom = atomWithStorage("file-path", ""); | ||
|
||
const AddFileComponent: FC<Props> = ({ roomId, refetchIfNeeded, hasFileComponent }) => { | ||
const { roomApi } = useServerSdk(); | ||
const [filePath, setFilePath] = useAtom(urlAtom); | ||
|
||
return ( | ||
<div className="w-full card bg-base-100 shadow-xl indicator"> | ||
<div className="card-body p-4"> | ||
<div className="flex flex-row justify-between"> | ||
<div className="flex flex-col gap-2"> | ||
<input | ||
value={filePath} | ||
onChange={(e) => setFilePath(e.target.value.trim())} | ||
className="input input-bordered w-full" | ||
placeholder="File Path" | ||
/> | ||
</div> | ||
<div | ||
className={!hasFileComponent ? "" : "tooltip tooltip-info z-10"} | ||
data-tip={hasFileComponent ? "File component already exists in this room" : ""} | ||
> | ||
<button | ||
disabled={hasFileComponent} | ||
onClick={() => { | ||
roomApi | ||
?.addComponent(roomId, { | ||
type: "file", | ||
options: { | ||
filePath: filePath, | ||
}, | ||
}) | ||
.then(() => { | ||
refetchIfNeeded(); | ||
}); | ||
}} | ||
className="btn btn-success" | ||
> | ||
Add File | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default AddFileComponent; |
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