Making Share Target functional
This commit is contained in:
@ -65,7 +65,7 @@ export class Footer extends Component<{}, { synced: boolean, syncing: boolean }>
|
||||
Welcome <b>{Notes.name}</b>
|
||||
</span>
|
||||
<span style="color: lightgrey;">
|
||||
v1.1
|
||||
v1.2
|
||||
</span>
|
||||
</footer>
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
import { h, Component } from "preact";
|
||||
import Notes from "../notes";
|
||||
|
||||
import "./notifications.scss"
|
||||
import Notifications, { MessageType } from "../notifications";
|
||||
@ -37,11 +36,11 @@ export default class NotificationsComponent extends Component<{}, {
|
||||
this.setState({ notifications: n });
|
||||
setTimeout(() => {
|
||||
this.removeNot(not);
|
||||
}, 3000);
|
||||
}, 20000);
|
||||
}
|
||||
|
||||
removeNot(not: { message: string }) {
|
||||
let n = this.state.notifications.slice(0).filter(e => e !== not);
|
||||
let n = this.state.notifications.filter(e => e !== not);
|
||||
this.setState({ notifications: n });
|
||||
}
|
||||
|
||||
|
5
src/components/routes/404/index.tsx
Normal file
5
src/components/routes/404/index.tsx
Normal file
@ -0,0 +1,5 @@
|
||||
import { h } from "preact";
|
||||
|
||||
export default function Error404Page() {
|
||||
return <h1>Page not found!</h1>;
|
||||
}
|
@ -6,7 +6,7 @@ import Navigation from "../../../navigation";
|
||||
export default class SharePage extends Page<{ state: any }, { vault: string }> {
|
||||
text: string;
|
||||
componentWillMount() {
|
||||
let { title, text, url } = Navigation.getQuery() || {} as any;
|
||||
let { title, text, url } = this.props.state;
|
||||
let note = "";
|
||||
if (title) {
|
||||
note += title + "\n"
|
||||
@ -24,7 +24,9 @@ export default class SharePage extends Page<{ state: any }, { vault: string }> {
|
||||
|
||||
render() {
|
||||
return <VaultsPage state={undefined} selectVault onSelected={vault => {
|
||||
Navigation.setPage("/vault", { id: vault }, { entry: "true", note: this.text }, true);
|
||||
Navigation.setPage("/", undefined, undefined, true);
|
||||
Navigation.setPage("/vault", { id: vault });
|
||||
Navigation.setPage("/vault", { id: vault }, { entry: "true", note: this.text });
|
||||
}} />
|
||||
}
|
||||
}
|
||||
|
@ -74,17 +74,30 @@ export default class EntryList extends Component<{ vault: Promise<IVault> }, { n
|
||||
}
|
||||
}
|
||||
|
||||
const deleteNote = async () => {
|
||||
Notes.delete(note._id).then(() => {
|
||||
Notifications.sendSuccess("Deleted")
|
||||
this.rawNotes = this.rawNotes.filter(e => e._id !== note._id);
|
||||
this.setState({ notes: this.state.notes.filter(e => e._id !== note._id) });
|
||||
}).catch(err => {
|
||||
Notifications.sendError(err);
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
let share;
|
||||
if ((window.navigator as any).share) {
|
||||
share = <button class="uk-button" onClick={() => shareNote()}>
|
||||
share = <button class="uk-button" onClick={shareNote}>
|
||||
share
|
||||
</button>
|
||||
let context = <ContextMenu event={evt} >
|
||||
{share}
|
||||
</ContextMenu>
|
||||
|
||||
this.setState({ context });
|
||||
}
|
||||
|
||||
let context = <ContextMenu event={evt} >
|
||||
{share}
|
||||
<button class="uk-button" onClick={deleteNote}>delete</button>
|
||||
</ContextMenu>
|
||||
|
||||
this.setState({ context });
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -218,7 +218,7 @@ export default class VaultsPage extends Page<VaultsProps, { vaults: VaultList, m
|
||||
{this.state.context}
|
||||
<header class="uk-background-primary">
|
||||
<span></span>
|
||||
<h3 style="display:inline" onClick={() => Navigation.setPage("/")}>Your vaults:</h3>
|
||||
<h3 style="display:inline" onClick={() => Navigation.setPage("/")}>{this.props.selectVault ? "Select Vault for share" : "Your vaults:"}</h3>
|
||||
<span></span>
|
||||
</header>
|
||||
<AddButton onClick={() => this.addButtonClick()} />
|
||||
|
@ -5,32 +5,32 @@ declare global {
|
||||
debug: any;
|
||||
}
|
||||
|
||||
namespace JSX {
|
||||
interface IntrinsicElements {
|
||||
"wired-button": HTMLAttributes;
|
||||
"wired-card": HTMLAttributes;
|
||||
"wired-checkbox": HTMLAttributes;
|
||||
"wired-combo": HTMLAttributes;
|
||||
"wired-fab": HTMLAttributes;
|
||||
"wired-icon-button": HTMLAttributes;
|
||||
"wired-input": HTMLAttributes;
|
||||
"wired-item": HTMLAttributes;
|
||||
"wired-lib": HTMLAttributes;
|
||||
"wired-listbox": HTMLAttributes;
|
||||
"wired-progress": HTMLAttributes;
|
||||
"wired-radio-group": HTMLAttributes;
|
||||
"wired-radio": HTMLAttributes;
|
||||
"wired-slider": HTMLAttributes;
|
||||
"wired-spinner": HTMLAttributes;
|
||||
"wired-tabs": HTMLAttributes;
|
||||
"wired-textarea": HTMLAttributes;
|
||||
"wired-toggle": HTMLAttributes;
|
||||
"wired-tooltip": HTMLAttributes;
|
||||
// namespace JSX {
|
||||
// interface IntrinsicElements {
|
||||
// "wired-button": HTMLAttributes;
|
||||
// "wired-card": HTMLAttributes;
|
||||
// "wired-checkbox": HTMLAttributes;
|
||||
// "wired-combo": HTMLAttributes;
|
||||
// "wired-fab": HTMLAttributes;
|
||||
// "wired-icon-button": HTMLAttributes;
|
||||
// "wired-input": HTMLAttributes;
|
||||
// "wired-item": HTMLAttributes;
|
||||
// "wired-lib": HTMLAttributes;
|
||||
// "wired-listbox": HTMLAttributes;
|
||||
// "wired-progress": HTMLAttributes;
|
||||
// "wired-radio-group": HTMLAttributes;
|
||||
// "wired-radio": HTMLAttributes;
|
||||
// "wired-slider": HTMLAttributes;
|
||||
// "wired-spinner": HTMLAttributes;
|
||||
// "wired-tabs": HTMLAttributes;
|
||||
// "wired-textarea": HTMLAttributes;
|
||||
// "wired-toggle": HTMLAttributes;
|
||||
// "wired-tooltip": HTMLAttributes;
|
||||
|
||||
}
|
||||
}
|
||||
// }
|
||||
// }
|
||||
}
|
||||
// declare const window: Window;
|
||||
declare const window: Window;
|
||||
|
||||
window.requestIdleCallback =
|
||||
window.requestIdleCallback ||
|
||||
@ -77,6 +77,7 @@ import DemoPage from './components/demo';
|
||||
import VaultPage from './components/routes/vault/Vault';
|
||||
import SharePage from './components/routes/share/Share';
|
||||
import Notifications from './notifications';
|
||||
import Error404Page from './components/routes/404';
|
||||
window.debug.notes = Notes;
|
||||
|
||||
(async () => {
|
||||
@ -104,6 +105,14 @@ window.debug.notes = Notes;
|
||||
Navigation.addPage("/vault", VaultPage as typeof Page)
|
||||
Navigation.addPage("/demo", DemoPage as typeof Page)
|
||||
Navigation.addPage("/share", SharePage as typeof Page)
|
||||
Navigation.addPage("/404", Error404Page);
|
||||
const trad = window.location.pathname;
|
||||
if (trad && trad !== "/" && trad !== "") {
|
||||
let p: any = {};
|
||||
new URL(window.location.href).searchParams.forEach((val, key) => p[key] = val);
|
||||
Navigation.setPage(trad, p, undefined, true);
|
||||
// window.location.href = "/#/" + trad;
|
||||
}
|
||||
Navigation.start();
|
||||
|
||||
render(<App />, document.body, document.getElementById('app'));
|
||||
|
@ -23,9 +23,10 @@ function parseQuery(query: string) {
|
||||
return data
|
||||
}
|
||||
|
||||
type PageFunction = () => JSX.Element;
|
||||
|
||||
export default class Navigation {
|
||||
private static _pages: Map<string, typeof Page> = new Map();
|
||||
private static _pages: Map<string, typeof Page | PageFunction> = new Map();
|
||||
private static _page: { route: string, page: JSX.Element };
|
||||
private static pageObservableServer = new Observable<JSX.Element>();
|
||||
public static pageObservable = Navigation.pageObservableServer.getPublicApi();
|
||||
@ -34,7 +35,7 @@ export default class Navigation {
|
||||
|
||||
private static _page_cache = new Map<string, VNode<any>>();
|
||||
|
||||
public static addPage(route: string, comp: typeof Page) {
|
||||
public static addPage(route: string, comp: typeof Page | PageFunction) {
|
||||
Navigation._pages.set(route, comp);
|
||||
}
|
||||
|
||||
@ -69,9 +70,9 @@ export default class Navigation {
|
||||
let oldkey = whash + serializQuery(history.state);
|
||||
if (newkey !== oldkey) {
|
||||
if (replace)
|
||||
window.history.replaceState(hidden, document.title, newhash);
|
||||
window.history.replaceState(hidden, document.title, "./" + newhash);
|
||||
else
|
||||
window.history.pushState(hidden, document.title, newhash);
|
||||
window.history.pushState(hidden, document.title, "./" + newhash);
|
||||
}
|
||||
let page = this._page_cache.get(newkey);
|
||||
if (!page) {
|
||||
|
Reference in New Issue
Block a user