Files
halo/ui/console-src/composables/use-content-snapshot.ts
Ryan Wang a93479dc34 chore: organize and fix imports (#6152)
#### What type of PR is this?

/area ui
/kind improvement
/milestone 2.17.x

#### What this PR does / why we need it:

重新组织和固定 UI 部分代码的 imports 导入,防止后续因为 imports 的顺序造成不必要的 diff。

基于:https://github.com/halo-dev/halo/pull/6151

#### Does this PR introduce a user-facing change?

```release-note
None
```
2024-06-26 10:42:50 +00:00

34 lines
743 B
TypeScript

import { coreApiClient } from "@halo-dev/api-client";
import { nextTick, ref, watch, type Ref } from "vue";
interface SnapshotContent {
version: Ref<number>;
handleFetchSnapshot: () => Promise<void>;
}
export function useContentSnapshot(
snapshotName: Ref<string | undefined>
): SnapshotContent {
const version = ref(0);
watch(snapshotName, () => {
nextTick(() => {
handleFetchSnapshot();
});
});
const handleFetchSnapshot = async () => {
if (!snapshotName.value) {
return;
}
const { data } = await coreApiClient.content.snapshot.getSnapshot({
name: snapshotName.value,
});
version.value = data.metadata.version || 0;
};
return {
version,
handleFetchSnapshot,
};
}