diff --git a/marko/page/data/components/changes-page/component.js b/marko/page/data/components/changes-page/component.js index 31883cf..2819cd5 100644 --- a/marko/page/data/components/changes-page/component.js +++ b/marko/page/data/components/changes-page/component.js @@ -1,11 +1,27 @@ +const { changesApi } = require("../../../../../rpdata/api/Change") + + module.exports = class { onCreate(input) { this.state = { - characters: input.characters, + changes: input.changes, + shownAll: false, modal: null, } } + clearLimit(e) { + // Disable mobile URL fallback. + if (e && e.preventDefault) { + e.preventDefault() + } + + changesApi.list({limit: 0}).then(changes => { + this.state.changes = changes + this.state.shownAll = true + }) + } + open(modal) { this.state.modal = modal } diff --git a/marko/page/data/components/changes-page/index.marko b/marko/page/data/components/changes-page/index.marko index 65ae451..e1175ec 100644 --- a/marko/page/data/components/changes-page/index.marko +++ b/marko/page/data/components/changes-page/index.marko @@ -3,10 +3,12 @@

Changes

All changes to listed resources is stored for 90 days for transparency reasons. The current state of an object after each change exists, but is only available through the GraphQL API at this time.

- + + Show All
+ diff --git a/marko/page/data/components/changes-page/style.less b/marko/page/data/components/changes-page/style.less index 91f0f46..1e324c7 100644 --- a/marko/page/data/components/changes-page/style.less +++ b/marko/page/data/components/changes-page/style.less @@ -33,4 +33,21 @@ opacity: 1; } } + + .show-more-button { + margin: 1em 0; + padding: 0.5em 2em; + font-size: 2em; + text-align: center; + user-select: none; + display: block; + + color: #DA1; + } + + .show-more-button:hover { + cursor: pointer; + + text-decoration: underline; + } } \ No newline at end of file diff --git a/marko/page/logs-content/components/log-suggestions/component.js b/marko/page/logs-content/components/log-suggestions/component.js index 77215e0..1abb32a 100644 --- a/marko/page/logs-content/components/log-suggestions/component.js +++ b/marko/page/logs-content/components/log-suggestions/component.js @@ -1,96 +1,10 @@ -const {logHeaderApi} = require("../../../../../rpdata/api/LogHeader") - module.exports = class { onCreate(input) { this.state = { id: input.log.id, channelName: input.log.channelName, eventName: input.log.eventName, - nexts: [], - prevs: [], - loaded: false, error: null, } } - - onMount() { - this.timeout = setTimeout(() => { - logHeaderApi.list().then(logs => { - const index = logs.findIndex(l => l.id === this.state.id); - if (index === -1) { - return Promise.reject("This log not found in list.") - } - const log = logs[index] - const characterIds = log.characters.map(c => c.id); - const nexts = [] - const prevs = [] - let foundGroups = {} - let foundChannel = false - - for (let i = index - 1; i >= 0; --i) { - const log2 = logs[i] - const hasEvent = (log.eventName ? log.eventName === log2.eventName : false) - const hasChannel = (log.channelName === log2.channelName) - - const characters = log2.findCharacters(...characterIds) - const characterIdsKey = characters.map(c => c.id).sort().join(",") - - const suggestion = {log: log2, characters, hasEvent, hasChannel} - - if (hasChannel && !foundChannel) { - foundChannel = true - foundGroups[characterIdsKey] = true - - nexts.push(suggestion) - } else if (hasEvent) { - foundGroups[characterIdsKey] = true - - nexts.push(suggestion) - } else if (nexts.length < 8 && !hasEvent && characters.length > 1 && !foundGroups[characterIdsKey]) { - foundGroups[characterIdsKey] = true - nexts.push(suggestion) - } - } - - foundGroups = {} - foundChannel = false - - for (let i = index + 1; i < logs.length; ++i) { - const log2 = logs[i] - const hasEvent = (log.eventName ? log.eventName === log2.eventName : false) - const hasChannel = (log.channelName === log2.channelName) - - const characters = log2.findCharacters(...characterIds) - const characterIdsKey = characters.map(c => c.id).sort().join(",") - - const suggestion = {log: log2, characters, hasEvent, hasChannel} - - if (hasChannel && !foundChannel) { - foundChannel = true - foundGroups[characterIdsKey] = true - - prevs.push(suggestion) - } else if (hasEvent) { - foundGroups[characterIdsKey] = true - - prevs.push(suggestion) - } else if (prevs.length < 8 && !hasEvent && characters.length > 1 && !foundGroups[characterIdsKey]) { - foundGroups[characterIdsKey] = true - prevs.push(suggestion) - } - } - - this.state.nexts = nexts; - this.state.prevs = prevs; - this.state.loaded = true; - }).catch(err => { - console.warn("Suggestions load error:", err) - this.suggestionsError = "Failed to load suggestions: " + err.toString() - }) - }, 1000) - } - - onUnmount() { - clearTimeout(this.timeout) - } } diff --git a/marko/page/logs-content/components/log-suggestions/index.marko b/marko/page/logs-content/components/log-suggestions/index.marko index 5cbafb4..1d4c41a 100644 --- a/marko/page/logs-content/components/log-suggestions/index.marko +++ b/marko/page/logs-content/components/log-suggestions/index.marko @@ -1,41 +1,33 @@ import moment from "moment" -
- - 0 || state.prevs.length > 0)> - 0)> -

Next Logs

-
- -
p)) class="suggestion-description color-text">${paragraph}
-
-
${s.log.eventName}
-
${s.log.channelName}
-
${c.name}
-
+
+ 0 || input.log.prevLogs.length > 0)> + 0)> +

Next Logs

