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
12 changes: 10 additions & 2 deletions src/@types/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,8 @@
"gotIt": "Got it",
"retry": "Retry",
"uploadFailed": "Upload failed.",
"copyLinkOriginal": "Copy link to original"
"copyLinkOriginal": "Copy link to original",
"search": "Search"
},
"label": {
"welcome": "Welcome!",
Expand Down Expand Up @@ -507,6 +508,8 @@
"namespaceLengthAtLeast2Characters": "The namespace must be at least 2 characters long",
"onlyWorkspaceOwnerCanUpdateNamespace": "Only workspace owner can update the namespace",
"onlyWorkspaceOwnerCanRemoveHomepage": "Only workspace owner can remove the homepage",
"onlyWorkspaceOwnerCanChangeHomepage": "Only workspace owner can change the homepage",
"onlyProCanSetHomepage": "Only Pro Plan workspace owner can set the homepage",
"setHomepageFailed": "Failed to set homepage",
"namespaceTooLong": "The namespace is too long, please try another one",
"namespaceTooShort": "The namespace is too short, please try another one",
Expand Down Expand Up @@ -3039,5 +3042,10 @@
"memberCount_zero": "{{count}} members",
"memberCount_one": "{{count}} member",
"memberCount_many": "{{count}} members",
"memberCount_other": "{{count}} members"
"memberCount_other": "{{count}} members",
"aiMatch": "AI match",
"titleMatch": "Title match",
"namespace": "Namespace",
"manageNamespaceDescription": "Manage your namespace and homepage",
"homepage": "Homepage"
}
143 changes: 142 additions & 1 deletion src/application/services/js-services/http/http_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ import {
CreateSpacePayload,
UpdateSpacePayload,
Role,
WorkspaceMember, QuickNote, QuickNoteEditorData, CreateWorkspacePayload, UpdateWorkspacePayload,
WorkspaceMember,
QuickNote,
QuickNoteEditorData,
CreateWorkspacePayload,
UpdateWorkspacePayload,
PublishViewPayload,
UploadPublishNamespacePayload,
} from '@/application/types';
import { GlobalComment, Reaction } from '@/application/comment.type';
import { initGrantService, refreshToken } from '@/application/services/js-services/http/gotrue';
Expand Down Expand Up @@ -328,6 +334,48 @@ export async function getUserWorkspaceInfo (): Promise<{
return Promise.reject(data);
}

export async function publishView (workspaceId: string, viewId: string, payload?: PublishViewPayload) {
const url = `/api/workspace/${workspaceId}/page-view/${viewId}/publish`;
const response = await axiosInstance?.post<{
code: number;
message: string;
}>(url, payload);

if (response?.data.code === 0) {
return;
}

return Promise.reject(response?.data);
}

export async function unpublishView (workspaceId: string, viewId: string) {
const url = `/api/workspace/${workspaceId}/page-view/${viewId}/unpublish`;
const response = await axiosInstance?.post<{
code: number;
message: string;
}>(url);

if (response?.data.code === 0) {
return;
}

return Promise.reject(response?.data);
}

export async function updatePublishNamespace (workspaceId: string, payload: UploadPublishNamespacePayload) {
const url = `/api/workspace/${workspaceId}/publish-namespace`;
const response = await axiosInstance?.put<{
code: number;
message: string;
}>(url, payload);

if (response?.data.code === 0) {
return;
}

return Promise.reject(response?.data);
}

