Skip to content

Commit

Permalink
feat: support publish outline
Browse files Browse the repository at this point in the history
  • Loading branch information
qinluhe committed Sep 4, 2024
1 parent 94c033b commit b4ead0f
Show file tree
Hide file tree
Showing 41 changed files with 528 additions and 234 deletions.
42 changes: 37 additions & 5 deletions frontend/appflowy_web_app/src/application/publish/context.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { GetViewRowsMap, LoadView, LoadViewMeta } from '@/application/collab.type';
import { db } from '@/application/db';
import { ViewMeta } from '@/application/db/tables/view_metas';
import { AFConfigContext } from '@/components/app/app.hooks';
import { View } from '@/application/types';
import { useService } from '@/components/app/app.hooks';
import { notify } from '@/components/_shared/notify';
import { useLiveQuery } from 'dexie-react-hooks';
import { createContext, useCallback, useContext, useEffect, useRef, useState } from 'react';
import { useNavigate } from 'react-router-dom';
Expand All @@ -14,8 +16,8 @@ export interface PublishContextType {
toView: (viewId: string) => Promise<void>;
loadViewMeta: LoadViewMeta;
getViewRowsMap?: GetViewRowsMap;

loadView: LoadView;
outline?: View;
}

export const PublishContext = createContext<PublishContextType | null>(null);
Expand All @@ -36,13 +38,17 @@ export const PublishProvider = ({

return db.view_metas.get(name);
}, [namespace, publishName]);

const [outline, setOutline] = useState<View>();

Check warning on line 42 in frontend/appflowy_web_app/src/application/publish/context.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/publish/context.tsx#L42

Added line #L42 was not covered by tests

const [subscribers, setSubscribers] = useState<Map<string, (meta: ViewMeta) => void>>(new Map());

useEffect(() => {
return () => {
setSubscribers(new Map());
};
}, []);

