mirror of
https://github.com/chinchang/web-maker.git
synced 2025-07-18 12:31:12 +02:00
add routing
This commit is contained in:
@@ -147,7 +147,7 @@ export function MainHeader(props) {
|
|||||||
}
|
}
|
||||||
class="main-header__avatar-img"
|
class="main-header__avatar-img"
|
||||||
/>
|
/>
|
||||||
{props.user && props.user.isPro ? <ProBadge /> : null}
|
{props.user?.isPro ? <ProBadge /> : null}
|
||||||
</HStack>
|
</HStack>
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
|
@@ -245,6 +245,10 @@ export default class App extends Component {
|
|||||||
this.setCurrentItem(this.state.currentItem).then(() => {
|
this.setCurrentItem(this.state.currentItem).then(() => {
|
||||||
this.refreshEditor();
|
this.refreshEditor();
|
||||||
});
|
});
|
||||||
|
} else if (this.props.itemId) {
|
||||||
|
window.db.fetchItem(this.props.itemId).then(item => {
|
||||||
|
this.setCurrentItem(item).then(() => this.refreshEditor());
|
||||||
|
});
|
||||||
} else if (result.preserveLastCode && lastCode) {
|
} else if (result.preserveLastCode && lastCode) {
|
||||||
this.setState({ unsavedEditCount: 0 });
|
this.setState({ unsavedEditCount: 0 });
|
||||||
log('Load last unsaved item', lastCode);
|
log('Load last unsaved item', lastCode);
|
||||||
@@ -570,6 +574,7 @@ export default class App extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
|
console.log('itemId', this.props.itemId);
|
||||||
function setBodySize() {
|
function setBodySize() {
|
||||||
document.body.style.height = `${window.innerHeight}px`;
|
document.body.style.height = `${window.innerHeight}px`;
|
||||||
}
|
}
|
||||||
|
13
src/db.js
13
src/db.js
@@ -142,6 +142,18 @@ import { log } from './utils';
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function fetchItem(itemId) {
|
||||||
|
const remoteDb = await getDb();
|
||||||
|
return remoteDb
|
||||||
|
.doc(`items/${itemId}`)
|
||||||
|
.get()
|
||||||
|
.then(doc => {
|
||||||
|
if (!doc.exists) return {};
|
||||||
|
const data = doc.data();
|
||||||
|
return data;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Fetch user settings.
|
// Fetch user settings.
|
||||||
// This isn't hitting the remote db because remote settings
|
// This isn't hitting the remote db because remote settings
|
||||||
// get fetch asynchronously (in user/) and update the envioronment.
|
// get fetch asynchronously (in user/) and update the envioronment.
|
||||||
@@ -161,6 +173,7 @@ import { log } from './utils';
|
|||||||
getUserLastSeenVersion,
|
getUserLastSeenVersion,
|
||||||
setUserLastSeenVersion,
|
setUserLastSeenVersion,
|
||||||
getSettings,
|
getSettings,
|
||||||
|
fetchItem,
|
||||||
local: dbLocalAlias,
|
local: dbLocalAlias,
|
||||||
sync: dbSyncAlias
|
sync: dbSyncAlias
|
||||||
};
|
};
|
||||||
|
10
src/index.js
10
src/index.js
@@ -1,3 +1,4 @@
|
|||||||
|
import Router from 'preact-router';
|
||||||
import App from './components/app.jsx';
|
import App from './components/app.jsx';
|
||||||
|
|
||||||
import './lib/codemirror/lib/codemirror.css';
|
import './lib/codemirror/lib/codemirror.css';
|
||||||
@@ -8,4 +9,11 @@ import './lib/hint.min.css';
|
|||||||
import './lib/inlet.css';
|
import './lib/inlet.css';
|
||||||
import './style.css';
|
import './style.css';
|
||||||
|
|
||||||
export default App;
|
export default function () {
|
||||||
|
return (
|
||||||
|
<Router>
|
||||||
|
<App path="/" />
|
||||||
|
<App path="/creation/:itemId" />
|
||||||
|
</Router>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
import { deferred } from './deferred';
|
import { deferred } from './deferred';
|
||||||
import { log } from 'util';
|
import { log } from './utils';
|
||||||
import firebase from 'firebase/app';
|
import firebase from 'firebase/app';
|
||||||
|
|
||||||
export const itemService = {
|
export const itemService = {
|
||||||
|
Reference in New Issue
Block a user