Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Entity, LiveData } from '@toeverything/infra';
import type { IndexerStore } from '../stores/indexer';
import type { WorkspaceService } from '@affine/core/modules/workspace';

export interface IndexerConfig {
type: 'local' | 'cloud';
lastIndexedAt?: Date;
status: 'idle' | 'indexing' | 'error';
error?: string;
}

export class Indexer extends Entity {
status$ = new LiveData<number>(this.store.status);

constructor(
private readonly workspaceService: WorkspaceService,

Check failure on line 16 in packages/frontend/core/src/modules/workspace-indexer-embedding/entities/indexer.ts

View workflow job for this annotation

GitHub Actions / Typecheck

Property 'workspaceService' is declared but its value is never read.
private readonly store: IndexerStore,
) {
super();
}

async startIndexing() {
await this.store.startIndexing();
}

override dispose(): void {
super.dispose();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Service } from '@toeverything/infra';
import { Indexer } from '../entities/indexer';

export class IndexerService extends Service {
indexer = this.framework.createEntity(Indexer);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Store, LiveData } from '@toeverything/infra';
import type { WorkspaceServerService } from '@affine/core/modules/cloud';

export class IndexerStore extends Store {
private readonly _status$ = new LiveData<number>(0);

constructor(private readonly workspaceServerService: WorkspaceServerService) {
super();
}

get status() {
return this._status$.value;
}

startIndexing() {
if (!this.workspaceServerService.server) {
throw new Error('[IndexerStore]No Server');
}

this.workspaceServerService.server.gql({});

Check failure on line 20 in packages/frontend/core/src/modules/workspace-indexer-embedding/stores/indexer.ts

View workflow job for this annotation

GitHub Actions / Typecheck

Argument of type '{}' is not assignable to parameter of type 'QueryOptions<GraphQLQuery>'.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useI18n } from '@affine/i18n';
import type React from 'react';

import { EmbeddingSettings } from './embedding-settings';
import { IndexerSettings } from './indexer-settings';

export const IndexerEmbeddingSettings: React.FC = () => {
const t = useI18n();
Expand All @@ -17,6 +18,7 @@ export const IndexerEmbeddingSettings: React.FC = () => {
/>

<EmbeddingSettings />
<IndexerSettings />
</>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import React, { useState } from 'react';
import { Button, Progress } from '@affine/component';
import {
SettingRow,
SettingWrapper,
} from '@affine/component/setting-components';
import { useI18n } from '@affine/i18n';

interface IndexerSettingsProps {}

export const IndexerSettings: React.FC<IndexerSettingsProps> = ({}) => {
const t = useI18n();
const [indexingProgress, setIndexingProgress] = useState(0);
const [isIndexing, setIsIndexing] = useState(false);

const handleReindexClick = React.useCallback(() => {
setIsIndexing(true);
setIndexingProgress(0);

// Simulated progress for demo
const interval = setInterval(() => {
setIndexingProgress(prev => {
if (prev >= 100) {
clearInterval(interval);
setIsIndexing(false);
return 100;
}
return prev + 10;
});
}, 1000);
}, []);

return (
<SettingWrapper title={t['Indexer']()}>
<SettingRow
name=""
desc={t[
'The indexer can choose from cloud and local sources. If the indexer is local, it may consume more memory.'
]()}
></SettingRow>

<SettingRow
name={t['Indexing Progress']()}
data-testid="indexer-indexing-progress-setting-row"
style={{ marginBottom: 10 }}
>
<Button onClick={handleReindexClick} disabled={isIndexing}>
{isIndexing ? t['Indexing...']() : t['Resync Indexing']()}
</Button>
</SettingRow>

<Progress
readonly
value={indexingProgress}
style={{ width: '100%', height: '20px' }}
/>
</SettingWrapper>
);
};
Loading