Skip to content
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

Dev love98 #13

Merged
merged 2 commits into from
Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"react-dom": "^18.2.0",
"react-router": "^5.3.4",
"react-router-dom": "^5.3.4",
"swiper": "^10.3.1"
"swiper": "^10.3.1",
"zustand": "^4.4.6"
},
"devDependencies": {
"@capacitor/cli": "5.5.0",
Expand Down
11 changes: 8 additions & 3 deletions src/apis/user.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import request from '.';
import { Department, Event } from '../context';
import { Department, Event, UserInfo } from '../context';

export const getAllConductingEvent = async () => {
const response = await request.get<Event[]>('/event/conducting');
Expand Down Expand Up @@ -75,7 +75,12 @@ export const getHistoryEvents = async () => {
return response.data;
}

export const getUserInfo =async () => {
const response = await request.get<any>('/user/info');
export const getUserInfo = async () => {
const response = await request.get<UserInfo>('/user/info');
return response.data;
}

export const updateUserInfo = async (userInfo: UserInfo) => {
const response = await request.put<any>('/user/info', userInfo);
return response.data;
}
20 changes: 17 additions & 3 deletions src/components/EventCard.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
justify-content: flex-end;
margin-top: 5px;
padding-bottom: 3px;
animation: zoomFade 0.7s ease-in-out forwards;

ion-card-header {
padding-bottom: 10px;

padding: 12px 20px 15px 20px;
.oneLineTextOverflow {
white-space: nowrap;
overflow: hidden;
Expand Down Expand Up @@ -102,4 +102,18 @@
margin-left: 5px;
margin-bottom: 2px;
}
}
}

@keyframes zoomFade {
0% {
transform: scale(0.7) translateY(50%);
opacity: 0;
}
50% {
opacity: 0.37;
}
100% {
transform: scale(1) translateY(0);
opacity: 1;
}
}
5 changes: 1 addition & 4 deletions src/components/EventCardList.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,18 @@
align-items: flex-start;
justify-content: flex-start;
column-gap: 0px;

@media screen and (min-width: 1601px) {
column-width: 25%;
column-count: 4;
}
@media screen and (min-width: 1051px) and (max-width: 1600px) {
column-width: 33%;
column-count: 3;
}
@media screen and (min-width: 500px) and (max-width: 1050px) {
column-width: 50%;
column-count: 2;
}

@media screen and (min-width: 300px) and (max-width: 499px) {
column-width: 100%;
column-count: 1;
}
}
Expand Down
Empty file added src/components/Profile.scss
Empty file.
69 changes: 69 additions & 0 deletions src/components/Profile.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { IonButton, IonButtons, IonCard, IonContent, IonHeader, IonInput, IonItem, IonList, IonModal, IonTextarea, IonTitle, IonToolbar } from '@ionic/react';
import './Profile.scss'
import { useRef } from 'react';
import { useUserInfoStore } from '../util/store';
import { updateUserInfo } from '../apis/user';
import { UserInfo } from '../context';

interface Props {
trigger: string;
}

const Profile: React.FC<Props> = ({ trigger }) => {
const modal = useRef<HTMLIonModalElement>(null);
const userInfoStore = useUserInfoStore((state) => state);
const userInfo = userInfoStore.userInfo;
const saveChanges = () => {
updateUserInfo(userInfo as UserInfo).then((res) => {
userInfoStore.updateUserInfo(userInfo);
});
modal.current?.dismiss();
}


return (
<>
<IonModal trigger={trigger} ref={modal}>
<IonHeader>
<IonToolbar>
<IonTitle>Modal</IonTitle>
<IonButtons slot="start">
<IonButton onClick={() => modal.current?.dismiss()}>Close</IonButton>
</IonButtons>

<IonButtons slot="end">
<IonButton onClick={saveChanges}>Save</IonButton>
</IonButtons>
</IonToolbar>
</IonHeader>
<IonContent className="ion-padding">
<IonList inset={true}>
<IonItem>
<IonInput
label='昵称'
value={userInfo?.nickname}
onIonChange={(e) => { userInfo.nickname = e.detail.value! }}

Check failure on line 45 in src/components/Profile.tsx

View workflow job for this annotation

GitHub Actions / build

'userInfo' is possibly 'undefined'.
></IonInput>
</IonItem>
<IonItem>
<IonInput disabled label='组织' value={userInfo?.organization}></IonInput>
</IonItem>
</IonList>
<IonList inset={true}>
<IonItem>
<IonTextarea
slot="start"
placeholder='自我介绍'
autoGrow={true}
value={userInfo?.biography}
onIonChange={(e) => { userInfo.biography = e.detail.value! }}

Check failure on line 59 in src/components/Profile.tsx

View workflow job for this annotation

GitHub Actions / build

'userInfo' is possibly 'undefined'.
></IonTextarea>
</IonItem>
</IonList>
</IonContent>
</IonModal>
</>
)
}

export default Profile;
3 changes: 1 addition & 2 deletions src/components/SlideImages.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
margin-top: 15px;
width: 95vw;
border-radius: 4px;
height: 30vw;
height: 40vw;
max-height: 380px;
overflow: hidden;
position: relative;
Expand All @@ -18,7 +18,6 @@
justify-content: center;
align-items: center;
text-align: center;
height: 30vw;
max-height: 380px;
}
}
13 changes: 13 additions & 0 deletions src/context/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,16 @@ export interface EventType {
typeName: string;
[property: string]: any;
}