export async function getPublishViewMeta (namespace: string, publishName: string) {
const url = `/api/workspace/v1/published/${namespace}/${publishName}`;
const response = await axiosInstance?.get<{
Expand Down Expand Up @@ -491,6 +539,9 @@ export async function getPublishInfoWithViewId (viewId: string) {
data?: {
namespace: string;
publish_name: string;
publisher_email: string;
view_id: string;
publish_timestamp: string;
};
message: string;
}>(url);
Expand Down Expand Up @@ -596,6 +647,75 @@ export async function getView (workspaceId: string, viewId: string, depth: numbe
return Promise.reject(data);
}

export async function getPublishNamespace (workspaceId: string) {
const url = `/api/workspace/${workspaceId}/publish-namespace`;
const response = await axiosInstance?.get<{
code: number;
data?: string;
message: string;
}>(url);

const data = response?.data;

if (data?.code === 0 && data.data) {
return data.data;
}

return Promise.reject(data);
}

export async function getPublishHomepage (workspaceId: string) {
const url = `/api/workspace/${workspaceId}/publish-default`;
const response = await axiosInstance?.get<{
code: number;
data?: {
namespace: string;
publish_name: string;
publisher_email: string;
view_id: string;
};
message: string;
}>(url);

const data = response?.data;

if (data?.code === 0 && data.data) {
return data.data;
}

return Promise.reject(data);
}

export async function updatePublishHomepage (workspaceId: string, viewId: string) {
const url = `/api/workspace/${workspaceId}/publish-default`;
const response = await axiosInstance?.put<{
code: number;
message: string;
}>(url, {
view_id: viewId,
});

if (response?.data.code === 0) {
return;
}

return Promise.reject(response?.data);
}

export async function removePublishHomepage (workspaceId: string) {
const url = `/api/workspace/${workspaceId}/publish-default`;
const response = await axiosInstance?.delete<{
code: number;
message: string;
}>(url);

if (response?.data.code === 0) {
return;
}

return Promise.reject(response?.data);
}

export async function getPublishOutline (publishNamespace: string) {
const url = `/api/workspace/published-outline/${publishNamespace}`;
const response = await axiosInstance?.get<{
Expand Down Expand Up @@ -1679,5 +1799,26 @@ export async function cancelSubscription (workspaceId: string, plan: Subscriptio
return;
}

return Promise.reject(res?.data);
}

export async function searchWorkspace (workspaceId: string, query: string) {
const url = `/api/search/${workspaceId}`;
const res = await axiosInstance?.get<{
code: number;
data: {
object_id: string
}[];
message: string;
}>(url, {
params: {
query,
},
});

if (res?.data.code === 0) {
return res?.data.data.map(item => item.object_id);
}

return Promise.reject(res?.data);
}
51 changes: 49 additions & 2 deletions src/application/services/js-services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ import {
import {
CreatePagePayload, CreateSpacePayload, CreateWorkspacePayload,
DatabaseRelations,
DuplicatePublishView, QuickNoteEditorData,
DuplicatePublishView, PublishViewPayload, QuickNoteEditorData,
SubscriptionInterval, SubscriptionPlan,
Types, UpdatePagePayload, UpdateSpacePayload, UpdateWorkspacePayload, WorkspaceMember,
Types, UpdatePagePayload, UpdateSpacePayload, UpdateWorkspacePayload, UploadPublishNamespacePayload, WorkspaceMember,
YjsEditorKey,
} from '@/application/types';
import { applyYDoc } from '@/application/ydoc/apply';
Expand Down Expand Up @@ -65,6 +65,43 @@ export class AFClientService implements AFService {
return this.clientId;
}

async publishView (workspaceId: string, viewId: string, payload?: PublishViewPayload) {
if (this.publishViewInfo.has(viewId)) {
this.publishViewInfo.delete(viewId);
}

return APIService.publishView(workspaceId, viewId, payload);
}

async unpublishView (workspaceId: string, viewId: string) {
if (this.publishViewInfo.has(viewId)) {
this.publishViewInfo.delete(viewId);
}

return APIService.unpublishView(workspaceId, viewId);
}

async updatePublishNamespace (workspaceId: string, payload: UploadPublishNamespacePayload) {
this.publishViewInfo.clear();
return APIService.updatePublishNamespace(workspaceId, payload);
}

async getPublishNamespace (workspaceId: string) {
return APIService.getPublishNamespace(workspaceId);
}

async getPublishHomepage (workspaceId: string) {
return APIService.getPublishHomepage(workspaceId);
}

async updatePublishHomepage (workspaceId: string, viewId: string) {
return APIService.updatePublishHomepage(workspaceId, viewId);
}

async removePublishHomepage (workspaceId: string) {
return APIService.removePublishHomepage(workspaceId);
}

async getPublishViewMeta (namespace: string, publishName: string) {
const name = `${namespace}_${publishName}`;

Expand Down Expand Up @@ -165,6 +202,9 @@ export class AFClientService implements AFService {
return this.publishViewInfo.get(viewId) as {
namespace: string;
publishName: string;
publisherEmail: string;
viewId: string;
publishedAt: string;
};
}

Expand All @@ -179,6 +219,9 @@ export class AFClientService implements AFService {
const data = {
namespace,
publishName: info.publish_name,
publisherEmail: info.publisher_email,
viewId: info.view_id,
publishedAt: info.publish_timestamp,
};

this.publishViewInfo.set(viewId, data);
Expand Down Expand Up @@ -568,4 +611,8 @@ export class AFClientService implements AFService {
deleteQuickNote (workspaceId: string, id: string) {
return APIService.deleteQuickNote(workspaceId, id);
}

searchWorkspace (workspaceId: string, query: string) {
return APIService.searchWorkspace(workspaceId, query);
}
}
3 changes: 2 additions & 1 deletion src/application/services/js-services/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class SyncManager {
private setupListener () {
this.doc.on('update', (_update: Uint8Array, origin: CollabOrigin) => {
if (origin === CollabOrigin.Remote) return;

console.log('Local changes detected. Sending update...', origin);
this.debouncedSendUpdate();
});
}
Expand Down Expand Up @@ -118,6 +118,7 @@ export class SyncManager {

public initialize () {
if (this.hasUnsyncedChanges) {
console.log('Unsynced changes found. Sending update...');
// Send an update if there are unsynced changes
this.debouncedSendUpdate();
}
Expand Down
23 changes: 20 additions & 3 deletions src/application/services/services.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ import {
UpdateSpacePayload,
WorkspaceMember,
QuickNoteEditorData,
QuickNote, Subscription, CreateWorkspacePayload, UpdateWorkspacePayload,
QuickNote,
Subscription,
CreateWorkspacePayload,
UpdateWorkspacePayload,
PublishViewPayload,
UploadPublishNamespacePayload,
} from '@/application/types';
import { GlobalComment, Reaction } from '@/application/comment.type';
import { ViewMeta } from '@/application/db/tables/view_metas';
Expand Down Expand Up @@ -53,6 +58,7 @@ export interface WorkspaceService {
deleteWorkspace: (workspaceId: string) => Promise<void>;
getWorkspaceMembers: (workspaceId: string) => Promise<WorkspaceMember[]>;
inviteMembers: (workspaceId: string, emails: string[]) => Promise<void>;
searchWorkspace: (workspaceId: string, searchTerm: string) => Promise<string[]>;
}

export interface AppService {
Expand Down Expand Up @@ -137,11 +143,22 @@ export interface TemplateService {
}

export interface PublishService {

publishView: (workspaceId: string, viewId: string, payload?: PublishViewPayload) => Promise<void>;
unpublishView: (workspaceId: string, viewId: string) => Promise<void>;
updatePublishNamespace: (workspaceId: string, payload: UploadPublishNamespacePayload) => Promise<void>;
getPublishViewMeta: (namespace: string, publishName: string) => Promise<ViewMeta>;
getPublishView: (namespace: string, publishName: string) => Promise<YDoc>;
getPublishRowDocument: (viewId: string) => Promise<YDoc>;
getPublishInfo: (viewId: string) => Promise<{ namespace: string; publishName: string }>;
getPublishInfo: (viewId: string) => Promise<{
namespace: string;
publishName: string,
publisherEmail: string,
publishedAt: string
}>;
getPublishNamespace: (namespace: string) => Promise<string>;
getPublishHomepage: (workspaceId: string) => Promise<{ view_id: string }>;
updatePublishHomepage: (workspaceId: string, viewId: string) => Promise<void>;
removePublishHomepage: (workspaceId: string) => Promise<void>;

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

Expand Down
17 changes: 17 additions & 0 deletions src/application/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,16 @@ export enum CollabOrigin {

}

export interface PublishViewPayload {
publish_name?: string;
visible_database_view_ids?: string[];
}

export interface UploadPublishNamespacePayload {
old_namespace: string;
new_namespace: string;
}

export const layoutMap = {
[ViewLayout.Document]: 'document',
[ViewLayout.Grid]: 'grid',
Expand Down Expand Up @@ -1020,4 +1030,11 @@ export interface CreateWorkspacePayload {

export interface UpdateWorkspacePayload {
workspace_name: string;
}

export enum SettingMenuItem {
ACCOUNT = 'ACCOUNT',
WORKSPACE = 'WORKSPACE',
MEMBERS = 'MEMBERS',
SITES = 'SITES',
}
2 changes: 1 addition & 1 deletion src/application/ydoc/apply/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function applyYDoc(doc: Y.Doc, state: Uint8Array) {
doc,
() => {
try {
Y.applyUpdate(doc, state);
Y.applyUpdate(doc, state, CollabOrigin.Remote);
} catch (e) {
console.error('Error applying', doc, e);
throw e;
Expand Down
Loading
Loading