EmptyRealtime.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import Link from 'next/link'
  2. import { AiIconAnimation, Button, Card, cn } from 'ui'
  3. import { AnimatedCursors } from './AnimatedCursors'
  4. import { SIDEBAR_KEYS } from '@/components/layouts/ProjectLayout/LayoutSidebar/LayoutSidebarProvider'
  5. import { DocsButton } from '@/components/ui/DocsButton'
  6. import { DOCS_URL } from '@/lib/constants'
  7. import { useAiAssistantStateSnapshot } from '@/state/ai-assistant-state'
  8. import { useSidebarManagerSnapshot } from '@/state/sidebar-manager-state'
  9. /**
  10. * Acts as a container component for the entire log display
  11. */
  12. export const EmptyRealtime = ({ projectRef }: { projectRef: string }) => {
  13. const aiSnap = useAiAssistantStateSnapshot()
  14. const { openSidebar } = useSidebarManagerSnapshot()
  15. const handleCreateTriggerWithAssistant = () => {
  16. openSidebar(SIDEBAR_KEYS.AI_ASSISTANT)
  17. aiSnap.newChat({
  18. name: `Realtime`,
  19. initialInput: `Help me set up a realtime experience for my project`,
  20. })
  21. }
  22. return (
  23. <div className="flex grow items-center justify-center p-12 @container">
  24. <div className="w-full max-w-4xl flex flex-col items-center gap-0">
  25. <div className="text-center mb-12">
  26. <AnimatedCursors />
  27. <h2 className="heading-section mb-1">Create realtime experiences</h2>
  28. <p className="text-foreground-light mb-6">
  29. Send your first realtime message from your database, application code or edge function
  30. </p>
  31. <Button
  32. type="default"
  33. icon={<AiIconAnimation />}
  34. onClick={handleCreateTriggerWithAssistant}
  35. >
  36. Set up realtime for me
  37. </Button>
  38. </div>
  39. <Card className="grid grid-cols-1 @xl:grid-cols-3 bg divide-x mb-8">
  40. <div className="flex flex-col h-full p-6">
  41. <div className="flex items-center gap-3 mb-2">
  42. <span
  43. className={cn(
  44. 'text-xs shrink-0 font-mono text-foreground-light w-7 h-7 bg border flex items-center justify-center rounded-md'
  45. )}
  46. >
  47. 1
  48. </span>
  49. <h3 className="heading-default">Broadcast messages</h3>
  50. </div>
  51. <p className="text-foreground-light text-sm mb-4 flex-1">
  52. Send messages to a channel from your client application or database via triggers.
  53. </p>
  54. <Button type="default" className="w-full">
  55. <Link href={`/project/${projectRef}/database/triggers`}>Create a trigger</Link>
  56. </Button>
  57. </div>
  58. <div className="flex flex-col h-full p-6">
  59. <div className="flex items-center gap-3 mb-2">
  60. <span
  61. className={cn(
  62. 'text-xs shrink-0 font-mono text-foreground-light w-7 h-7 bg border flex items-center justify-center rounded-md'
  63. )}
  64. >
  65. 2
  66. </span>
  67. <h3 className="heading-default">Write policies</h3>
  68. </div>
  69. <p className="text-foreground-light text-sm mb-4 flex-1">
  70. Set up Row Level Security policies to control who can see messages within a channel
  71. </p>
  72. <Button type="default">
  73. <Link href={`/project/${projectRef}/realtime/policies`}>Write a policy</Link>
  74. </Button>
  75. </div>
  76. <div className="flex flex-col h-full p-6">
  77. <div className="flex items-center gap-3 mb-2">
  78. <span
  79. className={cn(
  80. 'text-xs shrink-0 font-mono text-foreground-light w-7 h-7 bg border flex items-center justify-center rounded-md'
  81. )}
  82. >
  83. 3
  84. </span>
  85. <h3 className="heading-default">Subscribe to a channel</h3>
  86. </div>
  87. <p className="text-foreground-light text-sm mb-4 flex-1">
  88. Receive realtime messages in your application by listening to a channel
  89. </p>
  90. <DocsButton
  91. abbrev={false}
  92. href={`${DOCS_URL}/guides/realtime/subscribing-to-database-changes#listening-on-client-side`}
  93. />
  94. </div>
  95. </Card>
  96. </div>
  97. </div>
  98. )
  99. }