Refactor components
Implement context mechanism to pass default attributes to descendant components.
This commit is contained in:
1 parent
d46d133878
commit
ee8c43747e
35 files changed
+1903
-1831
No files matched your search
+43
-42
@@ -5,46 +5,47 @@ import m from "mithril";
|
||||
import * as store from "./store";
|
||||
import * as notifications from "./notifications";
|
||||
|
||||
const userMenu = {
|
||||
view: () => {
|
||||
if (window.username) {
|
||||
return m(
|
||||
"div.user-menu",
|
||||
window.username,
|
||||
m(
|
||||
"button",
|
||||
{
|
||||
onclick: e => {
|
||||
e.target.disabled = true;
|
||||
store
|
||||
.logOut()
|
||||
.then(() => {
|
||||
location.hash = "";
|
||||
location.reload();
|
||||
})
|
||||
.catch(err => {
|
||||
e.target.disabled = false;
|
||||
notifications.push("error", err.message);
|
||||
});
|
||||
return false;
|
||||
}
|
||||
},
|
||||
"Log out"
|
||||
)
|
||||
);
|
||||
} else {
|
||||
return m(
|
||||
"div.user-menu",
|
||||
m(
|
||||
"a",
|
||||
{
|
||||
href: "#!/login?" + m.buildQueryString({ continue: m.route.get() })
|
||||
},
|
||||
"Log in"
|
||||
)
|
||||
);
|
||||
export default function userMenu() {
|
||||
return {
|
||||
view: () => {
|
||||
if (window.username) {
|
||||
return m(
|
||||
"div.user-menu",
|
||||
window.username,
|
||||
m(
|
||||
"button",
|
||||
{
|
||||
onclick: e => {
|
||||
e.target.disabled = true;
|
||||
store
|
||||
.logOut()
|
||||
.then(() => {
|
||||
location.hash = "";
|
||||
location.reload();
|
||||
})
|
||||
.catch(err => {
|
||||
e.target.disabled = false;
|
||||
notifications.push("error", err.message);
|
||||
});
|
||||
return false;
|
||||
}
|
||||
},
|
||||
"Log out"
|
||||
)
|
||||
);
|
||||
} else {
|
||||
return m(
|
||||
"div.user-menu",
|
||||
m(
|
||||
"a",
|
||||
{
|
||||
href:
|
||||
"#!/login?" + m.buildQueryString({ continue: m.route.get() })
|
||||
},
|
||||
"Log in"
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default userMenu;
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user