refactor(Post, PostMapper, PostRepository, CreatePostScreen, HomeScreen): update communityId to channelId for improved clarity
- Renamed communityId to channelId across Post entity, PostMapper, and PostRepository for consistency and clarity. - Updated CreatePostScreen to include channel selection functionality, enhancing user experience when creating posts. - Adjusted HomeScreen to support filtering posts by channel, improving content organization. - Refactored related interfaces and services to align with the new channelId terminology, ensuring a cohesive codebase.
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
import AsyncStorage from '@react-native-async-storage/async-storage';
|
||||
import { CommonActions } from '@react-navigation/native';
|
||||
import Constants from 'expo-constants';
|
||||
import { Platform } from 'react-native';
|
||||
|
||||
// 生产地址 https://bbs.littlelan.cn
|
||||
const getBaseUrl = () => {
|
||||
@@ -381,12 +382,20 @@ class ApiClient {
|
||||
): Promise<ApiResponse<T>> {
|
||||
const formData = new FormData();
|
||||
|
||||
// 添加文件(使用image字段名)
|
||||
formData.append('image', {
|
||||
uri: file.uri,
|
||||
name: file.name,
|
||||
type: file.type,
|
||||
} as any);
|
||||
// 添加文件(使用 image 字段名)
|
||||
// Web 端需要 append Blob/File;原生端可以直接传 { uri, name, type }。
|
||||
if (Platform.OS === 'web') {
|
||||
const fileResponse = await fetch(file.uri);
|
||||
const blob = await fileResponse.blob();
|
||||
const uploadFile = new File([blob], file.name, { type: file.type || blob.type || 'application/octet-stream' });
|
||||
formData.append('image', uploadFile);
|
||||
} else {
|
||||
formData.append('image', {
|
||||
uri: file.uri,
|
||||
name: file.name,
|
||||
type: file.type,
|
||||
} as any);
|
||||
}
|
||||
|
||||
// 添加额外数据
|
||||
if (additionalData) {
|
||||
|
||||
29
src/services/channelService.ts
Normal file
29
src/services/channelService.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { api } from './api';
|
||||
|
||||
export interface ChannelItem {
|
||||
id: string;
|
||||
name: string;
|
||||
slug: string;
|
||||
description?: string;
|
||||
sort_order: number;
|
||||
is_active: boolean;
|
||||
}
|
||||
|
||||
interface ChannelListResponse {
|
||||
list: ChannelItem[];
|
||||
}
|
||||
|
||||
class ChannelService {
|
||||
async list(): Promise<ChannelItem[]> {
|
||||
try {
|
||||
const res = await api.get<ChannelListResponse>('/channels');
|
||||
return res.data?.list || [];
|
||||
} catch (error) {
|
||||
console.error('[channelService] 获取频道失败:', error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const channelService = new ChannelService();
|
||||
|
||||
@@ -44,6 +44,8 @@ export { pushService, registerDevice, getDevices, unregisterDevice, updateDevice
|
||||
|
||||
// 投票服务
|
||||
export { voteService } from './voteService';
|
||||
export { channelService } from './channelService';
|
||||
export type { ChannelItem } from './channelService';
|
||||
|
||||
// SSE 实时服务
|
||||
export { sseService } from './sseService';
|
||||
|
||||
@@ -29,6 +29,7 @@ interface CreatePostRequest {
|
||||
title: string;
|
||||
content: string;
|
||||
images?: string[];
|
||||
channel_id?: string;
|
||||
}
|
||||
|
||||
// 更新帖子请求
|
||||
@@ -45,7 +46,7 @@ class PostService {
|
||||
page = 1,
|
||||
pageSize = 20,
|
||||
tab?: string,
|
||||
communityId?: string
|
||||
channelId?: string
|
||||
): Promise<PaginatedData<Post>> {
|
||||
const params: Record<string, any> = {
|
||||
page,
|
||||
@@ -55,8 +56,8 @@ class PostService {
|
||||
if (tab) {
|
||||
params.tab = tab;
|
||||
}
|
||||
if (communityId) {
|
||||
params.community_id = communityId;
|
||||
if (channelId) {
|
||||
params.channel_id = channelId;
|
||||
}
|
||||
|
||||
const response = await api.get<PostListResponse>('/posts', params);
|
||||
|
||||
Reference in New Issue
Block a user