-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* embed discuss * update sidebar
- Loading branch information
Showing
6 changed files
with
201 additions
and
39 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
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,34 +1,61 @@ | ||
import { | ||
Button, | ||
Tabs, | ||
TabsList, | ||
TabsContent, | ||
TabsTrigger, | ||
} from "@renderer/components/ui"; | ||
import { UsersRankings, Posts } from "@renderer/components"; | ||
import { ChevronLeftIcon } from "lucide-react"; | ||
import { useNavigate } from "react-router-dom"; | ||
import { t } from "i18next"; | ||
import { useContext, useEffect, useRef } from "react"; | ||
import { AppSettingsProviderContext } from "@renderer/context"; | ||
import debounce from "lodash/debounce"; | ||
import { DISCUSS_URL, WEB_API_URL } from "@/constants"; | ||
|
||
export default () => { | ||
const navigate = useNavigate(); | ||
|
||
return ( | ||
<div className="min-h-full px-4 lg:px-8 py-6 max-w-screen-md mx-auto"> | ||
<Tabs defaultValue="square"> | ||
<TabsList className="mb-4"> | ||
<TabsTrigger value="square">{t("square")}</TabsTrigger> | ||
<TabsTrigger value="rankings">{t("rankings")}</TabsTrigger> | ||
</TabsList> | ||
|
||
<TabsContent value="square"> | ||
<Posts /> | ||
</TabsContent> | ||
|
||
<TabsContent value="rankings"> | ||
<UsersRankings /> | ||
</TabsContent> | ||
</Tabs> | ||
</div> | ||
); | ||
const containerRef = useRef<HTMLDivElement>(null); | ||
const { EnjoyApp, user, webApi } = useContext(AppSettingsProviderContext); | ||
|
||
const loadCommunity = async () => { | ||
let url = `${DISCUSS_URL}/login`; | ||
let ssoUrl = `${WEB_API_URL}/discourse/sso`; | ||
|
||
try { | ||
const { discussUrl, discussSsoUrl } = await webApi.config("discuss"); | ||
if (discussUrl) { | ||
url = discussUrl; | ||
} | ||
if (discussSsoUrl) { | ||
ssoUrl = discussSsoUrl; | ||
} | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
|
||
const { x, y, width, height } = | ||
containerRef.current.getBoundingClientRect(); | ||
EnjoyApp.view.loadCommunity( | ||
{ x, y, width, height }, | ||
{ navigatable: false, accessToken: user?.accessToken, url, ssoUrl } | ||
); | ||
}; | ||
|
||
const resize = debounce(() => { | ||
const { x, y, width, height } = | ||
containerRef.current.getBoundingClientRect(); | ||
EnjoyApp.view.resize({ x, y, width, height }); | ||
}, 100); | ||
|
||
useEffect(() => { | ||
if (!containerRef.current) return; | ||
|
||
loadCommunity(); | ||
const observer = new ResizeObserver(() => { | ||
resize(); | ||
}); | ||
observer.observe(containerRef.current); | ||
|
||
return () => { | ||
observer.disconnect(); | ||
}; | ||
}, []); | ||
|
||
useEffect(() => { | ||
return () => { | ||
EnjoyApp.view.remove(); | ||
}; | ||
}, []); | ||
|
||
return <div ref={containerRef} className="w-full h-full"></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