+
+ +
p)) class="suggestion-description color-text">${paragraph}
+
+
${input.log.eventName}
+
${s.log.channelName}
+
${c.name}
- - 0)> -

Previous Logs

-
- -
p)) class="suggestion-description color-text">${paragraph}
-
-
${s.log.eventName}
-
${s.log.channelName}
-
${c.name}
-
+
+
+ 0)> +

Previous Logs

+
+ +
p)) class="suggestion-description color-text">${paragraph}
+
+
${input.log.eventName}
+
${s.log.channelName}
+
${c.name}
- +
- -
(No suggestions)
-
- -
{state.error}
- -
Loading suggestions...
+
(No suggestions)
diff --git a/marko/page/logs/components/page/component.js b/marko/page/logs/components/page/component.js index 2f05e36..a094809 100644 --- a/marko/page/logs/components/page/component.js +++ b/marko/page/logs/components/page/component.js @@ -79,9 +79,14 @@ module.exports = class { } } - clearLimit() { + clearLimit(e) { this.state.filter = Object.assign({}, this.state.filter, {limit: 0}) + // Disable mobile URL fallback. + if (e && e.preventDefault) { + e.preventDefault() + } + this.refresh() this.updateQuery(this.state.filter) } diff --git a/marko/page/logs/components/page/index.marko b/marko/page/logs/components/page/index.marko index e138801..65a7ab4 100644 --- a/marko/page/logs/components/page/index.marko +++ b/marko/page/logs/components/page/index.marko @@ -4,9 +4,9 @@
0)> - +
diff --git a/marko/page/logs/components/page/style.less b/marko/page/logs/components/page/style.less index cbef823..3fccaf5 100644 --- a/marko/page/logs/components/page/style.less +++ b/marko/page/logs/components/page/style.less @@ -1,15 +1,16 @@ main.logs-page { - div.show-more-button { + .show-more-button { margin: 1em 0; padding: 0.5em 2em; font-size: 2em; text-align: center; user-select: none; + display: block; color: #DA1; } - div.show-more-button:hover { + .show-more-button:hover { cursor: pointer; text-decoration: underline; diff --git a/middleware/passport.js b/middleware/passport.js index c292d21..82049dc 100644 --- a/middleware/passport.js +++ b/middleware/passport.js @@ -7,7 +7,8 @@ const strategy = new Auth0Strategy({ domain: config.auth0.domain, clientID: config.auth0.clientId, clientSecret: config.auth0.secret, // Replace this with the client secret for your app - callbackURL: config.root + "/auth/callback" + callbackURL: config.root + "/auth/callback", + state: true, }, (accessToken, refreshToken, extraParams, profile, done) => { // accessToken is the token to call Auth0 API (not needed in the most cases) // extraParams.id_token has the JSON Web Token diff --git a/middleware/session.js b/middleware/session.js index b5d7481..1706965 100644 --- a/middleware/session.js +++ b/middleware/session.js @@ -6,7 +6,7 @@ module.exports = session({ secret: config.session.secret, store: new RedisStore(config.redis), cookie: { - secure: config.session.secure + secure: config.session.secure, }, resave: false, saveUninitialized: true, diff --git a/routes/auth.js b/routes/auth.js index ea3c98d..cffb6ed 100644 --- a/routes/auth.js +++ b/routes/auth.js @@ -17,12 +17,16 @@ router.get("/login", saveReferer, passport.authenticate("auth0", {scope: "openid res.redirect("/") }) -router.get("/callback", passport.authenticate("auth0"), (req, res) => { - if (req.user == null) { - throw new Error("user null"); - } - - res.redirect(req.session.loginReferrer || "/"); +router.get("/callback", function (req, res, next) { + passport.authenticate("auth0", function (err, user, info) { + if (err) { return next(err) } + if (!user) { console.log(err, user, info); return res.redirect("/auth/login") } + req.logIn(user, function (err) { + if (err) { return next(err) } + + res.redirect(req.session.loginReferrer || "/"); + }) + })(req, res, next); }) router.get("/user", (req, res) => { diff --git a/routes/data/changes.js b/routes/data/changes.js index 1ca6314..35f7f66 100644 --- a/routes/data/changes.js +++ b/routes/data/changes.js @@ -6,8 +6,10 @@ const {changesApi} = require("../../rpdata/api/Change") const changesTemplate = require("../../marko/page/data/changes.marko") router.get("/", async(req, res) => { + const limit = parseInt(req.query.limit) || 100 + res.markoAsync(changesTemplate, { - changes: changesApi.list({limit: 1000}), + changes: changesApi.list({limit}), selected: {changes: true}, }) }) diff --git a/rpdata/api/Log.js b/rpdata/api/Log.js index 1c363b7..920294d 100644 --- a/rpdata/api/Log.js +++ b/rpdata/api/Log.js @@ -31,7 +31,11 @@ class Log { } static fromData(data) { - return new Log(data.id, data.shortId, data.date, data.title, data.eventName, data.description, data.open, data.channel, data.characters, data.posts) + return new Log( + data.id, data.shortId, data.date, + data.title, data.eventName, data.description, + data.open, data.channel, data.characters, data.posts + ) } } @@ -70,10 +74,22 @@ class LogAPI { nick text } + nextLogs { + log {id title date channelName} + hasEvent + hasChannel + characters {name} + } + prevLogs { + log {id title date channelName} + hasEvent + hasChannel + characters {name} + } } } `, {id}).then(({log}) => { - return Log.fromData(log) + return log }) } @@ -219,7 +235,7 @@ class LogAPI { subscribeChanges(logId) { return new Subscription(` subscription Changes($keys: [ChangeKeyInput!]!) { - changes(keys: $keys) { + changes(filter: {keys: $keys}) { id model op