mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 18:44:16 +00:00
Add user model to app models, user layout updated for gathering data from model instead local functions
This commit is contained in:
parent
63dc7ea902
commit
ac6b2fb557
@ -45,6 +45,7 @@
|
|||||||
"concat-stream": "^2.0.0",
|
"concat-stream": "^2.0.0",
|
||||||
"cookie_js": "^1.4.0",
|
"cookie_js": "^1.4.0",
|
||||||
"dotenv": "^8.2.0",
|
"dotenv": "^8.2.0",
|
||||||
|
"dva-model-enhance": "^1.2.13",
|
||||||
"electron-config": "^2.0.0",
|
"electron-config": "^2.0.0",
|
||||||
"electron-context-menu": "^2.3.0",
|
"electron-context-menu": "^2.3.0",
|
||||||
"electron-is": "^3.0.0",
|
"electron-is": "^3.0.0",
|
||||||
|
@ -149,6 +149,10 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
*getStateConnector({payload}, { select }){
|
||||||
|
const state = yield select(state => state.app)
|
||||||
|
payload(state)
|
||||||
|
},
|
||||||
*logout({ payload }, { call, put, select }) {
|
*logout({ payload }, { call, put, select }) {
|
||||||
const uuid = yield select(state => state.app.session_uuid)
|
const uuid = yield select(state => state.app.session_uuid)
|
||||||
const token = yield select(state => state.app.session_token)
|
const token = yield select(state => state.app.session_token)
|
||||||
|
76
src/models/user.ts
Normal file
76
src/models/user.ts
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
import { effect, reducer, dvaModel, subscription, path, BaseModel } from 'dva-model-enhance'
|
||||||
|
import store from 'store'
|
||||||
|
import { app_config } from 'config'
|
||||||
|
import keys from 'config/app_keys'
|
||||||
|
import { user, session } from 'core/models'
|
||||||
|
import { router, verbosity, appInterface } from 'core/libs'
|
||||||
|
import settings from 'core/libs/settings'
|
||||||
|
import { DynamicSDCP } from 'core/libs/extension'
|
||||||
|
import * as core from 'core'
|
||||||
|
|
||||||
|
import jwt from 'jsonwebtoken'
|
||||||
|
import cookie from 'cookie_js'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
namespace: 'user',
|
||||||
|
state: {
|
||||||
|
|
||||||
|
},
|
||||||
|
subscriptions: {
|
||||||
|
setup({ dispatch }) {
|
||||||
|
dispatch({ type: 'query' })
|
||||||
|
},
|
||||||
|
},
|
||||||
|
effects: {
|
||||||
|
*query({ payload }, { call, put, select }) {
|
||||||
|
const stateConnector = yield select(state => state)
|
||||||
|
const { server_key, session_token, session_data, session_uuid, session_valid } = stateConnector.app
|
||||||
|
|
||||||
|
yield put({ type: "updateState", payload: { server_key, session_uuid, session_token, session_data, session_valid } })
|
||||||
|
},
|
||||||
|
*get({ callback, req }, { call, put, select }) {
|
||||||
|
const state = yield select(state => state.user)
|
||||||
|
|
||||||
|
if (state.session_valid) {
|
||||||
|
if (!req) {
|
||||||
|
callback(120, "req params not valid data")
|
||||||
|
}
|
||||||
|
user.get[req.fetch]({username: req.username, server_key: state.server_key, access_token: state.session_token }, (err, res) => {
|
||||||
|
if (err) {
|
||||||
|
return console.log(err)
|
||||||
|
}
|
||||||
|
const data = JSON.parse(res)["user_data"]
|
||||||
|
const frame = {
|
||||||
|
avatar: data.avatar,
|
||||||
|
can_follow: data.can_follow,
|
||||||
|
country_id: data.contry_id,
|
||||||
|
about: data.about,
|
||||||
|
cover: data.cover,
|
||||||
|
is_pro: data.is_pro,
|
||||||
|
lastseen: data.lastseen,
|
||||||
|
points: data.points,
|
||||||
|
registered:data.registered,
|
||||||
|
user_id: data.user_id,
|
||||||
|
verified: data.verified,
|
||||||
|
birthday: data.birthday,
|
||||||
|
details: data.details
|
||||||
|
}
|
||||||
|
return callback(false, frame)
|
||||||
|
})
|
||||||
|
}else{
|
||||||
|
callback(403, "You need to be logged in to get this data")
|
||||||
|
}
|
||||||
|
},
|
||||||
|
*set({ payload }, { call, put, select }) {
|
||||||
|
|
||||||
|
},
|
||||||
|
},
|
||||||
|
reducers: {
|
||||||
|
updateState(state, { payload }) {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
...payload,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
@ -1,9 +1,8 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { pathMatchRegexp } from 'core'
|
import { pathMatchRegexp } from 'core'
|
||||||
import { router } from 'core/libs/router'
|
import HandleError from 'core/libs/errorhandler'
|
||||||
import { Invalid } from 'components'
|
import { Invalid } from 'components'
|
||||||
import styles from './index.less'
|
import styles from './index.less'
|
||||||
import { user } from 'core/models'
|
|
||||||
|
|
||||||
import FollowButton from './components/follow'
|
import FollowButton from './components/follow'
|
||||||
import Menu from './components/menu'
|
import Menu from './components/menu'
|
||||||
@ -12,12 +11,6 @@ import * as antd from 'antd'
|
|||||||
import { connect } from 'umi'
|
import { connect } from 'umi'
|
||||||
const matchRegexp = pathMatchRegexp('/@/:id', location.pathname)
|
const matchRegexp = pathMatchRegexp('/@/:id', location.pathname)
|
||||||
|
|
||||||
const __Avatar = "https://comty.pw/upload/photos/2020/09/MEmX2WskbYdqxxIfG1Ci_12_bf9ae629707074e3dde5b6ff4ccb1caf_avatar.jpeg?cache=1599917094"
|
|
||||||
const __Cover = "https://comty.pw/upload/photos/2020/09/ontbBGwvDruPxxHxzd7K_12_b36cb70f20df86ea77cd04005786bad7_cover.png?cache=1599917132"
|
|
||||||
const __About = "Cum cum cum me gusta damme"
|
|
||||||
const __Followed = false
|
|
||||||
const __Followers = 150
|
|
||||||
|
|
||||||
class UserLayout extends React.Component{
|
class UserLayout extends React.Component{
|
||||||
state = {
|
state = {
|
||||||
styleComponent: "UserLayout",
|
styleComponent: "UserLayout",
|
||||||
@ -35,7 +28,6 @@ class UserLayout extends React.Component{
|
|||||||
const { layoutData } = this.props
|
const { layoutData } = this.props
|
||||||
if (layoutData) {
|
if (layoutData) {
|
||||||
this.setState({ layoutData: {...this.state.layoutData, ...layoutData} })
|
this.setState({ layoutData: {...this.state.layoutData, ...layoutData} })
|
||||||
console.log(this.state.layoutData)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,6 +81,7 @@ class UserLayout extends React.Component{
|
|||||||
@connect(({ app }) => ({ app }))
|
@connect(({ app }) => ({ app }))
|
||||||
export default class UserIndexer extends React.Component {
|
export default class UserIndexer extends React.Component {
|
||||||
state = {
|
state = {
|
||||||
|
ErrorCode: null,
|
||||||
loading: true,
|
loading: true,
|
||||||
response: null,
|
response: null,
|
||||||
layoutData: null
|
layoutData: null
|
||||||
@ -98,48 +91,32 @@ export default class UserIndexer extends React.Component {
|
|||||||
|
|
||||||
componentDidMount(){
|
componentDidMount(){
|
||||||
if (matchRegexp) {
|
if (matchRegexp) {
|
||||||
user.get.profileData({username: matchRegexp[1], server_key: this.props.app.server_key, access_token: this.props.app.session_token}, (err, res) => {
|
this.props.dispatch({
|
||||||
if (err) {
|
type: "user/get",
|
||||||
return false
|
req: {
|
||||||
|
fetch: "profileData",
|
||||||
|
username: matchRegexp[1]
|
||||||
|
},
|
||||||
|
callback: (err, res) => {
|
||||||
|
if(err){
|
||||||
|
this.setState({ ErrorCode: err })
|
||||||
|
return HandleError({ code: err, msg: res })
|
||||||
}
|
}
|
||||||
try {
|
this.setState({ loading: false, layoutData: res })
|
||||||
const data = JSON.parse(res)["user_data"]
|
|
||||||
const frame = {
|
|
||||||
avatar: data.avatar,
|
|
||||||
can_follow: data.can_follow,
|
|
||||||
country_id: data.contry_id,
|
|
||||||
about: data.about,
|
|
||||||
cover: data.cover,
|
|
||||||
is_pro: data.is_pro,
|
|
||||||
lastseen: data.lastseen,
|
|
||||||
points: data.points,
|
|
||||||
registered:data.registered,
|
|
||||||
user_id: data.user_id,
|
|
||||||
verified: data.verified,
|
|
||||||
birthday: data.birthday,
|
|
||||||
details: data.details
|
|
||||||
}
|
|
||||||
|
|
||||||
this.setState({ layoutData: frame, loading: false })
|
|
||||||
console.log(frame)
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
console.log(error)
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}else{
|
}else{
|
||||||
this.setState({ loading: false })
|
this.setState({ ErrorCode: 140 })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
render() {
|
render() {
|
||||||
|
if (this.state.ErrorCode) {
|
||||||
|
return <Invalid typeByCode={this.state.ErrorCode} messageProp1={location.pathname} />
|
||||||
|
}
|
||||||
if (this.state.loading) {
|
if (this.state.loading) {
|
||||||
return <div style={{ display: "flex", width: "100%", justifyContent: "center", alignContent: "center" }}><antd.Card style={{ width: "100%" }} ><antd.Skeleton active /></antd.Card></div>
|
return <div style={{ display: "flex", width: "100%", justifyContent: "center", alignContent: "center" }}><antd.Card style={{ width: "100%" }} ><antd.Skeleton active /></antd.Card></div>
|
||||||
}
|
}
|
||||||
if (matchRegexp) {
|
|
||||||
return <UserLayout layoutData={this.state.layoutData} />
|
return <UserLayout layoutData={this.state.layoutData} />
|
||||||
}
|
}
|
||||||
return <Invalid type="index" messageProp1={location.pathname} />
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user