Skip to content

Commit 3cc21bc

Browse files
committed
fix: 修复web mobile 模式的显示问题
1 parent 75fff96 commit 3cc21bc

4 files changed

Lines changed: 143 additions & 10 deletions

File tree

apps/desktop/src/pages/Profile.tsx

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export default function Profile() {
7373
const [showCreateModal, setShowCreateModal] = useState(false);
7474
const [newCollectionName, setNewCollectionName] = useState("");
7575
const [showDropdown, setShowDropdown] = useState(false);
76+
const [syncing, setSyncing] = useState<string | null>(null);
7677
const dropdownRef = useRef<HTMLDivElement>(null);
7778

7879
// Close dropdown on click outside
@@ -173,6 +174,31 @@ export default function Profile() {
173174

174175
const downloadedBooks: Book[] = [];
175176

177+
const handleSync = async (type: "full" | "incremental") => {
178+
const title = type === "full" ? "全量更新" : "增量更新";
179+
const message =
180+
type === "full"
181+
? "扫描所有本地书籍,新增数据库不存在的,标记已删除的,重新抓取所有现有书籍的元数据。"
182+
: "仅扫描新数据,现有数据不做处理。";
183+
184+
if (!window.confirm(`${title}\n\n${message}\n\n确认开始更新吗?`)) {
185+
return;
186+
}
187+
188+
setSyncing(type);
189+
try {
190+
const { getApiClient } = await import("@bookdock/api-client");
191+
const api = getApiClient();
192+
const res = await api.syncBooks(type);
193+
alert(res.data?.message || `${type === "full" ? "全量" : "增量"}更新成功`);
194+
} catch (e: any) {
195+
alert(e?.response?.data?.message || "同步失败");
196+
} finally {
197+
setSyncing(null);
198+
setShowDropdown(false);
199+
}
200+
};
201+
176202
const handleCreateCollection = useCallback(async () => {
177203
if (!newCollectionName.trim()) return;
178204
try {
@@ -479,6 +505,22 @@ export default function Profile() {
479505
<Plus className="w-4 h-4" />
480506
<span>新建书单</span>
481507
</button>
508+
<button
509+
onClick={() => { handleSync("incremental"); setShowDropdown(false); }}
510+
disabled={!!syncing}
511+
className="w-full flex items-center gap-2 px-4 py-2.5 text-sm text-gray-700 dark:text-gray-200 hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors disabled:opacity-50"
512+
>
513+
<Plus className="w-4 h-4" />
514+
<span>增量更新</span>
515+
</button>
516+
<button
517+
onClick={() => { handleSync("full"); setShowDropdown(false); }}
518+
disabled={!!syncing}
519+
className="w-full flex items-center gap-2 px-4 py-2.5 text-sm text-gray-700 dark:text-gray-200 hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors disabled:opacity-50"
520+
>
521+
<RefreshCw className="w-4 h-4" />
522+
<span>全量更新</span>
523+
</button>
482524
<Link
483525
to="/membership"
484526
onClick={() => setShowDropdown(false)}

apps/mobile/src/screens/ProfileScreen.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -379,21 +379,22 @@ export function ProfileScreen() {
379379
<Ionicons name="folder-open-outline" size={18} color={theme.colors.text} />
380380
<Text style={{ fontSize: fontSizes.md, color: theme.colors.text }}>新建书单</Text>
381381
</TouchableOpacity>
382+
<View style={{ height: 1, backgroundColor: theme.colors.border, marginHorizontal: spacing.md }} />
383+
<TouchableOpacity style={styles.menuItem} onPress={() => handleSync('incremental')} disabled={!!syncing}>
384+
<Ionicons name="add-circle-outline" size={18} color={theme.colors.text} />
385+
<Text style={{ fontSize: fontSizes.md, color: theme.colors.text }}>增量更新</Text>
386+
</TouchableOpacity>
387+
<TouchableOpacity style={styles.menuItem} onPress={() => handleSync('full')} disabled={!!syncing}>
388+
<Ionicons name="refresh-circle-outline" size={18} color={theme.colors.text} />
389+
<Text style={{ fontSize: fontSizes.md, color: theme.colors.text }}>全量更新</Text>
390+
</TouchableOpacity>
382391
{user?.role === 'admin' && (
383392
<>
384393
<View style={{ height: 1, backgroundColor: theme.colors.border, marginHorizontal: spacing.md }} />
385394
<TouchableOpacity style={styles.menuItem} onPress={() => { setMenuVisible(false); navigation.navigate('AdminUsers'); }}>
386395
<Ionicons name="people-outline" size={18} color={theme.colors.text} />
387396
<Text style={{ fontSize: fontSizes.md, color: theme.colors.text }}>用户管理</Text>
388397
</TouchableOpacity>
389-
<TouchableOpacity style={styles.menuItem} onPress={() => handleSync('incremental')} disabled={!!syncing}>
390-
<Ionicons name="add-circle-outline" size={18} color={theme.colors.text} />
391-
<Text style={{ fontSize: fontSizes.md, color: theme.colors.text }}>增量更新</Text>
392-
</TouchableOpacity>
393-
<TouchableOpacity style={styles.menuItem} onPress={() => handleSync('full')} disabled={!!syncing}>
394-
<Ionicons name="refresh-circle-outline" size={18} color={theme.colors.text} />
395-
<Text style={{ fontSize: fontSizes.md, color: theme.colors.text }}>全量更新</Text>
396-
</TouchableOpacity>
397398
</>
398399
)}
399400
</View>

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"private": true,
55
"packageManager": "pnpm@10.33.4",
66
"scripts": {
7-
"dev": "pnpm -r dev",
7+
"dev": "concurrently \"pnpm --filter @bookdock/server run dev\" \"pnpm --filter @bookdock/desktop run dev\"",
88
"dev:desktop": "pnpm --filter @bookdock/desktop dev:desktop",
99
"build": "pnpm -r build",
1010
"lint": "pnpm -r lint",
@@ -15,6 +15,7 @@
1515
"devDependencies": {
1616
"@tailwindcss/typography": "^0.5.19",
1717
"babel-plugin-module-resolver": "^5.0.3",
18+
"concurrently": "^10.0.3",
1819
"vite-plugin-pwa": "^1.2.0",
1920
"workbox-window": "^7.4.0"
2021
},
@@ -24,4 +25,4 @@
2425
"react": "18.3.1",
2526
"react-native": "0.76.9"
2627
}
27-
}
28+
}

pnpm-lock.yaml

Lines changed: 89 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)