export interface UserInfo {
avatar: string;
biography: string;
email: string;
id: string;
link: Array<string[]>;
linkId: string;
nickname: string;
organization: string;
studentId: string;
[property: string]: any;
}
1 change: 0 additions & 1 deletion src/pages/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const Home: React.FC = () => {
window.location.reload();
}

// TODO: change layout styles to falls
return (
<IonPage>
<IonHeader translucent={false}>
Expand Down
40 changes: 23 additions & 17 deletions src/pages/Me.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,42 @@ import React, { useEffect, useState } from 'react';
import './Me.scss';
import OnDevAlert from '../components/OnDevAlert';
import { getUserInfo } from '../apis/user';
import Profile from '../components/Profile';
import { useUserInfoStore } from '../util/store';

const Me: React.FC = () => {
const { themeToggle, toggleChange } = React.useContext(ThemeContext);
const [userInfo, setUserInfo] = useState<any | null>(JSON.parse(String(localStorage.getItem('userInfo'))));
const userInfoStore = useUserInfoStore((state) => state);
const userInfo = userInfoStore.userInfo;
const router = useIonRouter();
const isLoggedIn = localStorage.getItem('token') !== null;;
const isLoggedIn = localStorage.getItem('token') !== null;

const themeIcon = themeToggle ? moon : sunnyOutline;

useEffect(() => {
console.log(isLoggedIn);
console.log(userInfo);
if (isLoggedIn && userInfo === null) {


if (isLoggedIn && userInfo === undefined) {
getUserInfo().then((res) => {
setUserInfo(res);
userInfoStore.updateUserInfo(res);
});
}
}, [])
}, [userInfo])

const logOut = () => {
localStorage.clear();
setUserInfo(null);
userInfoStore.rmUserInfo();
}

const toHistoryEvents = () => {
router.push("/history", 'forward');
}

const handleRefresh = () => {
window.location.reload();
}
window.location.reload();
}

return (
<IonPage>
Expand All @@ -60,14 +63,17 @@ const Me: React.FC = () => {
<div className='meWarpper'>
<IonCard className='userProfileWarpper'>
{isLoggedIn ? (
<IonItem lines="none">
<IonThumbnail slot="start">
<IonImg src={userInfo?.avatar !== null ? userInfo?.avatar : "/link.ico"} alt="avatar" className='userProfileAvatar' />
</IonThumbnail>
<h2 slot="start" className='userProfile__name'>{String(userInfo?.studentId).toUpperCase()}</h2>
</IonItem>
<>
<IonItem lines="none" id='userBasicInfo'>
<IonThumbnail slot="start">
<IonImg src={userInfo?.avatar !== null ? userInfo?.avatar : "/link.ico"} alt="avatar" className='userProfileAvatar' />
</IonThumbnail>
<h2 slot="start" className='userProfile__name'>{String(userInfo?.nickname)}</h2>
</IonItem>
<Profile trigger='userBasicInfo' ></Profile>
</>
) : (
<IonItem onClick={() => {router.push("/login", "forward")}} lines="none">
<IonItem onClick={() => { router.push("/login", "forward") }} lines="none">
<IonThumbnail slot="start">
<IonImg src="/link.ico" alt="avatar" className='userProfileAvatar' />
</IonThumbnail>
Expand Down
23 changes: 23 additions & 0 deletions src/util/store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { create } from "zustand"
import { devtools, persist } from 'zustand/middleware'
import { UserInfo } from "../context"

interface UserInfoStore {
userInfo?: UserInfo
rmUserInfo: () => void
updateUserInfo: (userInfo: UserInfo | undefined) => void
}

export const useUserInfoStore = create<UserInfoStore>()(
devtools(
persist(
(set) => ({
userInfo: undefined,
rmUserInfo: () => set({ userInfo: undefined }),
updateUserInfo: (userInfo) => set({ userInfo }),
}),
{
name: 'userInfo-store'
})
),
)
Loading