Skip to content

Instantly share code, notes, and snippets.

@jasonLaster
Created September 12, 2020 03:14
Show Gist options
  • Select an option

  • Save jasonLaster/52031b7559cc6759eb44c91b234191b1 to your computer and use it in GitHub Desktop.

Select an option

Save jasonLaster/52031b7559cc6759eb44c91b234191b1 to your computer and use it in GitHub Desktop.
commit bb192af76183bfcce029aaa969e3e959a108cc8f
Author: Jason Laster <jason.laster.11@gmail.com>
Date: Fri Sep 11 20:14:35 2020 -0700
tweaks
diff --git a/src/ui/actions/app.js b/src/ui/actions/app.js
index 26f76009..52f63f44 100644
--- a/src/ui/actions/app.js
+++ b/src/ui/actions/app.js
@@ -1,6 +1,5 @@
import { ThreadFront } from "protocol/thread";
import { selectors } from "ui/reducers";
-import { seek } from "./timeline";
export function setupApp(_, store) {
ThreadFront.ensureProcessed(_, regions => store.dispatch(onUnprocessedRegions(regions))).then(
@@ -39,25 +38,6 @@ function onUnprocessedRegions({ regions }) {
};
}
-export function focusComment(comment) {
- return ({ dispatch, getState }) => {
- const existingComments = selectors.getComments(getState());
- const { id, time, point, hasFrames } = comment;
- dispatch(setFocusedCommentId(id));
- dispatch(seek(point, time, hasFrames));
- };
-}
-
-export function unfocusComment() {
- return ({ dispatch }) => {
- dispatch(setFocusedCommentId(null));
- };
-}
-
-function setFocusedCommentId(id) {
- return { type: "set_focused_comment_id", id };
-}
-
export function updateTheme(theme) {
return { type: "update_theme", theme };
}
diff --git a/src/ui/actions/metadata.js b/src/ui/actions/metadata.js
index 0dfb8e5c..c3d96bee 100644
--- a/src/ui/actions/metadata.js
+++ b/src/ui/actions/metadata.js
@@ -98,6 +98,28 @@ export function clearComments() {
};
}
+function setFocusedCommentId(id) {
+ return { type: "set_focused_comment_id", id };
+}
+
+export function focusComment(comment) {
+ return ({ dispatch }) => {
+ const { id, time, point, hasFrames } = comment;
+ dispatch(setFocusedCommentId(id));
+ dispatch(seek(point, time, hasFrames));
+ };
+}
+
+export function unfocusComment() {
+ return ({ dispatch, getState }) => {
+ const focusedComment = selectors.getFocusedComment(getState());
+ if (focusComment.contents == "") {
+ dispatch(removeComment(focusedComment));
+ }
+ dispatch(setFocusedCommentId(null));
+ };
+}
+
export function registerUser() {
const user = prefs.user?.id
? prefs.user
diff --git a/src/ui/reducers/app.js b/src/ui/reducers/app.js
index f409c645..af6e5444 100644
--- a/src/ui/reducers/app.js
+++ b/src/ui/reducers/app.js
@@ -7,7 +7,6 @@ function initialAppState() {
selectedPanel: prefs.selectedPanel,
tooltip: null,
loading: 4,
- focusedComment: null,
};
}
@@ -29,10 +28,6 @@ export default function update(state = initialAppState(), action) {
return { ...state, loading: action.loading };
}
- case "set_focused_comment_id": {
- return { ...state, focusedCommentId: action.id };
- }
-
default: {
return state;
}
@@ -51,12 +46,4 @@ export function getSelectedPanel(state) {
return state.app.selectedPanel;
}
-export function getFocusedCommentId(state) {
- return state.app.focusedCommentId;
-}
-
-export function hasFocusedComment(state) {
- return state.app.focusedCommentId !== null;
-}
-
export const getLoading = state => state.app.loading;
diff --git a/src/ui/reducers/metadata.js b/src/ui/reducers/metadata.js
index 839d2fc9..cde6085d 100644
--- a/src/ui/reducers/metadata.js
+++ b/src/ui/reducers/metadata.js
@@ -5,6 +5,7 @@ function initialTimelineState() {
comments: [],
user: prefs.user,
users: [],
+ focusedCommentId: null,
};
}
@@ -22,6 +23,10 @@ export default function update(state = initialTimelineState(), action) {
return { ...state, users: action.users };
}
+ case "set_focused_comment_id": {
+ return { ...state, focusedCommentId: action.id };
+ }
+
default: {
return state;
}
@@ -39,3 +44,15 @@ export function getUser(state) {
export function getUsers(state) {
return state.metadata.users;
}
+
+export function getFocusedCommentId(state) {
+ return state.app.focusedCommentId;
+}
+
+export function getFocusedComment(state) {
+ return state.metadata.comments[getFocusedCommentId(state)];
+}
+
+export function hasFocusedComment(state) {
+ return state.app.focusedCommentId !== null;
+}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment