Skip to content

Commit

Permalink
feat: use yarn instead of npm; add prettierrc
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoomen committed May 8, 2022
1 parent 184a6dd commit b0e0c50
Show file tree
Hide file tree
Showing 25 changed files with 10,920 additions and 34,648 deletions.
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"printWidth": 100,
"singleQuote": true,
"trailingComma": "all"
}
34,205 changes: 0 additions & 34,205 deletions package-lock.json

This file was deleted.

11 changes: 9 additions & 2 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use tauri::Manager;
use tauri::AppHandle;
use tauri::{Manager, AppHandle, Menu, Submenu, MenuItem, CustomMenuItem};
use std::fs::File;
use std::io::Read;
use std::path::Path;
Expand Down Expand Up @@ -28,7 +27,15 @@ fn save_library(app: AppHandle, library_state: String) {
}

fn main() {
let quit = CustomMenuItem::new("quit".to_string(), "Quit");
let close = CustomMenuItem::new("close".to_string(), "Close");
let submenu = Submenu::new("File", Menu::new().add_item(quit).add_item(close));
let menu = Menu::new()
.add_native_item(MenuItem::Copy)
.add_submenu(submenu);

tauri::Builder::default()
.menu(menu)
.setup(|app| {
let handle = app.handle();
config::init(handle);
Expand Down
12 changes: 6 additions & 6 deletions src/components/App/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { useSelector } from "react-redux";
import Library from "../Library";
import Paper from "../Paper";
import { useSelector } from 'react-redux';
import Library from '../Library';
import Paper from '../Paper';

function App() {
const currentRoute = useSelector((state) => state.router.current);
switch (currentRoute.name) {
case "library":
case 'library':
return <Library />;

case "paper":
case 'paper':
return <Paper paperId={currentRoute.args.paperId} />;

default:
console.error("Unknown route", currentRoute);
console.error('Unknown route', currentRoute);
break;
}
}
Expand Down
25 changes: 12 additions & 13 deletions src/components/InlineEdit/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from "react";
import PropTypes from "prop-types";
import Tooltip from "rc-tooltip";
import { KEY } from "../../constants";
import styles from "./styles.module.css";
import classNames from "classnames";
import React from 'react';
import PropTypes from 'prop-types';
import Tooltip from 'rc-tooltip';
import { KEY } from '../../constants';
import styles from './styles.module.css';
import classNames from 'classnames';

class InlineEdit extends React.Component {
input = React.createRef();
Expand Down Expand Up @@ -64,11 +64,10 @@ class InlineEdit extends React.Component {
* for the input element.
*/
getInputWidth = () => {
var span = document.createElement("span");
span.classList.add(styles["inline-edit__tmp-element"]);
const value =
this.state.value !== null ? this.state.value : this.props.defaultValue;
span.innerHTML = value.replaceAll(" ", "&nbsp;");
var span = document.createElement('span');
span.classList.add(styles['inline-edit__tmp-element']);
const value = this.state.value !== null ? this.state.value : this.props.defaultValue;
span.innerHTML = value.replaceAll(' ', '&nbsp;');
document.body.appendChild(span);
const width = Math.round(span.getBoundingClientRect().width) + 2;
document.body.removeChild(span);
Expand All @@ -82,7 +81,7 @@ class InlineEdit extends React.Component {
style={{ width: this.getInputWidth() }}
ref={this.input}
type="text"
className={styles["inline-edit__input"]}
className={styles['inline-edit__input']}
defaultValue={this.props.defaultValue}
onChange={this.onChange}
onBlur={this.onBlur}
Expand All @@ -95,7 +94,7 @@ class InlineEdit extends React.Component {
return (
<Tooltip placement="top" overlay="double click to edit">
<span
className={classNames("ellipsis", styles["inline-edit__text"])}
className={classNames('ellipsis', styles['inline-edit__text'])}
onDoubleClick={() => this.toggleEdit()}
>
{this.props.defaultValue}
Expand Down
55 changes: 24 additions & 31 deletions src/components/Library/components/FolderListItem/index.js
Original file line number Diff line number Diff line change
@@ -1,61 +1,54 @@
import classNames from "classnames";
import PropTypes from "prop-types";
import InlineEdit from "../../../InlineEdit";
import { ReactComponent as FolderIcon } from "./../../../../assets/icons/folder.svg";
import {
deleteFolder,
updateFolderName,
} from "./../../../../reducers/library/librarySlice";
import { store } from "./../../../../store";
import styles from "./styles.module.css";
import { ReactComponent as TrashcanIcon } from "./../../../../assets/icons/trashcan.svg";
import { confirm } from "@tauri-apps/api/dialog";
import classNames from 'classnames';
import PropTypes from 'prop-types';
import InlineEdit from '../../../InlineEdit';
import { ReactComponent as FolderIcon } from './../../../../assets/icons/folder.svg';
import { deleteFolder, updateFolderName } from './../../../../reducers/library/librarySlice';
import { store } from './../../../../store';
import styles from './styles.module.css';
import { ReactComponent as TrashcanIcon } from './../../../../assets/icons/trashcan.svg';
import { confirm } from '@tauri-apps/api/dialog';

function FolderListItem(props) {
const onEditDone = (name) => {
store.dispatch(
updateFolderName({
id: props.folder.id,
name,
})
}),
);
};

const onClick = (e) => {
// Do not trigger the onClick when we click on a button.
if (e.target.nodeName === "BUTTON") return false;
if (e.target.nodeName === 'BUTTON') return false;

props.onClick();
};

const onDeleteFolder = () => {
confirm(
`Are you sure you want to delete the folder "${props.folder.name}" ?`
).then((shouldDelete) => {
if (shouldDelete) {
store.dispatch(deleteFolder(props.folder.id));
props.onDelete();
}
});
confirm(`Are you sure you want to delete the folder "${props.folder.name}" ?`).then(
(shouldDelete) => {
if (shouldDelete) {
store.dispatch(deleteFolder(props.folder.id));
props.onDelete();
}
},
);
};

return (
<div
className={classNames(styles["folder-list-item__container"], {
[styles["folder-list-item__active"]]: props.isActive,
className={classNames(styles['folder-list-item__container'], {
[styles['folder-list-item__active']]: props.isActive,
})}
onClick={onClick}
>
<FolderIcon className={styles["folder-list-item__container__icon"]} />
<span className={styles["folder-list-item__name"]}>
<FolderIcon className={styles['folder-list-item__container__icon']} />
<span className={styles['folder-list-item__name']}>
<InlineEdit defaultValue={props.folder.name} onEditDone={onEditDone} />
</span>
<button
className={classNames(
"btn",
"btn-icon",
styles["folder-list-item__delete-btn"]
)}
className={classNames('btn', 'btn-icon', styles['folder-list-item__delete-btn'])}
onClick={onDeleteFolder}
>
<TrashcanIcon />
Expand Down
44 changes: 20 additions & 24 deletions src/components/Library/components/PaperListItem/index.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,39 @@
import React from "react";
import PropTypes from "prop-types";
import styles from "./styles.module.css";
import Paper from "../../../Paper";
import classNames from "classnames";
import { deletePaper } from "./../../../../reducers/library/librarySlice";
import { ReactComponent as TrashcanIcon } from "./../../../../assets/icons/trashcan.svg";
import { store } from "./../../../../store";
import { confirm } from "@tauri-apps/api/dialog";
import React from 'react';
import PropTypes from 'prop-types';
import styles from './styles.module.css';
import Paper from '../../../Paper';
import classNames from 'classnames';
import { deletePaper } from './../../../../reducers/library/librarySlice';
import { ReactComponent as TrashcanIcon } from './../../../../assets/icons/trashcan.svg';
import { store } from './../../../../store';
import { confirm } from '@tauri-apps/api/dialog';

function PaperListItem(props) {
const onDeletePaper = () => {
confirm(
`Are you sure you want to delete the paper "${props.paper.name}" ?`
).then((shouldDelete) => {
if (shouldDelete) {
store.dispatch(deletePaper(props.paper.id));
}
});
confirm(`Are you sure you want to delete the paper "${props.paper.name}" ?`).then(
(shouldDelete) => {
if (shouldDelete) {
store.dispatch(deletePaper(props.paper.id));
}
},
);
};

const onClick = (e) => {
// Do not trigger the onClick when we click on a button.
if (e.target.nodeName === "BUTTON") return false;
if (e.target.nodeName === 'BUTTON') return false;

props.onClick();
};

return (
<div className={styles["paper-list-item__container"]} onClick={onClick}>
<div className={styles['paper-list-item__container']} onClick={onClick}>
<Paper paperId={props.paper.id} readonly />
<div className={classNames("ellipsis", styles["paper-list-item__name"])}>
<div className={classNames('ellipsis', styles['paper-list-item__name'])}>
{props.paper.name}
</div>
<button
className={classNames(
"btn",
"btn-icon",
styles["paper-list-item__delete-btn"]
)}
className={classNames('btn', 'btn-icon', styles['paper-list-item__delete-btn'])}
onClick={onDeletePaper}
>
<TrashcanIcon />
Expand Down
Loading

0 comments on commit b0e0c50

Please sign in to comment.