-
Notifications
You must be signed in to change notification settings - Fork 47
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
Refactored Code: Removed redundant window.androidIntract, added GetBotList and SocketComponents, implemented expired bot logic #126
Merged
geeky-abhishek
merged 5 commits into
samagra-comms:c4gt-development
from
Rishit30G:master
Jul 19, 2023
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5128e13
to be edited
Rishit30G 78b3e37
Update .env.sample
Rishit30G 9342ad7
Update set-local-storage.ts
Rishit30G 1261cc8
fix: enhancement done for #126
Rishit30G 826409e
Merge branch 'master' of https://github.com/Rishit30G/uci-web-channel
Rishit30G File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,84 @@ | ||
import { getBotDetailsList } from "@/utils/api-handler"; | ||
import { normalizeUsers } from "@/utils/normalize-user"; | ||
import { reverse, sortBy, without } from "lodash"; | ||
import moment from "moment"; | ||
import { useEffect } from "react"; | ||
import { toast } from "react-hot-toast"; | ||
import { setUsers, setCurrentUser, setLoading } from "@/types/react-dispatch"; | ||
|
||
interface GetBotItemProp{ | ||
setUsers: setUsers, | ||
setCurrentUser: setCurrentUser, | ||
setLoading: setLoading | ||
} | ||
|
||
|
||
const GetBotList: React.FC<GetBotItemProp> = ({ setUsers, setCurrentUser, setLoading }) => { | ||
|
||
useEffect(() => { | ||
try { | ||
const checkOnline = async (): Promise<void> => { | ||
if (window.navigator.onLine) { | ||
|
||
const botIds = JSON.parse(localStorage.getItem("botList") || '{}'); | ||
getBotDetailsList() | ||
.then((response): any => { | ||
console.log({ response }) | ||
const botDetailsList = without( | ||
reverse( | ||
sortBy( | ||
response?.data?.result?.map((bot: any, index: number) => { | ||
if ( | ||
// bot?.logicIDs?.[0]?.transformers?.[0]?.meta?.type !== | ||
// "broadcast" && | ||
// includes(botIds, bot?.id) | ||
true | ||
) { | ||
if (index === 0) localStorage.setItem('userID', bot?.id); | ||
return normalizeUsers({ | ||
...bot, | ||
active: index === 0, | ||
botUuid: bot?.id, | ||
createTime: moment(bot?.createdAt).valueOf(), | ||
}); | ||
} | ||
return null; | ||
}), | ||
["createTime"] | ||
) | ||
), | ||
null | ||
); | ||
|
||
|
||
// @ts-ignore | ||
setUsers(botDetailsList); | ||
setLoading(false); | ||
|
||
if (localStorage.getItem("currentUser")) { | ||
|
||
// @ts-ignore | ||
setCurrentUser(JSON.parse(localStorage.getItem("currentUser"))); | ||
|
||
// @ts-ignore | ||
} else setCurrentUser(botDetailsList?.[0]); | ||
}) | ||
.catch((err: any) => console.log("qwerty:", { err })); | ||
} else { | ||
setLoading(false); | ||
if (localStorage.getItem("botDetails")) { | ||
setUsers(JSON.parse(localStorage.getItem("botDetails") || '[]')); | ||
setCurrentUser(JSON.parse(localStorage.getItem("botDetails") || '[]')?.[0]); | ||
} | ||
} | ||
}; | ||
checkOnline(); | ||
} catch (err: any) { | ||
toast.error(err?.message); | ||
} | ||
}, []); | ||
|
||
return null; | ||
} | ||
|
||
export default GetBotList; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
use useMemo for calculated variables