Skip to content

Commit

Permalink
Merge pull request #146 from funnyzak/refactor/code11
Browse files Browse the repository at this point in the history
  • Loading branch information
funnyzak authored Oct 21, 2022
2 parents 6cbd340 + 2a4479f commit 4336b5b
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 49 deletions.
4 changes: 2 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ android {
applicationId "github.funnyzak.v2ex"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 35
versionName "0.8.3"
versionCode 36
versionName "0.8.4"
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()

if (isNewArchitectureEnabled()) {
Expand Down
4 changes: 2 additions & 2 deletions ios/app.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 0.8.3;
MARKETING_VERSION = 0.8.4;
OTHER_LDFLAGS = (
"$(inherited)",
"-ObjC",
Expand Down Expand Up @@ -528,7 +528,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 0.8.3;
MARKETING_VERSION = 0.8.4;
OTHER_LDFLAGS = (
"$(inherited)",
"-ObjC",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "v2hub",
"version": "0.8.3",
"version": "0.8.4",
"description": "This project used React Native to build a V2EX mobile client application. The main goal was to build a React Native rapid development scaffold.",
"main": "index.js",
"private": false,
Expand Down
4 changes: 2 additions & 2 deletions src/actions/MemberActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export const unFollowPeople = (member: AppObject.Member) => async (dispatch: Dis
dispatch(cacheMemberFollowing(getState().member.followPeoples))
}

export const setCurrentToken = (token?: AppObject.MToken) => ({
export const setCurrentToken = (token?: AppObject.MemberToken) => ({
type: APP_AUTH,
payload: token
})
Expand All @@ -121,7 +121,7 @@ export const loginByToken = (token: string) => async (dispatch: Dispatch) => {
}
}

const loginByTokenSuccess = (token: AppObject.MToken) => async (dispatch: Dispatch, getState: () => RootState) => {
const loginByTokenSuccess = (token: AppObject.MemberToken) => async (dispatch: Dispatch, getState: () => RootState) => {
await AsyncStorage.setItem(MEMBER_TOKEN_KEY, token.token)

ApiLib.setToken(token.token)
Expand Down
30 changes: 15 additions & 15 deletions src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,23 @@ const defaultConfiguration = {
}

class V2ex {
configuration: AppAPI.BaseConfiguration = defaultConfiguration
configuration: AppAPI.APIConfiguration = defaultConfiguration
root_path?: string
token?: string
reply: AppAPI.Reply = reply(this)
member: AppAPI.Member = member(this)
node: AppAPI.Node = node(this)
topic: AppAPI.Topic = topic(this)
notification: AppAPI.Notification = notification(this)
reply: AppAPI.ReplyAPI = reply(this)
member: AppAPI.MemberAPI = member(this)
node: AppAPI.NodeAPI = node(this)
topic: AppAPI.TopicAPI = topic(this)
notification: AppAPI.NotificationAPI = notification(this)

constructor(options?: AppAPI.APIConfiguration) {
if (options) {
this.setOptions(options)
}
this.init()
}

setOptions(options: AppAPI.BaseConfiguration) {
setOptions(options: AppAPI.APIConfiguration) {
this.configuration = _.merge(this.configuration, options)
this.root_path = `/${this.configuration.store}`

Expand Down Expand Up @@ -106,7 +113,7 @@ class V2ex {

send<T>(
path: string,
method: AppAPI.Method,
method: AppAPI.HttpMethod,
headers?: { [name: string]: string },
params?: Record<string, string>,
data?: any,
Expand Down Expand Up @@ -138,13 +145,6 @@ class V2ex {
headers = _.merge(_headers, headers)

return new Promise<T>((resolve, reject) => {
// console.log({
// uri,
// method,
// headers,
// data,
// ...params
// })
fetch(uri, { method, headers, body: JSON.stringify(data) })
.then((response: Response) => {
if (response.ok) {
Expand Down
6 changes: 3 additions & 3 deletions src/api/lib/member/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AppAPI, AppObject } from '../../types'

export default (v2ex: AppAPI.APP): AppAPI.Member => ({
myToken: () => v2ex.get<AppObject.MToken>('/token', undefined, undefined, undefined, 'v2'),
export default (v2ex: AppAPI.APP): AppAPI.MemberAPI => ({
myToken: () => v2ex.get<AppObject.MemberToken>('/token', undefined, undefined, undefined, 'v2'),

myProfile: () => v2ex.get<AppObject.Member>('/member', undefined, undefined, undefined, 'v2'),

Expand All @@ -15,7 +15,7 @@ export default (v2ex: AppAPI.APP): AppAPI.Member => ({
),

token: (token: string) =>
v2ex.get<AppObject.MToken>(
v2ex.get<AppObject.MemberToken>(
`/token`,
{
Authorization: `Bearer ${token}`
Expand Down
2 changes: 1 addition & 1 deletion src/api/lib/node/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AppAPI, AppObject } from '../../types'

export default (v2ex: AppAPI.APP): AppAPI.Node => ({
export default (v2ex: AppAPI.APP): AppAPI.NodeAPI => ({
get: (id: string | number, version: AppAPI.API_VERSION): Promise<AppObject.Node> =>
v2ex.get<AppObject.Node>(
version === 'v2' ? `/nodes/${id}` : `/nodes/show.json?${typeof id === 'string' ? 'name' : 'id'}=${id}`,
Expand Down
2 changes: 1 addition & 1 deletion src/api/lib/notification/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AppAPI, AppObject } from '../../types'

export default (v2ex: AppAPI.APP): AppAPI.Notification => ({
export default (v2ex: AppAPI.APP): AppAPI.NotificationAPI => ({
/**
* Get my latest notifications
*/
Expand Down
2 changes: 1 addition & 1 deletion src/api/lib/reply/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AppAPI, AppObject } from '../../types'

export default (v2ex: AppAPI.APP): AppAPI.Reply => ({
export default (v2ex: AppAPI.APP): AppAPI.ReplyAPI => ({
/**
* Get topic replies
* @param topic_id : topic id
Expand Down
2 changes: 1 addition & 1 deletion src/api/lib/topic/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AppAPI, AppObject } from '../../types'

export default (v2ex: AppAPI.APP): AppAPI.Topic => ({
export default (v2ex: AppAPI.APP): AppAPI.TopicAPI => ({
/**
* pager note topic list by api version 2
* @param name : node name
Expand Down
37 changes: 19 additions & 18 deletions src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export declare namespace AppAPI {
/**
* V2ex API Configuration
*/
export interface BaseConfiguration {
export interface APIConfiguration {
url?: string
store?: string
userAgent?: string
Expand All @@ -25,7 +25,7 @@ export declare namespace AppAPI {
extend?: { [name: string]: string | undefined }
}

export type Method =
export type HttpMethod =
| 'get'
| 'GET'
| 'delete'
Expand All @@ -50,16 +50,17 @@ export declare namespace AppAPI {
/**
* V2ex Main API
*/
export interface APP {
configuration: BaseConfiguration
export class APP {
constructor(configuration?: APIConfiguration)
configuration: APIConfiguration
root_path?: string
token?: string
node: Node
topic: Topic
notification: Notification
member: Member
reply: Reply
setOptions: (options: BaseConfiguration) => void
node: NodeAPI
topic: TopicAPI
notification: NotificationAPI
member: MemberAPI
reply: ReplyAPI
setOptions: (options: APIConfiguration) => void
init: () => void
setToken(token?: string): void
setUserAgent(userAgent?: string): void
Expand Down Expand Up @@ -100,11 +101,11 @@ export declare namespace AppAPI {
): Promise<T>
getErrorMessageForResponse(data: any): string
}
export interface Member {
export interface MemberAPI {
/**
* Get my token info
*/
myToken: () => Promise<AppObject.MToken>
myToken: () => Promise<AppObject.MemberToken>

/**
* Get my profile
Expand All @@ -119,10 +120,10 @@ export declare namespace AppAPI {
/**
* check user token
*/
token: (token: string) => Promise<AppObject.MToken>
token: (token: string) => Promise<AppObject.MemberToken>
}

export interface Node {
export interface NodeAPI {
/**
* Get node info by node name/id
* @param node id or node name
Expand All @@ -136,7 +137,7 @@ export declare namespace AppAPI {
all(): Promise<AppObject.Node[]>
}

export interface Notification {
export interface NotificationAPI {
/**
* Get my latest notifications
*/
Expand All @@ -148,7 +149,7 @@ export declare namespace AppAPI {
remove: (id: string) => Promise<void>
}

export interface Topic {
export interface TopicAPI {
/**
* Get latest topic list by api version 1
*/
Expand Down Expand Up @@ -180,7 +181,7 @@ export declare namespace AppAPI {
topics(id: string | number, get_type: 'username' | 'node_id' | 'node_name' | 'id'): Promise<AppObject.Topic[]>
}

export interface Reply {
export interface ReplyAPI {
/**
* Get topic replies by api version 1
* @param topic_id : topic id
Expand Down Expand Up @@ -211,7 +212,7 @@ export declare namespace AppObject {
/**
* Member Token Info
*/
export interface MToken {
export interface MemberToken {
token: string
scope: string
expiration: number
Expand Down
2 changes: 1 addition & 1 deletion src/screens/my/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const My = ({
}: ScreenProps &
IState.State & {
profile?: AppObject.Member
token?: AppObject.MToken
token?: AppObject.MemberToken
readedTopics?: AppObject.Topic[]
topics?: AppObject.Topic[]
likeTopics: AppObject.Topic[]
Expand Down
2 changes: 1 addition & 1 deletion src/store/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export declare module IState {
/**
* 用户令牌信息
*/
token?: AppObject.MToken
token?: AppObject.MemberToken

/**
* 用户信息
Expand Down

0 comments on commit 4336b5b

Please sign in to comment.