Skip to content

Commit 107befb

Browse files
authoredSep 16, 2021
Merge pull request #1653 from filipesilva/presence-details
Page-level presence
2 parents 23a35d3 + 65ea223 commit 107befb

File tree

13 files changed

+237
-353
lines changed

13 files changed

+237
-353
lines changed
 

‎.babelrc

-19
This file was deleted.

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@ dist
3434

3535
# design system static build
3636
/storybook-static
37+
/src/gen

‎babel.config.js

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
const {existsSync, lstatSync} = require("fs");
2+
const {resolve, dirname} = require("path");
3+
4+
function isRelativeImport(path){
5+
return path.startsWith(".");
6+
}
7+
8+
function isDirectory(path) {
9+
return existsSync(path) && lstatSync(path).isDirectory();
10+
}
11+
12+
function resolveImport (from, to) {
13+
return resolve(dirname(from), to);
14+
}
15+
16+
function replaceDirectoryImports() {
17+
return {
18+
visitor: {
19+
ImportDeclaration: (path, state) => {
20+
const importPath = path.node.source.value;
21+
const fileName = state.file.opts.filename;
22+
if (isRelativeImport(importPath) && isDirectory(resolveImport(fileName, importPath))) {
23+
path.node.source.value += "/index";
24+
}
25+
}
26+
}
27+
}
28+
}
29+
30+
31+
// This config will output files to ./src/gen/components via the `yarn components` script
32+
// See https://shadow-cljs.github.io/docs/UsersGuide.html#_javascript_dialects
33+
module.exports = {
34+
presets: [
35+
"@babel/env",
36+
// Compile tsx files.
37+
"@babel/preset-typescript",
38+
// Use the react runtime import if available.
39+
["@babel/preset-react", {"runtime": "automatic"}]
40+
],
41+
plugins: [
42+
// Add /index to all relative directory imports, because Shadow-CLJS does not support
43+
// them (https://github.com/thheller/shadow-cljs/issues/841#issuecomment-777323477)
44+
// NB: Putting these files in node_modules would have fixed the directory imports
45+
// but broken hot reload (https://github.com/thheller/shadow-cljs/issues/764#issuecomment-663064549)
46+
replaceDirectoryImports,
47+
// Allow using @/ for root relative imports in the component library.
48+
["module-resolver", {alias: {"@": "./src/js/components"}}],
49+
// Transform material-ui imports into deep imports for faster reload.
50+
// material-ui is very big, and importing it all can slow down development rebuilds by a lot.
51+
// https://material-ui.com/guides/minimizing-bundle-size/#development-environment
52+
["transform-imports", {
53+
"@material-ui/core": {
54+
transform: "@material-ui/core/esm/${member}",
55+
preventFullImport: true
56+
},
57+
"@material-ui/icons": {
58+
transform: "@material-ui/icons/esm/${member}",
59+
preventFullImport: true
60+
}
61+
}],
62+
// Our build doesn't need the {loose: true} option, but if not included it wil
63+
// show a lot of warnings on the storybook build.
64+
["@babel/proposal-class-properties", {loose: true}],
65+
["@babel/proposal-object-rest-spread", {loose: true}],
66+
// Used only by storybook, but must be included to avoid build warnings/errors.
67+
["@babel/plugin-proposal-private-methods", {loose: true}],
68+
["@babel/plugin-proposal-private-property-in-object", {loose: true}],
69+
// Import helpers from @babel/runtime instead of duplicating them everywhere.
70+
"@babel/plugin-transform-runtime",
71+
// Better debug information for styled components.
72+
// https://styled-components.com/docs/tooling#babel-plugin
73+
"babel-plugin-styled-components"
74+
],
75+
// Do not apply this babel config to node_modules.
76+
// Shadow-CLJS also runs babel over node_modules and we don't want this
77+
// configuration to apply to it.
78+
// We still want it to be picked up by storybook though.
79+
exclude: ["node_modules"]
80+
}