useEffect(() => {
db.view_metas.hook('creating', (primaryKey, obj) => {
const subscriber = subscribers.get(primaryKey);
Expand Down Expand Up @@ -72,7 +78,8 @@ export const PublishProvider = ({

const prevViewMeta = useRef(viewMeta);

const service = useContext(AFConfigContext)?.service;
const service = useService();

Check warning on line 81 in frontend/appflowy_web_app/src/application/publish/context.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/publish/context.tsx#L81

Added line #L81 was not covered by tests

const navigate = useNavigate();
const toView = useCallback(
async (viewId: string) => {
Expand All @@ -83,16 +90,36 @@ export const PublishProvider = ({
throw new Error('Not found');
}

const { namespace, publishName } = res;
const { namespace: viewNamespace, publishName } = res;

navigate(`/${namespace}/${publishName}`);
prevViewMeta.current = undefined;
navigate(`/${viewNamespace}/${publishName}`, {
replace: true,

Check warning on line 97 in frontend/appflowy_web_app/src/application/publish/context.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/publish/context.tsx#L96-L97

Added lines #L96 - L97 were not covered by tests
});
return;
} catch (e) {
return Promise.reject(e);
}
},
[navigate, service],
);

const loadOutline = useCallback(async () => {

Check warning on line 107 in frontend/appflowy_web_app/src/application/publish/context.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/publish/context.tsx#L107

Added line #L107 was not covered by tests
if (!service || !namespace) return;
console.log('loadOutline', namespace);
try {

Check warning on line 110 in frontend/appflowy_web_app/src/application/publish/context.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/publish/context.tsx#L109-L110

Added lines #L109 - L110 were not covered by tests
const res = await service?.getPublishOutline(namespace);

if (!res) {

Check warning on line 113 in frontend/appflowy_web_app/src/application/publish/context.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/publish/context.tsx#L113

Added line #L113 was not covered by tests
throw new Error('Publish outline not found');
}

Check warning on line 115 in frontend/appflowy_web_app/src/application/publish/context.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/publish/context.tsx#L115

Added line #L115 was not covered by tests

setOutline(res);
} catch (e) {

Check warning on line 118 in frontend/appflowy_web_app/src/application/publish/context.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/publish/context.tsx#L118

Added line #L118 was not covered by tests
notify.error('Publish outline not found');
}
}, [namespace, service]);

Check warning on line 121 in frontend/appflowy_web_app/src/application/publish/context.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/publish/context.tsx#L121

Added line #L121 was not covered by tests

const loadViewMeta = useCallback(
async (viewId: string, callback?: (meta: ViewMeta) => void) => {
try {
Expand Down Expand Up @@ -188,6 +215,10 @@ export const PublishProvider = ({
prevViewMeta.current = viewMeta;
}, [viewMeta]);

useEffect(() => {

Check warning on line 218 in frontend/appflowy_web_app/src/application/publish/context.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/publish/context.tsx#L218

Added line #L218 was not covered by tests
void loadOutline();
}, [loadOutline]);

Check warning on line 220 in frontend/appflowy_web_app/src/application/publish/context.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/publish/context.tsx#L220

Added line #L220 was not covered by tests

return (
<PublishContext.Provider
value={{
Expand All @@ -199,6 +230,7 @@ export const PublishProvider = ({
namespace,
publishName,
isTemplateThumb,
outline,
}}
>
{children}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
TemplateCreator, TemplateCreatorFormValues, TemplateSummary,
UploadTemplatePayload,
} from '@/application/template.type';
import { FolderView, User, Workspace } from '@/application/types';
import { FolderView, User, View, Workspace } from '@/application/types';
import axios, { AxiosInstance } from 'axios';
import dayjs from 'dayjs';

Expand Down Expand Up @@ -233,6 +233,23 @@ export async function getPublishInfoWithViewId (viewId: string) {
return Promise.reject(data);
}

export async function getPublishOutline (publishNamespace: string) {
const url = `/api/workspace/published-outline/${publishNamespace}`;

Check warning on line 237 in frontend/appflowy_web_app/src/application/services/js-services/http/http_api.ts

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/services/js-services/http/http_api.ts#L237

Added line #L237 was not covered by tests
const response = await axiosInstance?.get<{
code: number;
data?: View;
message: string;
}>(url);

const data = response?.data;

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

Check warning on line 248 in frontend/appflowy_web_app/src/application/services/js-services/http/http_api.ts

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/services/js-services/http/http_api.ts#L246-L248

Added lines #L246 - L248 were not covered by tests

return Promise.reject(data);
}

Check warning on line 251 in frontend/appflowy_web_app/src/application/services/js-services/http/http_api.ts

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/services/js-services/http/http_api.ts#L251

Added line #L251 was not covered by tests

export async function getPublishViewComments (viewId: string): Promise<GlobalComment[]> {
const url = `/api/workspace/published-info/${viewId}/comment`;
const response = await axiosInstance?.get<{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ export class AFClientService implements AFService {
return data;
}

async getPublishOutline (namespace: string) {
return APIService.getPublishOutline(namespace);
}

Check warning on line 169 in frontend/appflowy_web_app/src/application/services/js-services/index.ts

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/services/js-services/index.ts#L168-L169

Added lines #L168 - L169 were not covered by tests

async loginAuth (url: string) {
try {
console.log('loginAuth', url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
UploadTemplatePayload,
} from '@/application/template.type';
import * as Y from 'yjs';
import { DuplicatePublishView, FolderView, User, Workspace } from '@/application/types';
import { DuplicatePublishView, FolderView, User, View, Workspace } from '@/application/types';

export type AFService = PublishService;

Expand Down Expand Up @@ -37,6 +37,8 @@ export interface PublishService {
destroy: () => void;
}>;

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

getPublishViewGlobalComments: (viewId: string) => Promise<GlobalComment[]>;
createCommentOnPublishView: (viewId: string, content: string, replyCommentId?: string) => Promise<void>;
deleteCommentOnPublishView: (viewId: string, commentId: string) => Promise<void>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export class AFClientService implements AFService {
return Promise.reject('Method not implemented');
}

async getPublishOutline (_namespace: string) {
return Promise.reject('Method not implemented');
}

async getPublishViewMeta (_namespace: string, _publishName: string) {
return Promise.reject('Method not implemented');
}
Expand Down
24 changes: 23 additions & 1 deletion frontend/appflowy_web_app/src/application/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CollabType } from '@/application/collab.type';
import { CollabType, ViewLayout } from '@/application/collab.type';

export interface Workspace {
icon: string;
Expand Down Expand Up @@ -38,3 +38,25 @@ export interface DuplicatePublishView {
collabType: CollabType;
viewId: string;
}

export interface ViewIcon {
ty: number;
value: string;
}

export interface ViewExtra {
is_space: boolean;
space_created_at?: number;
space_icon?: string;
space_icon_color?: string;
space_permission?: number;
}

export interface View {
view_id: string;
name: string;
icon: ViewIcon | null;
layout: ViewLayout;
extra: ViewExtra | null;
children: View[];
}
57 changes: 33 additions & 24 deletions frontend/appflowy_web_app/src/assets/appflowy.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion frontend/appflowy_web_app/src/assets/chevron_down.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Divider } from '@mui/material';
import React from 'react';
import { ReactComponent as AppFlowyLogo } from '@/assets/appflowy.svg';

function AppFlowyPower ({
divider,
width,
}: {
divider?: boolean;
width?: number;
}) {
return (

Check warning on line 12 in frontend/appflowy_web_app/src/components/_shared/appflowy-power/AppFlowyPower.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/components/_shared/appflowy-power/AppFlowyPower.tsx#L12

Added line #L12 was not covered by tests
<div
style={{
backdropFilter: 'saturate(180%) blur(16px)',
width,
boxShadow: 'var(--footer) 0px -4px 14px 13px',
}}
className={'flex bg-bg-body sticky bottom-0 w-full flex-col items-center justify-center'}
>
{divider && <Divider className={'w-full my-0'} />}

<div

Check warning on line 23 in frontend/appflowy_web_app/src/components/_shared/appflowy-power/AppFlowyPower.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/components/_shared/appflowy-power/AppFlowyPower.tsx#L23

Added line #L23 was not covered by tests
onClick={() => {
window.open('https://appflowy.io', '_blank');
}}
style={{
width,
}}
className={
'flex w-full cursor-pointer gap-2 items-center justify-center py-4 text-sm text-text-title opacity-50'
}
>
Powered by
<AppFlowyLogo className={'w-[88px]'} />
</div>
</div>
);
}

export default AppFlowyPower;
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ interface Props {
open: boolean;
onClose: () => void;
placement?: PopperPlacementType;
PaperProps?: {
className?: string;
};

}

export const RichTooltip = ({ placement = 'top', open, onClose, content, children }: Props) => {
export const RichTooltip = ({ placement = 'top', open, onClose, content, children, PaperProps }: Props) => {
const [childNode, setChildNode] = React.useState<HTMLElement | null>(null);
const [, setTransitioning] = React.useState(false);

Expand Down Expand Up @@ -48,7 +52,8 @@ export const RichTooltip = ({ placement = 'top', open, onClose, content, childre
>
<Paper className={'bg-transparent shadow-none'}>
<ClickAwayListener onClickAway={onClose}>
<Paper className={'m-2 rounded-md border border-line-divider bg-bg-body overflow-hidden'}>
<Paper
className={'m-2 rounded-md border border-line-divider bg-bg-body overflow-hidden'} {...PaperProps}>

Check warning on line 56 in frontend/appflowy_web_app/src/components/_shared/popover/RichTooltip.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/components/_shared/popover/RichTooltip.tsx#L56

Added line #L56 was not covered by tests
<Box>{content}</Box>
</Paper>
</ClickAwayListener>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react';
import { Skeleton, Box } from '@mui/material';

export const BreadcrumbsSkeleton = () => {
return (
<Box display="flex" alignItems="center">
<Skeleton variant="text" width={60} height={20} />
<Skeleton variant="text" width={20} height={20} sx={{ mx: 1 }} />
<Skeleton variant="text" width={80} height={20} />
<Skeleton variant="text" width={20} height={20} sx={{ mx: 1 }} />
<Skeleton variant="text" width={100} height={20} />
</Box>
);
};

export default BreadcrumbsSkeleton;
Loading

0 comments on commit b4ead0f

Please sign in to comment.