Compare commits

...

2 Commits

Binary file not shown.

File diff suppressed because it is too large Load Diff

@ -6,6 +6,7 @@
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"date-fns": "^2.9.0",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-markdown": "^4.3.1",

@ -5,13 +5,18 @@
background-color: #282c34;
color: white;
width: 100%;
}
.SearchArea {
padding: 10px;
background-color: lightgray;
}
.NoteArea {
display: flex;
flex-direction: column;
flex-grow: 1;
padding: 0 10px;
}
.NoteArea.Vertical {

@ -1,10 +1,10 @@
import React, { PureComponent } from "react";
import NoteList from "./components/NoteList";
import NoteList from "./components/NoteList/NoteList";
import NoteContent from "./components/NoteContent";
import Omnibar from "./components/Omnibar";
import { createNote, getNotes } from "./state";
import { createNote, getNotes, upsertNote } from "./state";
import "./App.css";
@ -12,18 +12,21 @@ class App extends PureComponent {
state = { ...getNotes(), selectedNote: null };
handleSearch = text => {
const { notes } = this.state;
const newNote = createNote({
title: text,
content: "this is a new note",
tags: []
});
this.setState({
notes: notes.concat(newNote)
notes: getNotes().notes.filter(
n =>
n.title.includes(text) ||
n.tags.find(x => x === text) ||
n.content.includes(text)
)
});
};
handleCreate = title => {
const newNote = upsertNote(title);
this.setState({ ...getNotes(), selectedNote: newNote });
};
handleSelectNote = noteTitle => {
const { notes } = this.state;
const sn = notes.filter(({ title }) => title === noteTitle);
@ -69,8 +72,11 @@ class App extends PureComponent {
return (
<div className="App">
<section>
<Omnibar onEnter={this.handleSearch} />
<section className="SearchArea">
<Omnibar
onEnter={this.handleCreate}
onSearch={this.handleSearch}
/>
{/* add settings button here */}
</section>
<section className="NoteArea">

@ -1,37 +0,0 @@
import React, { useState } from "react";
import ReactMarkdown from "react-markdown";
import { noop } from "../state";
import "./EditableNoteArea.css";
export default function EditableNoteArea({ content = null, onSave = noop }) {
const [editMode, setEditMode] = useState(false);
const [newContent, setNewContent] = useState(content);
const toggleEditMode = () => {
setEditMode(!editMode);
if (editMode && newContent) {
onSave(newContent, content);
}
};
const updateContent = ({ target }) =>
setNewContent(target.value || newContent);
return (
<section
className="EditableNoteArea"
onClick={toggleEditMode}
// onDoubleClick={toggleEditMode}
>
{editMode ? (
<textarea
defaultValue={content}
onChange={updateContent}
></textarea>
) : (
<ReactMarkdown source={content} />
)}
</section>
);
}

@ -0,0 +1,26 @@
import React, { useState } from "react";
import ReactMarkdown from "react-markdown";
import { noop } from "../../state";
import "./EditableNoteArea.css";
export default function EditableNoteArea({
content = null,
onSave = noop,
preview = false
}) {
const [newContent, setNewContent] = useState(content);
const updateContent = ({ target }) =>
setNewContent(target.value || newContent);
return (
<section className="EditableNoteArea">
{!preview ? (
<textarea defaultValue={content} onChange={updateContent} />
) : (
<ReactMarkdown source={content} />
)}
</section>
);
}

@ -8,7 +8,7 @@
padding: 0 10px 15px 10px;
}
.NoteContent h2 {
margin: 10px 0;
padding: 0;
.NoteContent .controls {
padding: 10px;
display: flex;
}

@ -1,17 +1,42 @@
import React from "react";
import EditableNoteArea from "./EditableNoteArea";
import "./NoteContent.css";
import React, { useState } from "react";
import { noop } from "../state";
import EditableNoteArea from "./EditableNoteArea/EditableNoteArea";
import "./NoteContent.css";
export default function NoteContent({ note = null, onSave = noop }) {
const [renderMarkdown, setRenderMarkdown] = useState(false);
const { content, title } = note || {};
return (
<div className="NoteContent">
<header>
<h2>{title}</h2>
<header className="controls">
<Checkbox
label="Preview Markdown"
onChange={checked => setRenderMarkdown(checked)}
/>
</header>
<EditableNoteArea content={content} onSave={onSave} />
<EditableNoteArea
content={content}
onSave={onSave}
preview={renderMarkdown}
/>
</div>
);
}
const Checkbox = ({
className = "",
onChange = noop,
label = "checkbox",
defaultChecked = false
}) => (
<div className={className}>
<label>{label}:</label>
<input
type="checkbox"
defaultChecked={defaultChecked}
onChange={({ target }) => onChange(target.checked)}
/>
</div>
);

@ -1,59 +0,0 @@
.NoteList {
height: 25%;
list-style-type: none;
border-color: black;
border-width: 2px;
border-style: groove;
margin: 0;
padding: 0;
text-align: left;
overflow-y: scroll;
min-height: 75px;
}
.NoteList li:hover {
cursor: pointer;
}
.NoteList li:nth-child(even) {
background-color: #222222;
}
.NoteList .NoteListItem {
padding: 0 10px;
}
.NoteList .NoteListItem h2 {
font-size: 1rem;
margin: 0;
}
.NoteList .NoteListItem .TagList {
display: flex;
align-items: baseline;
width: 100%;
}
.NoteList .NoteListItem .TagList input {
width: 100%;
}
.NoteList .NoteListItem .TagList span {
font-size: 10pt;
color: #aaa;
}
.NoteList .NoteListItem .TagList ul {
list-style-type: none;
margin: 0;
padding: 10px 0;
font-size: 8pt;
display: flex;
flex-direction: row;
}
.NoteList .NoteListItem .TagList li {
background-color: #333;
padding: 2px 7px;
border-radius: 10px;
}

@ -1,84 +0,0 @@
import React, { Fragment, useState } from "react";
import { noop } from "../state.js";
import "./NoteList.css";
export default function NoteList({
notes = [],
onSelect = noop,
onTagUpdate = noop
}) {
return (
<ul className="NoteList">
{notes.map(n => (
<li key={n.title}>
<a onClick={() => onSelect(n.title)}>
<NoteListItem
title={n.title}
tags={n.tags}
content={n.content}
onTagUpdate={onTagUpdate}
/>
</a>
</li>
))}
{notes.length === 0 && (
<li>Click the text box above to create a note.</li>
)}
</ul>
);
}
const NoteListItem = ({
title = "empty note",
tags = [],
content = "",
onTagUpdate = noop
}) => (
<div className="NoteListItem">
<h2>{title}</h2>
<TagList tags={tags} onTagUpdate={onTagUpdate} />
</div>
);
const TagList = ({ tags = [], onTagUpdate = noop }) => {
const getTags = () => tags.join(",");
const [state, setState] = useState({
editMode: false,
editTags: getTags()
});
const { editMode, editTags } = state;
const toggleEditMode = () => {
setState({ editMode: !editMode });
if (editMode) {
onTagUpdate(editTags.split(","));
}
};
const updateTags = ({ target }) =>
setState({ editMode: editMode, editTags: target.value });
return (
<span className="TagList" onDoubleClick={toggleEditMode}>
{editMode ? (
<input
type="text"
defaultValue={getTags()}
onChange={updateTags}
/>
) : (
<Fragment>
<span>tags</span>
<ul>
{tags.map(t => (
<li key={t}> {t} </li>
))}
</ul>
</Fragment>
)}
</span>
);
};

@ -0,0 +1,57 @@
.NoteList {
height: 25%;
list-style-type: none;
border-color: black;
border-width: 2px;
border-style: groove;
border-top-style: none;
margin: 0;
padding: 0;
text-align: left;
overflow-y: scroll;
min-height: 75px;
}
.NoteList li:hover {
cursor: pointer;
}
.NoteList li:nth-child(even) {
background-color: #222222;
}
.NoteList .NoteListItem {
padding: 0 10px;
display: flex;
justify-content: space-between;
font-size: 9pt;
}
.NoteListItem .attributes {
display: flex;
justify-content: right;
align-items: center;
flex-basis: min-content;
max-width: 35%;
}
.NoteListItem .attributes .lastModified {
padding: 0 5px;
white-space: nowrap;
}
.NoteList .NoteListItem h2 {
flex: 0 1 min-content;
white-space: pre;
font-size: 1rem;
margin: auto;
}
.NoteListItem .preview {
overflow: hidden;
white-space: nowrap;
color: #777;
padding: 0 5px 0 10px;
text-overflow: ellipsis;
flex: 1 2 min-content;
}

@ -0,0 +1,52 @@
import React from "react";
import { formatRelative } from "date-fns";
import { noop } from "../../state.js";
import TagList from "../TagList/TagList";
import "./NoteList.css";
export default function NoteList({
notes = [],
onSelect = noop,
onTagUpdate = noop
}) {
return (
<ul className="NoteList">
{notes.map(n => (
<li key={n.title}>
<NoteListItem
{...n}
onSelect={onSelect}
onTagUpdate={onTagUpdate}
/>
</li>
))}
{notes.length === 0 && (
<li>Click the text box above to create a note.</li>
)}
</ul>
);
}
const NoteListItem = ({
content,
title,
tags,
lastModified,
onSelect,
onTagUpdate
}) => {
return (
<div className="NoteListItem" onClick={() => onSelect(title)}>
<h2>{title}</h2>
<p className="preview">-- {content}</p>
<span className="attributes">
<TagList tags={tags} onTagUpdate={onTagUpdate} />
<span className="lastModified">
{formatRelative(new Date(lastModified), new Date())}
</span>
</span>
</div>
);
};

@ -6,4 +6,5 @@
.Omnibar input {
padding: 2px 10px;
flex-grow: 1;
border-radius: 5px;
}

@ -1,22 +1,20 @@
import React, { useState } from "react";
import { noop } from "../state.js";
import { noop, enterKeyPressed } from "../state.js";
import "./Omnibar.css";
export default function Omnibar({ onSearch = noop, onEnter = noop }) {
const [text, setText] = useState("");
const onEnterFunc = ({ charCode }) => {
if (charCode === 13) onEnter && onEnter(text);
};
const onTextChange = text => setText(text) || onSearch(text);
return (
<div className="Omnibar">
<input
type="text"
placeholder='Type here to search. Type here and press "enter" to create a note.'
onChange={({ target }) => setText(target.value)}
onKeyPress={onEnterFunc}
onChange={({ target }) => onTextChange(target.value)}
onKeyPress={enterKeyPressed(() => onEnter(text))}
/>
</div>
);

@ -0,0 +1,32 @@
.TagList {
display: flex;
align-items: baseline;
overflow-x: scroll;
}
.TagList input {
max-width: 100%;
min-width: 75px;
}
.TagList span {
color: #aaa;
}
.TagList ul {
list-style-type: none;
margin: 0;
padding: 10px 0;
font-size: 8pt;
display: flex;
flex-direction: row;
}
.TagList li {
margin: 0 2px;
padding: 2px 7px;
border-radius: 10px;
background-color: #ccc !important;
color: #333 !important;
white-space: nowrap;
}

@ -0,0 +1,42 @@
import React, { Fragment, useState } from "react";
import { noop, enterKeyPressed } from "../../state.js";
import "./TagList.css";
export default function TagList({ tags = [], onTagUpdate = noop }) {
const getTags = () => tags.join(",");
const [editMode, setEditMode] = useState(false);
const [editTags, setEditTags] = useState(getTags());
const toggleEditMode = () => {
setEditMode(!editMode);
if (editMode) {
onTagUpdate(editTags.split(",").map(x => x.trim()));
}
};
const updateTags = ({ target }) => setEditTags(target.value);
return (
<span className="TagList" onDoubleClick={toggleEditMode}>
{editMode ? (
<input
type="text"
style={{ width: `${editTags.length - 2}ch` }}
defaultValue={getTags()}
onChange={updateTags}
onKeyPress={enterKeyPressed(toggleEditMode)}
onBlur={() => editMode && toggleEditMode()}
/>
) : (
<Fragment>
{tags.length <= 0 && <span>tags</span>}
<ul>
{tags.map(t => (
<li key={t}>{t}</li>
))}
</ul>
</Fragment>
)}
</span>
);
}

@ -15,7 +15,7 @@ code {
#root {
width: 100vw;
height: 100vh;
min-height: 100vh;
display: flex;
justify-content: center;
}

@ -1,7 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 841.9 595.3">
<g fill="#61DAFB">
<path d="M666.3 296.5c0-32.5-40.7-63.3-103.1-82.4 14.4-63.6 8-114.2-20.2-130.4-6.5-3.8-14.1-5.6-22.4-5.6v22.3c4.6 0 8.3.9 11.4 2.6 13.6 7.8 19.5 37.5 14.9 75.7-1.1 9.4-2.9 19.3-5.1 29.4-19.6-4.8-41-8.5-63.5-10.9-13.5-18.5-27.5-35.3-41.6-50 32.6-30.3 63.2-46.9 84-46.9V78c-27.5 0-63.5 19.6-99.9 53.6-36.4-33.8-72.4-53.2-99.9-53.2v22.3c20.7 0 51.4 16.5 84 46.6-14 14.7-28 31.4-41.3 49.9-22.6 2.4-44 6.1-63.6 11-2.3-10-4-19.7-5.2-29-4.7-38.2 1.1-67.9 14.6-75.8 3-1.8 6.9-2.6 11.5-2.6V78.5c-8.4 0-16 1.8-22.6 5.6-28.1 16.2-34.4 66.7-19.9 130.1-62.2 19.2-102.7 49.9-102.7 82.3 0 32.5 40.7 63.3 103.1 82.4-14.4 63.6-8 114.2 20.2 130.4 6.5 3.8 14.1 5.6 22.5 5.6 27.5 0 63.5-19.6 99.9-53.6 36.4 33.8 72.4 53.2 99.9 53.2 8.4 0 16-1.8 22.6-5.6 28.1-16.2 34.4-66.7 19.9-130.1 62-19.1 102.5-49.9 102.5-82.3zm-130.2-66.7c-3.7 12.9-8.3 26.2-13.5 39.5-4.1-8-8.4-16-13.1-24-4.6-8-9.5-15.8-14.4-23.4 14.2 2.1 27.9 4.7 41 7.9zm-45.8 106.5c-7.8 13.5-15.8 26.3-24.1 38.2-14.9 1.3-30 2-45.2 2-15.1 0-30.2-.7-45-1.9-8.3-11.9-16.4-24.6-24.2-38-7.6-13.1-14.5-26.4-20.8-39.8 6.2-13.4 13.2-26.8 20.7-39.9 7.8-13.5 15.8-26.3 24.1-38.2 14.9-1.3 30-2 45.2-2 15.1 0 30.2.7 45 1.9 8.3 11.9 16.4 24.6 24.2 38 7.6 13.1 14.5 26.4 20.8 39.8-6.3 13.4-13.2 26.8-20.7 39.9zm32.3-13c5.4 13.4 10 26.8 13.8 39.8-13.1 3.2-26.9 5.9-41.2 8 4.9-7.7 9.8-15.6 14.4-23.7 4.6-8 8.9-16.1 13-24.1zM421.2 430c-9.3-9.6-18.6-20.3-27.8-32 9 .4 18.2.7 27.5.7 9.4 0 18.7-.2 27.8-.7-9 11.7-18.3 22.4-27.5 32zm-74.4-58.9c-14.2-2.1-27.9-4.7-41-7.9 3.7-12.9 8.3-26.2 13.5-39.5 4.1 8 8.4 16 13.1 24 4.7 8 9.5 15.8 14.4 23.4zM420.7 163c9.3 9.6 18.6 20.3 27.8 32-9-.4-18.2-.7-27.5-.7-9.4 0-18.7.2-27.8.7 9-11.7 18.3-22.4 27.5-32zm-74 58.9c-4.9 7.7-9.8 15.6-14.4 23.7-4.6 8-8.9 16-13 24-5.4-13.4-10-26.8-13.8-39.8 13.1-3.1 26.9-5.8 41.2-7.9zm-90.5 125.2c-35.4-15.1-58.3-34.9-58.3-50.6 0-15.7 22.9-35.6 58.3-50.6 8.6-3.7 18-7 27.7-10.1 5.7 19.6 13.2 40 22.5 60.9-9.2 20.8-16.6 41.1-22.2 60.6-9.9-3.1-19.3-6.5-28-10.2zM310 490c-13.6-7.8-19.5-37.5-14.9-75.7 1.1-9.4 2.9-19.3 5.1-29.4 19.6 4.8 41 8.5 63.5 10.9 13.5 18.5 27.5 35.3 41.6 50-32.6 30.3-63.2 46.9-84 46.9-4.5-.1-8.3-1-11.3-2.7zm237.2-76.2c4.7 38.2-1.1 67.9-14.6 75.8-3 1.8-6.9 2.6-11.5 2.6-20.7 0-51.4-16.5-84-46.6 14-14.7 28-31.4 41.3-49.9 22.6-2.4 44-6.1 63.6-11 2.3 10.1 4.1 19.8 5.2 29.1zm38.5-66.7c-8.6 3.7-18 7-27.7 10.1-5.7-19.6-13.2-40-22.5-60.9 9.2-20.8 16.6-41.1 22.2-60.6 9.9 3.1 19.3 6.5 28.1 10.2 35.4 15.1 58.3 34.9 58.3 50.6-.1 15.7-23 35.6-58.4 50.6zM320.8 78.4z"/>
<circle cx="420.9" cy="296.5" r="45.7"/>
<path d="M520.5 78.1z"/>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 2.6 KiB

@ -1,5 +1,6 @@
export const noop = () => {};
export const enterKeyPressed = (cb = noop) => ({ charCode }) =>
charCode === 13 && cb();
export const createNote = ({ title = null, content = "", tags = [] }) => {
if (title === null) {
throw new Error("cannot create a note with a null title");
@ -16,10 +17,17 @@ export const createNote = ({ title = null, content = "", tags = [] }) => {
};
};
export const getNotes = window.LoadNotes || (() => defaultNotes);
export const upsertNote = () => {};
export const getNotes = window.LoadNotes || (() => ({ ...notesStore }));
export const upsertNote = newTitle => {
const newNote = createNote({
title: newTitle
});
notesStore.notes = notesStore.notes.concat(newNote);
return newNote;
};
const defaultNotes = {
const notesStore = {
error: null,
notes: [
createNote({
@ -41,17 +49,17 @@ const defaultNotes = {
tags: ["ass"]
}),
createNote({
title: "ass 3",
title: "too many asses",
content: "this is an ass note",
tags: ["ass"]
}),
createNote({
title: "ass 4",
title: "this note doesn't have the word ass in the content",
content: "this is an ass note",
tags: ["ass"]
}),
createNote({
title: "ass 5",
title: "this is not an ass 5",
content: "this is an ass note",
tags: ["not ass"]
})

@ -3380,6 +3380,11 @@ data-urls@^1.0.0, data-urls@^1.1.0:
whatwg-mimetype "^2.2.0"
whatwg-url "^7.0.0"
date-fns@^2.9.0:
version "2.9.0"
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.9.0.tgz#d0b175a5c37ed5f17b97e2272bbc1fa5aec677d2"
integrity sha512-khbFLu/MlzLjEzy9Gh8oY1hNt/Dvxw3J6Rbc28cVoYWQaC1S3YI4xwkF9ZWcjDLscbZlY9hISMr66RFzZagLsA==
debug@2.6.9, debug@^2.2.0, debug@^2.3.3, debug@^2.6.0, debug@^2.6.8, debug@^2.6.9:
version "2.6.9"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"

@ -74,6 +74,9 @@ func (as *AppState) LoadNotes() LoadNoteResult {
notes := []Note{}
if err := filepath.Walk(as.Settings.Directory, func(path string, info os.FileInfo, err error) error {
if info == nil {
return nil
}
fileExt := filepath.Ext(info.Name())
if fileExt == "md" || fileExt == "txt" || fileExt == "utf" || fileExt == "todo" {
content, err := ioutil.ReadFile(path)

@ -5,8 +5,12 @@ FRONTEND_DIR := ./frontend/build
FRONTEND_DEPS := ./frontend/node_modules
PLATFORMS = linux darwin windows
OUTPUT_DIR := .bin
.SHELLARGS = -eou pipefail
build-all: $(OUTPUT_DIR)/linux/xnv $(OUTPUT_DIR)/windows/xnv.exe
build-all: $(OUTPUT_DIR)/linux/xnv $(OUTPUT_DIR)/windows/xnv.exe $(OUTPUT_DIR)/darwin/xnv
linux: $(OUTPUT_DIR)/linux/xnv
darwin: $(OUTPUT_DIR)/darwin/xnv
windows: $(OUTPUT_DIR)/windows/xnv.exe
clean:
@rm -rf ./$(OUTPUT_DIR) ./pkged.go ./xnv $(FRONTEND_DIR)
@ -14,7 +18,7 @@ clean:
clobber: clean
@rm -rf $(FRONTEND_DEPS)
.PHONY: clean clobber build
.PHONY: clean clobber build-all darwin linux windows
$(OUTPUT_DIR)/xnv: pkged.go $(OUTPUT_DIR)
go build -ldflags "-r ." -o $(OUTPUT_DIR)/xnv
@ -52,16 +56,11 @@ $(OUTPUT_DIR)/linux/xnv: pkged.go $(OUTPUT_DIR)/linux
7zr e -y -o'$(OUTPUT_DIR)/linux/' -i'!./bin/*.so' \
$(OUTPUT_DIR)/linux/ultralight-sdk-latest-linux-x64.7z
ultralight/linux:
mkdir -p $(OUTPUT_DIR)/linux/ultralight
curl https://ultralight-sdk.sfo2.cdn.digitaloceanspaces.com/ultralight-sdk-latest-linux-x64.7z \
-o $(OUTPUT_DIR)/linux/ultralight-sdk-latest-linux-x64.7z && \
7zr e -o'$(OUTPUT_DIR)/linux/ultralight' -i'!./bin/*.so' \
$(OUTPUT_DIR)/linux/ultralight-sdk-latest-linux-x64.7z
ultralight/darwin:
mkdir -p $(OUTPUT_DIR)/darwin/ultralight
$(OUTPUT_DIR)/darwin/xnv: pkged.go $(OUTPUT_DIR)/darwin
CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 go build -v -ldflags="-r ." -o $(OUTPUT_DIR)/darwin/$(APP)
curl https://ultralight-sdk.sfo2.cdn.digitaloceanspaces.com/ultralight-sdk-latest-mac-x64.7z \
-o $(OUTPUT_DIR)/darwin/ultralight-sdk-latest-mac-x64.7z && \
7zr e -o'$(OUTPUT_DIR)/darwin/ultralight' -i'!./bin/*.so' \
$(OUTPUT_DIR)/darwin/ultralight-sdk-latest-mac-x64.7z
7zr e -y -o'$(OUTPUT_DIR)/darwin/' -i'!./bin/*.dylib' \
$(OUTPUT_DIR)/darwin/ultralight-sdk-latest-mac-x64.7z
@echo 'to run do:'
@echo 'LD_LIBRARY_PATH=$$PWD/.bin/darwin'
Loading…
Cancel
Save