Skip to content

Commit

Permalink
Fixes and improvements (#113)
Browse files Browse the repository at this point in the history
* fix: Drawer does not close

Passing `open` to the Styled component doesn't refresh the `transform` CSS property.

Resolves: Issue #106

* refactor: Removes metadata from the window title from the export filename

Transforms `(123) My super video - YouTube` into just `My super video`

* fix: Fixes deprecated error when using `fromString` and `isUuid`

Also fixes exporting markdown files with links without the video ID nor the `t=` query param.

* fix: Moves uuid to a separate file
  • Loading branch information
lemattma authored Feb 18, 2024
1 parent a3eb39e commit 487b34f
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 10 deletions.
1 change: 1 addition & 0 deletions packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"marked": "^1.1.0",
"md5": "^2.2.1",
"page-metadata-parser": "^1.1.4",
"uuid": "^8.3.2",
"uuidv4": "^6.0.0"
}
}
4 changes: 2 additions & 2 deletions packages/common/services/storage/BrowserStorage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isUuid } from 'uuidv4';
import { validate } from 'uuid';
import Storage from './Storage';
import { addNoteToList, addTagToList } from '../../utils';

Expand All @@ -11,7 +11,7 @@ export default class BrowserStorage extends Storage {
_getPages() {
return this.storage.get().then(pages => {
return Object.keys(pages)
.filter(key => isUuid(key))
.filter(key => validate(key))
.map(key => pages[key]);
});
}
Expand Down
5 changes: 3 additions & 2 deletions packages/common/store/page.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { action, thunk } from 'easy-peasy';
import { getMetadata } from 'page-metadata-parser';
import { fromString } from 'uuidv4';
import { v5 } from 'uuid';
import { storage as StorageService } from '../services';
import { generatePageId, addTagToList, addNoteToList } from '../utils';
import uuidNamespace from '../utils/uuid-namespace';

export const defaultPage = {
id: '',
Expand Down Expand Up @@ -45,7 +46,7 @@ const pageModel = {
}),
saveNote: thunk(async (actions, note, { getState, getStoreState }) => {
const { url } = getStoreState().app;
const id = note.id || fromString(note.content + note.timestamp);
const id = note.id || v5(note.content + note.timestamp, uuidNamespace);
let { data: page } = getState();

if (!page.id) {
Expand Down
7 changes: 4 additions & 3 deletions packages/common/utils/generatePageId.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { fromString } from 'uuidv4';
import { v5 } from 'uuid';
import compose from 'compose-function';
import videoUrlParser from 'js-video-url-parser';
import { PROVIDER_YOUTUBE } from '../constants';
import uuidNamespace from './uuid-namespace';

const getUrlWithoutHash = url => {
const parsedUrl = new URL(url);
Expand All @@ -20,8 +21,8 @@ export default url => {
getUrlWithoutHash
)(url);
if (provider === PROVIDER_YOUTUBE) {
return fromString(`${provider}-${id}`);
return v5(`${provider}-${id}`, uuidNamespace);
}

return fromString(urlWithoutHash);
return v5(urlWithoutHash, uuidNamespace);
};
1 change: 1 addition & 0 deletions packages/common/utils/uuid-namespace.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'e1433c8f-bc34-431d-99b1-2a78abdd7f35';
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,13 @@ const Toolbar = () => {

const handleExportMarkdown = () => {
const data = MarkdownService.pagesToMarkdown([{ meta, notes }]);
return FileService.exportMarkdownFile(data, `yinote_${meta.title}.md`);

// Removing notifications count and " - Youtube" at the end
const fileName = meta.title
.replace(/^\(.*\) /g, '')
.replace(/ - YouTube$/g, '');

return FileService.exportMarkdownFile(data, `${fileName}.md`);
};

const handleOpenPage = () => {
Expand Down
8 changes: 7 additions & 1 deletion packages/extension/src/ui/containers/App/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,13 @@ const App = () => {
}, [getPlayer, history, open, pathname]);

return (
<StyledDrawer open={open} className={open && 'panel-shadow'}>
<StyledDrawer
// fixes toggling the drawer open and closed.
// For some reason passing `open` doesn't update the component's styles
style={{ transform: open ? 'translateX(0)' : 'translateX(100%)' }}
open={open}
className={open && 'panel-shadow'}
>
<Grid container>
<Header />
<StyledViewWrapper>
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16679,7 +16679,7 @@ uuid@3.4.0, uuid@^3.0.0, uuid@^3.0.1, uuid@^3.3.2, uuid@^3.4.0:
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee"
integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==

uuid@8.3.2:
uuid@8.3.2, uuid@^8.3.2:
version "8.3.2"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2"
integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==
Expand Down

0 comments on commit 487b34f

Please sign in to comment.