-
Notifications
You must be signed in to change notification settings - Fork 53
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
140 changed files
with
28,466 additions
and
8,371 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
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
60 changes: 60 additions & 0 deletions
60
packages/examples/sdk-frontend-react/src/app/ChatTest/GetChatMemberCountTest.tsx
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,60 @@ | ||
import { useState, useContext } from 'react'; | ||
import { Section, SectionItem, CodeFormatter, SectionButton } from '../components/StyledComponents'; | ||
import Loader from '../components/Loader'; | ||
import { EnvContext } from '../context'; | ||
import * as PushAPI from '@pushprotocol/restapi'; | ||
|
||
const GetChatMemberCountTest = () => { | ||
const { env } = useContext<any>(EnvContext); | ||
const [isLoading, setLoading] = useState(false); | ||
const [chatId, setChatId] = useState<string>(''); | ||
const [totalMembersCount, setTotalMembersCount] = useState<PushAPI.ChatMemberCounts | null>(null); | ||
|
||
const updateChatId = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
setChatId(e.target.value); | ||
}; | ||
|
||
const fetchMemberCount = async () => { | ||
try { | ||
setLoading(true); | ||
const counts = await PushAPI.chat.getChatMemberCount({ chatId, env }); | ||
setTotalMembersCount(counts); | ||
} catch (error) { | ||
console.error('Failed to fetch chat member count:', error); | ||
} finally { | ||
setLoading(false); | ||
} | ||
}; | ||
|
||
return ( | ||
<div> | ||
<h2>Get Chat Member Count Test Page</h2> | ||
<Loader show={isLoading} /> | ||
<Section> | ||
<SectionItem> | ||
<label>Chat ID:</label> | ||
<input | ||
type="text" | ||
onChange={updateChatId} | ||
value={chatId} | ||
style={{ width: 400, height: 30 }} | ||
/> | ||
</SectionItem> | ||
<SectionItem> | ||
<SectionButton onClick={fetchMemberCount}>Fetch Member Count</SectionButton> | ||
</SectionItem> | ||
{totalMembersCount && ( | ||
<SectionItem> | ||
<div> | ||
<CodeFormatter> | ||
{JSON.stringify(totalMembersCount, null, 2)} | ||
</CodeFormatter> | ||
</div> | ||
</SectionItem> | ||
)} | ||
</Section> | ||
</div> | ||
); | ||
}; | ||
|
||
export default GetChatMemberCountTest; |
63 changes: 63 additions & 0 deletions
63
packages/examples/sdk-frontend-react/src/app/ChatTest/GetGroupInfoTest.tsx
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,63 @@ | ||
import React, { useState, useContext } from 'react'; | ||
import { EnvContext } from '../context'; | ||
import * as PushAPI from '@pushprotocol/restapi'; | ||
import Loader from '../components/Loader'; | ||
import { Section, SectionItem, CodeFormatter, SectionButton } from '../components/StyledComponents'; | ||
|
||
const GetGroupInfoTest = () => { | ||
const { env } = useContext<any>(EnvContext); | ||
const [chatId, setChatId] = useState(''); | ||
const [sendResponse, setSendResponse] = useState<any>(''); | ||
const [isLoading, setLoading] = useState(false); | ||
|
||
const updateChatId = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
setChatId(e.target.value); | ||
}; | ||
|
||
const fetchGroupInfo = async () => { | ||
setLoading(true); | ||
try { | ||
const groupInfo = await PushAPI.chat.getGroupInfo({ chatId, env }); | ||
setSendResponse(groupInfo); | ||
} catch (error) { | ||
console.error('Error fetching group info:', error); | ||
} finally { | ||
setLoading(false); | ||
} | ||
}; | ||
|
||
return ( | ||
<div> | ||
<h2>Get Group Info Test</h2> | ||
<Loader show={isLoading} /> | ||
<Section> | ||
<SectionItem> | ||
<label htmlFor="chatId">Chat ID:</label> | ||
<input | ||
id="chatId" | ||
type="text" | ||
onChange={updateChatId} | ||
value={chatId} | ||
placeholder="Enter chat ID" | ||
style={{ width: '100%', height: 30 }} | ||
/> | ||
</SectionItem> | ||
<SectionItem> | ||
<SectionButton onClick={fetchGroupInfo}> | ||
Fetch Group Info | ||
</SectionButton> | ||
</SectionItem> | ||
{sendResponse && ( | ||
<SectionItem> | ||
<h3>Group Information:</h3> | ||
<CodeFormatter> | ||
{JSON.stringify(sendResponse, null, 2)} | ||
</CodeFormatter> | ||
</SectionItem> | ||
)} | ||
</Section> | ||
</div> | ||
); | ||
}; | ||
|
||
export default GetGroupInfoTest; |
98 changes: 98 additions & 0 deletions
98
packages/examples/sdk-frontend-react/src/app/ChatTest/GetGroupMembersTest.tsx
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,98 @@ | ||
import { useState, useContext, useEffect } from 'react'; | ||
import { Section, SectionItem, CodeFormatter, SectionButton } from '../components/StyledComponents'; | ||
import Loader from '../components/Loader'; | ||
import { EnvContext } from '../context'; | ||
import * as PushAPI from '@pushprotocol/restapi'; | ||
|
||
const GetGroupMembersTest = () => { | ||
const { env } = useContext<any>(EnvContext); | ||
const [isLoading, setLoading] = useState(false); | ||
const [chatId, setChatId] = useState<string>(''); | ||
const [pageNumber, setPageNumber] = useState<number>(1); | ||
const [pageSize, setPageSize] = useState<number>(20); | ||
const [sendResponse, setSendResponse] = useState<any>(''); | ||
|
||
|
||
const updateChatId = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
setChatId(e.target.value); | ||
}; | ||
|
||
const updatePageNumber = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
setPageNumber(parseInt(e.target.value)); | ||
}; | ||
|
||
const updatePageSize = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
setPageSize(parseInt(e.target.value)); | ||
}; | ||
|
||
const fetchGroupMembers = async () => { | ||
setLoading(true); | ||
try { | ||
const result = await PushAPI.chat.getGroupMembers({ | ||
chatId, | ||
page: pageNumber, | ||
limit: pageSize, | ||
env, | ||
}); | ||
setSendResponse(result); | ||
} catch (error) { | ||
console.error('Failed to fetch group members:', error); | ||
} finally { | ||
setLoading(false); | ||
} | ||
}; | ||
|
||
// Fetch members when component mounts | ||
useEffect(() => { | ||
fetchGroupMembers(); | ||
}, []); | ||
|
||
return ( | ||
<div> | ||
<h2>Get Group Members Test Page</h2> | ||
<Loader show={isLoading} /> | ||
<Section> | ||
<SectionItem> | ||
<label>Chat ID:</label> | ||
<input | ||
type="text" | ||
onChange={updateChatId} | ||
value={chatId} | ||
placeholder="Enter chat ID" | ||
style={{ width: '100%', height: 30 }} | ||
/> | ||
</SectionItem> | ||
<SectionItem> | ||
<label>Page Number:</label> | ||
<input | ||
type="number" | ||
onChange={updatePageNumber} | ||
value={pageNumber} | ||
style={{ width: '100%', height: 30 }} | ||
/> | ||
</SectionItem> | ||
<SectionItem> | ||
<label>Page Size:</label> | ||
<input | ||
type="number" | ||
onChange={updatePageSize} | ||
value={pageSize} | ||
style={{ width: '100%', height: 30 }} | ||
/> | ||
</SectionItem> | ||
<SectionItem> | ||
<SectionButton onClick={fetchGroupMembers}>Fetch Group Members</SectionButton> | ||
</SectionItem> | ||
{sendResponse && ( | ||
<SectionItem> | ||
<CodeFormatter> | ||
{JSON.stringify(sendResponse, null, 2)} | ||
</CodeFormatter> | ||
</SectionItem> | ||
)} | ||
</Section> | ||
</div> | ||
); | ||
}; | ||
|
||
export default GetGroupMembersTest; |
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
Oops, something went wrong.