Skip to content

Commit

Permalink
Merge pull request #39 from punky-lab/yhy-ui
Browse files Browse the repository at this point in the history
Yhy UI
  • Loading branch information
FrozenArcher authored Nov 9, 2024
2 parents 19b1a49 + 294f39f commit 00b3a32
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 27 deletions.
22 changes: 11 additions & 11 deletions components/MainUI/Dog/Dog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,16 @@ import LoadingDots from "../loadingDots";
export default function Dog({ onClick, loading }: { onClick?: () => void, loading: boolean }) {
const [isTalking, setIsTalking] = useState(false);
const [currentFrames, setCurrentFrames] = useState<any[]>(punkyFrames); // Default frames
const [isSitting, setIsSitting] = useState(false);

const handleSwipe = () => {
const animations = [punkySitFrames, punkyRollFrames, punkyRunFrames];
const randomAnimationIndex = Math.floor(Math.random() * animations.length);
const randomAnimation = animations[randomAnimationIndex];

setCurrentFrames([randomAnimation]);

setTimeout(() => {
setCurrentFrames(punkyFrames); // 恢复到默认帧动画
}, 3000); // 2 秒后恢复
if (isSitting) {
setCurrentFrames(punkyFrames);
setIsSitting(false);
} else {
setCurrentFrames([punkySitFrames]);
setIsSitting(true);
}
};

let touchStartX: number | null = null;
Expand All @@ -38,10 +37,11 @@ export default function Dog({ onClick, loading }: { onClick?: () => void, loadin
handleSwipe(); // 触发随机动画
}
};

return (
<div className="grow flex flex-col items-center" onClick={onClick}>
<div
className="fixed top-[29%]"
className="fixed top-[240px]"
onTouchStart={(e: React.TouchEvent<HTMLDivElement>) =>
handleTouchStart(e)
}
Expand All @@ -50,7 +50,7 @@ export default function Dog({ onClick, loading }: { onClick?: () => void, loadin
{loading && <LoadingDots />}
<FrameAnimation
frames={currentFrames}
interval={300}
interval={800}
width={180}
height={180}
isThinking={isTalking}
Expand Down
22 changes: 11 additions & 11 deletions components/MainUI/Main2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,17 @@ export default function Init({
};

const autoLogin = async () => {
try {
const response = await authApis.login({
username: "[email protected]",
password: "password"
});
const { access_token, refresh_token } = response.data.data;
localStorage.setItem('token', access_token);
localStorage.setItem('refresh_token', refresh_token);
} catch (error) {
console.error('自动登录失败:', error);
}
// try {
// const response = await authApis.login({
// username: "[email protected]",
// password: "password"
// });
// const { access_token, refresh_token } = response.data.data;
// localStorage.setItem('token', access_token);
// localStorage.setItem('refresh_token', refresh_token);
// } catch (error) {
// console.error('自动登录失败:', error);
// }
};

const fetchUserData = async () => {
Expand Down
34 changes: 29 additions & 5 deletions components/Root/Root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
bindMiniAppCSSVars,
bindThemeParamsCSSVars,
bindViewportCSSVars,
retrieveLaunchParams,
} from "@telegram-apps/sdk-react";
import { AppRoot } from "@telegram-apps/telegram-ui";

Expand All @@ -20,12 +21,14 @@ import { useDidMount } from "@/hooks/useDidMount";
import LoadingAnimation from "../loadingAnimation";
import { DynamicContextProvider } from "@dynamic-labs/sdk-react-core";
import { SolanaWalletConnectors } from "@dynamic-labs/solana";
import axios from "axios";

function App(props: PropsWithChildren) {
const lp = useLaunchParams();
const miniApp = useMiniApp();
const themeParams = useThemeParams();
const viewport = useViewport();
const { initDataRaw } = retrieveLaunchParams();

useEffect(() => {
return bindMiniAppCSSVars(miniApp, themeParams);
Expand All @@ -39,22 +42,43 @@ function App(props: PropsWithChildren) {
return viewport && bindViewportCSSVars(viewport);
}, [viewport]);

useEffect(() => {
console.log(initDataRaw);
if (!initDataRaw) {
console.error("initDataRaw is empty");
return;
}
axios
.post(`/api/v1/telegram/login?init_data=${initDataRaw}`)
.then((res) => {
console.log("telegram login", res);
if (!res.data.success) {
throw new Error(`telegram login failed: ${res.data.message}`);
}
const data = res.data.data;
localStorage.setItem("access_token", data.access_token);
localStorage.setItem("refresh_token", data.refresh_token);
})
.catch((err) => {
console.error("telegram login error", err);
});
}, [initDataRaw]);

return (
<AppRoot
appearance={miniApp.isDark ? 'dark' : 'light'}
platform={['macos', 'ios'].includes(lp.platform) ? 'ios' : 'base'}
appearance={miniApp.isDark ? "dark" : "light"}
platform={["macos", "ios"].includes(lp.platform) ? "ios" : "base"}
>
<DynamicContextProvider
settings={{
environmentId: 'db69ee58-41e4-43e7-be42-a601a83085ea',
environmentId: "db69ee58-41e4-43e7-be42-a601a83085ea",
walletConnectors: [SolanaWalletConnectors],
}}
theme={'dark'}
theme={"dark"}
>
{props.children}
</DynamicContextProvider>
</AppRoot>

);
}

Expand Down

0 comments on commit 00b3a32

Please sign in to comment.