‎package.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
"update": "standard-version -p --releaseCommitMessageFormat v{{currentTag}}",
1313
"dev": "yarn components && concurrently \"yarn components:watch\" \"yarn client:watch\"",
1414
"client:watch": "shadow-cljs watch main renderer app",
15-
"components": "babel ./src/js/components/ --extensions \".ts,.tsx\" --out-dir ./dist/js/components/",
15+
"components": "babel ./src/js/components/ --extensions \".ts,.tsx\" --out-dir ./src/gen/components/",
1616
"components:watch": "yarn components --watch",
1717
"compile": "yarn components && shadow-cljs compile main renderer app",
1818
"prod": "yarn components && shadow-cljs release main renderer app",
19-
"clean": "rm -rf resources/public/**/*.js target .shadow-cljs ./src/stories/**/*.js",
19+
"clean": "rm -rf resources/public/**/*.js target .shadow-cljs src/gen",
2020
"dist": "electron-builder -p always",
2121
"storybook:watch": "start-storybook -p 6006",
2222
"storybook": "build-storybook",
@@ -59,6 +59,7 @@
5959
}
6060
},
6161
"dependencies": {
62+
"@babel/runtime": "^7.15.4",
6263
"@geometricpanda/storybook-addon-badges": "^0.0.4",
6364
"@js-joda/core": "1.12.0",
6465
"@js-joda/locale_en-us": "3.1.1",
@@ -100,6 +101,7 @@
100101
"@babel/plugin-proposal-object-rest-spread": "^7.15.6",
101102
"@babel/plugin-proposal-private-methods": "^7.14.5",
102103
"@babel/plugin-proposal-private-property-in-object": "^7.15.4",
104+
"@babel/plugin-transform-runtime": "^7.15.0",
103105
"@babel/preset-env": "^7.15.6",
104106
"@babel/preset-react": "^7.14.5",
105107
"@babel/preset-typescript": "^7.15.0",
@@ -110,6 +112,8 @@
110112
"@storybook/react": "^6.3.8",
111113
"babel-loader": "^8.2.2",
112114
"babel-plugin-module-resolver": "^4.1.0",
115+
"babel-plugin-styled-components": "^1.13.2",
116+
"babel-plugin-transform-imports": "^2.0.0",
113117
"concurrently": "^6.2.1",
114118
"electron": "^12.0.4",
115119
"electron-builder": "22.10",

‎project.clj

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757

5858
:min-lein-version "2.5.3"
5959

60-
:source-paths ["src/clj" "src/cljs" "src/cljc" "src/js" "dist/js"]
60+
:source-paths ["src/clj" "src/cljs" "src/cljc" "src/js" "src/gen"]
6161

6262
:main athens.self-hosted.core
6363
:aot [athens.self-hosted.core]

‎src/cljs/athens/self_hosted/presence/events.cljs

+6
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@
4343
(update-in [:presence :users new-username] assoc :username new-username))))
4444

4545

46+
(rf/reg-event-db
47+
:presence/update-color
48+
(fn [db [_ username color]]
49+
(assoc-in db [:presence :users username :color] color)))
50+
51+
4652
(rf/reg-event-fx
4753
:presence/send-rename
4854
(fn [_ [_ current-username new-username]]

‎src/cljs/athens/self_hosted/presence/subs.cljs

+13-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@
2121
users))))
2222

2323

24+
(rf/reg-sub
25+
:presence/current-user
26+
:<- [:presence/users-with-page-data]
27+
:<- [:settings]
28+
(fn [[users settings] [_]]
29+
(-> (filter (fn [[_ user]]
30+
(= (:username settings) (:username user)))
31+
users)
32+
first
33+
second)))
34+
35+
2436
(rf/reg-sub
2537
:presence/same-page
2638
:<- [:presence/users-with-page-data]
@@ -34,7 +46,7 @@
3446
(= current-route-uid (:page/uid user)))
3547
users))
3648

37-
[])))
49+
{})))
3850

3951

4052
(rf/reg-sub

1 commit comments

Comments
 (1)
Please sign in to comment.