-
Notifications
You must be signed in to change notification settings - Fork 46
[WEB-4086] Port Next projects to Vite 4 #2491
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1 @@ | ||
| VITE_PUBLIC_ABLY_KEY= | ||
| NEXT_PUBLIC_ABLY_KEY= | ||
| VITE_ABLY_KEY= |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,7 @@ | ||
| import baseConfig from '../../vite.config'; | ||
| import { defineConfig } from 'vite'; | ||
| import dotenv from 'dotenv'; | ||
| import path from 'path'; | ||
|
|
||
| dotenv.config({ path: path.resolve(__dirname, '../../.env.local') }); | ||
| import baseConfig from '../../vite.config'; | ||
|
|
||
| export default defineConfig({ | ||
| ...baseConfig, | ||
| envDir: '../../', | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <title>Ably Example</title> | ||
| </head> | ||
| <body> | ||
| <div id="root"></div> | ||
| <script type="module" src="/src/index.tsx"></script> | ||
| </body> | ||
| </html> |
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| import React, { useState, useEffect } from 'react'; | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wouldn't look too closely at the |
||
| import * as Ably from 'ably'; | ||
| import { AblyProvider, useConnectionStateListener } from 'ably/react'; | ||
| import './styles/styles.css'; | ||
|
|
||
| interface StatusMessage { | ||
| id: number; | ||
| success: boolean; | ||
| message: string; | ||
| } | ||
|
|
||
| interface StatusMessagesProps { | ||
| messages: StatusMessage[]; | ||
| setMessages: React.Dispatch<React.SetStateAction<StatusMessage[]>>; | ||
| } | ||
|
|
||
| const StatusMessages = ({ messages, setMessages }: StatusMessagesProps) => { | ||
| useConnectionStateListener((stateChange) => { | ||
| if (stateChange.current === 'connected') { | ||
| setMessages((prevMessages) => prevMessages.map((msg) => (msg.id === 3 ? { ...msg, success: true } : msg))); | ||
| } | ||
| }); | ||
|
|
||
| return ( | ||
| <div className="flex items-center justify-center min-h-screen bg-gray-100"> | ||
| <div className="bg-white shadow-md rounded-md p-8 w-[50%] flex flex-col"> | ||
| <div className="flex-grow text-center"> | ||
| <h1 className="text-2xl font-bold mb-4">Authentication to Ably with a JWT</h1> | ||
| <p className="mb-8">The Ably client has been successfully initialized.</p> | ||
| </div> | ||
|
|
||
| <div className="mt-4 text-left text-sm h-40 overflow-y-auto"> | ||
| {messages.map((msg) => ( | ||
| <div key={msg.id} className="flex items-center gap-2"> | ||
| <span> | ||
| {msg.success ? <span className="text-green-500">✓</span> : <span className="text-red-500">✗</span>} | ||
| </span> | ||
| {msg.message} | ||
| </div> | ||
| ))} | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default function App() { | ||
| const [client, setClient] = useState<Ably.Realtime | null>(null); | ||
| const [messages, setMessages] = useState<StatusMessage[]>([ | ||
| { id: 1, success: false, message: 'Client requests JWT from server' }, | ||
| { id: 2, success: false, message: 'Client initializes connection to Ably with generated JWT' }, | ||
| { id: 3, success: false, message: 'Client is connected' }, | ||
| ]); | ||
|
|
||
| const handleConnect = async () => { | ||
| // Navigate to authenticated page | ||
| window.location.href = '/authenticated'; | ||
| }; | ||
|
|
||
| return ( | ||
| <div className="flex items-center justify-center min-h-screen bg-gray-100"> | ||
| <div className="bg-white shadow-md rounded-md p-8 w-[50%] flex flex-col"> | ||
| <div className="flex-grow text-center"> | ||
| <h1 className="text-2xl font-bold mb-4">Authentication to Ably with a JWT</h1> | ||
| <p>Press the Connect button to initialize the client:</p> | ||
| <button onClick={handleConnect} className="uk-btn uk-btn-md uk-btn-primary mb-4 rounded"> | ||
| Connect | ||
| </button> | ||
| </div> | ||
|
|
||
| <div className="mt-4 text-left text-sm h-40 overflow-y-auto"> | ||
| {messages.map((msg, index) => ( | ||
| <div key={msg.id} className="flex items-center gap-2"> | ||
| <span> | ||
| {msg.success ? <span className="text-green-500">✓</span> : <span className="text-red-500">✗</span>} | ||
| </span> | ||
| {msg.message} | ||
| </div> | ||
| ))} | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| /// <reference types="vite/client" /> | ||
|
|
||
| interface ImportMetaEnv { | ||
| readonly VITE_ABLY_KEY: string; | ||
| } | ||
|
|
||
| interface ImportMeta { | ||
| readonly env: ImportMetaEnv; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import React from 'react'; | ||
| import ReactDOM from 'react-dom/client'; | ||
| import App from './App'; | ||
|
|
||
| ReactDOM.createRoot(document.getElementById('root')!).render( | ||
| <React.StrictMode> | ||
| <App /> | ||
| </React.StrictMode>, | ||
| ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a more vite-y approach than dotenv