Skip to content
Merged
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
9 changes: 2 additions & 7 deletions .github/workflows/web_ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,14 @@ jobs:
uses: pnpm/action-setup@v2
with:
version: ${{ env.PNPM_VERSION }}
- name: Node_modules cache
uses: actions/cache@v2
with:
path: node_modules
key: node-modules-${{ runner.os }}


- name: install frontend dependencies
run: |
pnpm install
- name: Run lint check
run: |
pnpm run lint

- name: build and analyze
run: |
pnpm run analyze >> analyze-size.txt
Expand Down
3 changes: 3 additions & 0 deletions deploy/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ http {
root /usr/share/nginx/html;
expires 30d;
access_log off;

add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Methods' 'GET' always;
}

location /.well-known/apple-app-site-association {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"coverage": "pnpm run test:unit && pnpm run test:components"
},
"dependencies": {
"@appflowyinc/editor": "^0.0.40",
"@appflowyinc/ai-chat": "0.0.14",
"@appflowyinc/editor": "^0.1.5",
"@atlaskit/primitives": "^5.5.3",
"@emoji-mart/data": "^1.1.2",
"@emoji-mart/react": "^1.1.1",
Expand Down
476 changes: 470 additions & 6 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/@types/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2695,7 +2695,8 @@
"error": {
"pageNameIsEmpty": "The page name is empty, please try another one"
},
"visitOurWebsite": "Visit our official website"
"visitOurWebsite": "Visit our official website",
"addMessagesToPage": "Add messages to page"
},
"globalComment": {
"comments": "Comments",
Expand Down
4 changes: 4 additions & 0 deletions src/application/services/js-services/http/http_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ export * from './gotrue';

let axiosInstance: AxiosInstance | null = null;

export function getAxiosInstance() {
return axiosInstance;
}

export function initAPIService(config: AFCloudConfig) {
if(axiosInstance) {
return;
Expand Down
4 changes: 4 additions & 0 deletions src/application/services/js-services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ export class AFClientService implements AFService {
APIService.initAPIService(config.cloudConfig);
}

getAxiosInstance() {
return APIService.getAxiosInstance();
}

getClientId() {
return this.clientId;
}
Expand Down
40 changes: 20 additions & 20 deletions src/application/services/js-services/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class SyncManager {

private isSending = false;

constructor (private doc: Y.Doc, private context: {
constructor(private doc: Y.Doc, private context: {
userId: string, workspaceId: string, objectId: string, collabType: Types
}) {
this.versionVector = this.loadVersionVector();
Expand All @@ -26,41 +26,41 @@ export class SyncManager {
this.setupListener();
}

private setupListener () {
private setupListener() {
this.doc.on('update', (_update: Uint8Array, origin: CollabOrigin) => {
if (origin === CollabOrigin.Remote) return;
if(origin === CollabOrigin.Remote) return;
console.log('Local changes detected. Sending update...', origin);
this.debouncedSendUpdate();
});
}

private getStorageKey (baseKey: string): string {
private getStorageKey(baseKey: string): string {
return `${this.context.userId}_${baseKey}_${this.context.workspaceId}_${this.context.objectId}`;
}

private loadVersionVector (): number {
private loadVersionVector(): number {
const storedVector = localStorage.getItem(this.getStorageKey(VERSION_VECTOR_KEY));

return storedVector ? parseInt(storedVector, 10) : 0;
}

private saveVersionVector () {
private saveVersionVector() {
localStorage.setItem(this.getStorageKey(VERSION_VECTOR_KEY), this.versionVector.toString());
}

private loadUnsyncedFlag (): boolean {
private loadUnsyncedFlag(): boolean {
return localStorage.getItem(this.getStorageKey(UNSYNCED_FLAG_KEY)) === 'true';
}

private saveUnsyncedFlag () {
private saveUnsyncedFlag() {
localStorage.setItem(this.getStorageKey(UNSYNCED_FLAG_KEY), this.hasUnsyncedChanges.toString());
}

private loadLastSyncedAt (): string {
private loadLastSyncedAt(): string {
return localStorage.getItem(this.getStorageKey(LAST_SYNCED_AT_KEY)) || '';
}

private saveLastSyncedAt () {
private saveLastSyncedAt() {
localStorage.setItem(this.getStorageKey(LAST_SYNCED_AT_KEY), this.lastSyncedAt);
}

Expand All @@ -71,8 +71,8 @@ export class SyncManager {
void this.sendUpdate();
}, 1000); // 1 second debounce

private async sendUpdate () {
if (this.isSending) return;
private async sendUpdate() {
if(this.isSending) return;
this.isSending = true;

try {
Expand All @@ -85,14 +85,14 @@ export class SyncManager {

const response = await updateCollab(this.context.workspaceId, this.context.objectId, this.context.collabType, update, context);

if (response) {
if(response) {
console.log(`Update sent successfully. Server version: ${response.version_vector}`);

// Update last synced time
this.lastSyncedAt = String(Date.now());
this.saveLastSyncedAt();

if (response.version_vector === this.versionVector) {
if(response.version_vector === this.versionVector) {
// Our update was the latest
this.hasUnsyncedChanges = false;
this.saveUnsyncedFlag();
Expand All @@ -106,7 +106,7 @@ export class SyncManager {
} else {
return Promise.reject(response);
}
} catch (error) {
} catch(error) {
console.error('Failed to send update:', error);
// Keep the unsynced flag as true
this.hasUnsyncedChanges = true;
Expand All @@ -116,23 +116,23 @@ export class SyncManager {
}
}

public initialize () {
if (this.hasUnsyncedChanges) {
public initialize() {
if(this.hasUnsyncedChanges) {
console.log('Unsynced changes found. Sending update...');
// Send an update if there are unsynced changes
this.debouncedSendUpdate();
}
}

public getUnsyncedStatus (): boolean {
public getUnsyncedStatus(): boolean {
return this.hasUnsyncedChanges;
}

public getLastSyncedAt (): string {
public getLastSyncedAt(): string {
return this.lastSyncedAt;
}

public getCurrentVersionVector (): number {
public getCurrentVersionVector(): number {
return this.versionVector;
}
}
4 changes: 3 additions & 1 deletion src/application/services/services.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ import {
TemplateCreator, TemplateCreatorFormValues, TemplateSummary,
UploadTemplatePayload,
} from '@/application/template.type';
import { AxiosInstance } from 'axios';

export type AFService = PublishService & AppService & WorkspaceService & TemplateService & QuickNoteService & {
getClientId: () => string;
getAxiosInstance: () => AxiosInstance | null;
};

export interface AFServiceConfig {
Expand Down Expand Up @@ -163,7 +165,7 @@ export interface PublishService {
updatePublishHomepage: (workspaceId: string, viewId: string) => Promise<void>;
removePublishHomepage: (workspaceId: string) => Promise<void>;

getPublishOutline (namespace: string): Promise<View[]>;
getPublishOutline(namespace: string): Promise<View[]>;

getPublishViewGlobalComments: (viewId: string) => Promise<GlobalComment[]>;
createCommentOnPublishView: (viewId: string, content: string, replyCommentId?: string) => Promise<void>;
Expand Down
Loading
Loading