feat: refresh app list after mock import flow
This commit is contained in:
1 parent
bbf4123844
commit
36671fd8c1
4 files changed
+53
-2
No files matched your search
@@ -12,13 +12,17 @@ export struct AppListView {
|
||||
Column() {
|
||||
Text(item.name).fontSize(18)
|
||||
Text(item.version || '').fontSize(12)
|
||||
Text(item.status).fontSize(12)
|
||||
Text(item.status === 'ready' ? '可运行' : '不可运行').fontSize(12)
|
||||
}
|
||||
.width('100%')
|
||||
.padding(16)
|
||||
.opacity(item.status === 'ready' ? 1 : 0.5)
|
||||
.alignItems(HorizontalAlign.Start)
|
||||
}
|
||||
.onClick(() => {
|
||||
if (item.status !== 'ready') {
|
||||
return
|
||||
}
|
||||
if (this.onItemTap) {
|
||||
this.onItemTap(item.id)
|
||||
}
|
||||
|
||||
@@ -8,11 +8,13 @@ import { AppListView } from '../components/appList/AppListView'
|
||||
|
||||
@Component
|
||||
export struct AppListPage {
|
||||
@Prop refreshToken: number = 0
|
||||
onNavigateImport?: () => void
|
||||
onNavigateRun?: (appId: string) => void
|
||||
|
||||
@State refreshTick: number = 0
|
||||
@State selectedAppId: string = ''
|
||||
private lastHandledRefreshToken: number = -1
|
||||
private store: AppCatalogStore = new AppCatalogStore()
|
||||
private unsubscribe?: () => void
|
||||
|
||||
@@ -32,6 +34,14 @@ export struct AppListPage {
|
||||
}
|
||||
}
|
||||
|
||||
private ensureRefreshByToken(): void {
|
||||
if (this.refreshToken === this.lastHandledRefreshToken) {
|
||||
return
|
||||
}
|
||||
this.lastHandledRefreshToken = this.refreshToken
|
||||
this.store.refreshApps()
|
||||
}
|
||||
|
||||
private openImportPage(): void {
|
||||
if (this.onNavigateImport) {
|
||||
this.onNavigateImport()
|
||||
@@ -50,8 +60,10 @@ export struct AppListPage {
|
||||
}
|
||||
|
||||
build() {
|
||||
this.ensureRefreshByToken()
|
||||
|
||||
Column() {
|
||||
Text(`${this.refreshTick}`).fontSize(1).opacity(0)
|
||||
Text(`${this.refreshTick}-${this.refreshToken}`).fontSize(1).opacity(0)
|
||||
PageHeader({ title: '应用列表' })
|
||||
if (this.selectedAppId) {
|
||||
StatusBanner({ text: `已选择应用:${this.selectedAppId}` })
|
||||
|
||||
@@ -34,6 +34,7 @@ struct ShellRootPage {
|
||||
Text(`${this.catalogRefreshTick}`).fontSize(1).opacity(0)
|
||||
if (this.currentRoute === 'appList') {
|
||||
AppListPage({
|
||||
refreshToken: this.catalogRefreshTick,
|
||||
onNavigateImport: () => this.goToImport(),
|
||||
onNavigateRun: (appId: string) => this.goToRun(appId)
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user