-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: ✏️ adding useStorage and useSession docs
- Loading branch information
Showing
10 changed files
with
311 additions
and
83 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
"use client"; | ||
|
||
import * as React from "react"; | ||
import { OnlineUserInfo } from "@mirohq/websdk-types"; | ||
import { useSession } from "../../../esm"; | ||
|
||
export const UseSession: React.FC = () => { | ||
const { status, session, start, usersInSession, usersNotInSession } = useSession(); | ||
|
||
const handleStartSession = async () => { | ||
await start({ | ||
name: "Test session", | ||
}); | ||
}; | ||
|
||
const handleInviteUser = async (user: OnlineUserInfo) => { | ||
await session?.invite(user); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<h4>Session {status}</h4> | ||
{session ? ( | ||
<div> | ||
<p> | ||
#{session.id} - {session.name} | ||
</p> | ||
<ul> | ||
<li> | ||
<strong>Users in session</strong> | ||
</li> | ||
{usersInSession.map((user) => ( | ||
<li key={user.id}> | ||
#{user.id} - {user.name} | ||
</li> | ||
))} | ||
</ul> | ||
<ul> | ||
<li> | ||
<strong>Users not in session</strong> | ||
</li> | ||
{usersNotInSession.map((user) => ( | ||
<li key={user.id}> | ||
#{user.id} - {user.name} | ||
<button onClick={() => handleInviteUser(user)}>Invite</button> | ||
</li> | ||
))} | ||
</ul> | ||
</div> | ||
) : ( | ||
<button onClick={handleStartSession}>Start session</button> | ||
)} | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
"use client"; | ||
|
||
import * as React from "react"; | ||
import { useStorage } from "../../../esm"; | ||
|
||
export const UseStorage: React.FC = () => { | ||
const { status, result, error, set, remove } = useStorage("react-hooks", "example"); | ||
|
||
if (status === "loading") { | ||
return <p>Fetching values...</p>; | ||
} | ||
|
||
if (error) { | ||
return <p>Something went wrong</p>; | ||
} | ||
|
||
const handleSetValue = async () => { | ||
await set("Just changed from the app"); | ||
}; | ||
|
||
const handleRemoveValue = async () => { | ||
await remove(); | ||
}; | ||
|
||
if (status === "success") { | ||
return ( | ||
<div> | ||
<p>Current value:</p> | ||
<pre>{JSON.stringify(result, null, 2)}</pre> | ||
<button onClick={handleSetValue}>Set value</button> | ||
<button disabled={!result} onClick={handleRemoveValue}> | ||
Remove value | ||
</button> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
"use client"; | ||
|
||
import * as React from "react"; | ||
|
||
import { UseCurrentUser } from "./pages/UserCurrentUser"; | ||
import { Index } from "./pages/Index"; | ||
import { Miro } from "./pages/UseMiro"; | ||
import { UseInfo } from "./pages/UseInfo"; | ||
import { UseOnlineUsers } from "./pages/UseOnlineUsers"; | ||
import { UseSelectedItems } from "./pages/UseSelectedItems"; | ||
import { UseViewport } from "./pages/UseViewport"; | ||
import { UseStorage } from "./pages/UseStorage"; | ||
import { UseSession } from "./pages/UseSession"; | ||
|
||
export const routes = [ | ||
{ | ||
path: "/app.html", | ||
element: <Index />, | ||
}, | ||
{ | ||
path: "/miro", | ||
element: <Miro />, | ||
}, | ||
{ | ||
path: "/use-current-user", | ||
element: <UseCurrentUser />, | ||
}, | ||
{ | ||
path: "/use-info", | ||
element: <UseInfo />, | ||
}, | ||
{ | ||
path: "/use-online-users", | ||
element: <UseOnlineUsers />, | ||
}, | ||
{ | ||
path: "/use-selected-items", | ||
element: <UseSelectedItems />, | ||
}, | ||
{ | ||
path: "/use-viewport", | ||
element: <UseViewport />, | ||
}, | ||
{ | ||
path: "/use-storage", | ||
element: <UseStorage />, | ||
}, | ||
{ | ||
path: "/use-session", | ||
element: <UseSession />, | ||
}, | ||
]; |
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,3 +1,76 @@ | ||
# useSession | ||
|
||
Interact with [Miro collaborative sessions](https://developers.miro.com/docs/websdk-reference-session). | ||
Interact with [Miro collaborative sessions](https://developers.miro.com/docs/websdk-reference-session). | ||
|
||
**Note**: Make sure you are running this code in a configured [Miro WebSDK app](https://developers.miro.com/docs/build-your-first-hello-world-app). | ||
|
||
## Example | ||
|
||
|
||
```tsx | ||
import * as React from "react"; | ||
import { createRoot } from "react-dom/client"; | ||
import { useSession } from "@mirohq/websdk-react-hooks"; | ||
|
||
export const UseSession: React.FC = () => { | ||
const { status, session, start, usersInSession, usersNotInSession } = useSession(); | ||
|
||
const handleStartSession = async () => { | ||
await start({ | ||
name: "Test session", | ||
}); | ||
}; | ||
|
||
const handleInviteUser = async (user: OnlineUserInfo) => { | ||
await session?.invite(user); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<h4>Session {status}</h4> | ||
{session ? ( | ||
<div> | ||
<p> | ||
#{session.id} - {session.name} | ||
</p> | ||
<ul> | ||
<li> | ||
<strong>Users in session</strong> | ||
</li> | ||
{usersInSession.map((user) => ( | ||
<li key={user.id}> | ||
#{user.id} - {user.name} | ||
</li> | ||
))} | ||
</ul> | ||
<ul> | ||
<li> | ||
<strong>Users not in session</strong> | ||
</li> | ||
{usersNotInSession.map((user) => ( | ||
<li key={user.id}> | ||
#{user.id} - {user.name} | ||
<button onClick={() => handleInviteUser(user)}>Invite</button> | ||
</li> | ||
))} | ||
</ul> | ||
</div> | ||
) : ( | ||
<button onClick={handleStartSession}>Start session</button> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
const App = () => { | ||
return ( | ||
<MiroProvider> | ||
<UseSelectedItems /> | ||
</MiroProvider> | ||
) | ||
}; | ||
|
||
const container = document.getElementById("root")!; | ||
const root = createRoot(container); | ||
root.render(<App />); | ||
``` |
Oops, something went wrong.