Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix timeline feature error when base url is set #402

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
14 changes: 10 additions & 4 deletions packages/docprovider/src/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Props = {
contentType: string;
format: string;
};
const DOCUMENT_TIMELINE_URL = 'api/collaboration/timeline';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have it here and here. Should it be in one place?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I will fix that. Thanks for the feedback !


export const TimelineSliderComponent: React.FC<Props> = ({
apiURL,
Expand Down Expand Up @@ -147,16 +148,21 @@ export const TimelineSliderComponent: React.FC<Props> = ({
function determineAction(currentTimestamp: number): 'undo' | 'redo' {
return currentTimestamp < currentTimestampIndex ? 'undo' : 'redo';
}

function extractFilenameFromURL(url: string): string {
try {
const parsedURL = new URL(url);
const pathname = parsedURL.pathname;
const segments = pathname.split('/');

return segments.slice(4 - segments.length).join('/');
const apiIndex = pathname.indexOf(DOCUMENT_TIMELINE_URL);
if (apiIndex === -1) {
throw new Error(
`API segment "${DOCUMENT_TIMELINE_URL}" not found in URL.`
);
}

return pathname.slice(apiIndex + DOCUMENT_TIMELINE_URL.length);
} catch (error) {
console.error('Invalid URL:', error);
console.error('Invalid URL or unable to extract filename:', error);
return '';
}
}
Expand Down
Loading