forked from outline/outline
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow sort by position for comments (outline#7770)
* feat: allow sort by position for comments * wait for prosemirror nodes to load * Move to menu * remove sort; rename enum * asc sort for in-thread display * revert sort --------- Co-authored-by: Tom Moor <[email protected]>
- Loading branch information
Showing
11 changed files
with
199 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import queryString from "query-string"; | ||
import React from "react"; | ||
import { useTranslation } from "react-i18next"; | ||
import { useHistory, useLocation } from "react-router-dom"; | ||
import styled from "styled-components"; | ||
import { s } from "@shared/styles"; | ||
import { UserPreference } from "@shared/types"; | ||
import InputSelect from "~/components/InputSelect"; | ||
import useCurrentUser from "~/hooks/useCurrentUser"; | ||
import useQuery from "~/hooks/useQuery"; | ||
import { CommentSortType } from "~/types"; | ||
|
||
const CommentSortMenu = () => { | ||
const { t } = useTranslation(); | ||
const location = useLocation(); | ||
const history = useHistory(); | ||
const user = useCurrentUser(); | ||
const params = useQuery(); | ||
|
||
const viewingResolved = params.get("resolved") === ""; | ||
const value = viewingResolved | ||
? "resolved" | ||
: user.getPreference(UserPreference.SortCommentsByOrderInDocument) | ||
? CommentSortType.OrderInDocument | ||
: CommentSortType.MostRecent; | ||
|
||
const handleSortTypeChange = (type: CommentSortType) => { | ||
user.setPreference( | ||
UserPreference.SortCommentsByOrderInDocument, | ||
type === CommentSortType.OrderInDocument | ||
); | ||
void user.save(); | ||
}; | ||
|
||
const showResolved = () => { | ||
history.push({ | ||
search: queryString.stringify({ | ||
...queryString.parse(location.search), | ||
resolved: "", | ||
}), | ||
pathname: location.pathname, | ||
}); | ||
}; | ||
|
||
const showUnresolved = () => { | ||
history.push({ | ||
search: queryString.stringify({ | ||
...queryString.parse(location.search), | ||
resolved: undefined, | ||
}), | ||
pathname: location.pathname, | ||
}); | ||
}; | ||
|
||
return ( | ||
<Select | ||
style={{ margin: 0 }} | ||
ariaLabel={t("Sort comments")} | ||
value={value} | ||
onChange={(ev) => { | ||
if (ev === "resolved") { | ||
showResolved(); | ||
} else { | ||
handleSortTypeChange(ev as CommentSortType); | ||
showUnresolved(); | ||
} | ||
}} | ||
borderOnHover | ||
options={[ | ||
{ value: CommentSortType.MostRecent, label: t("Most recent") }, | ||
{ value: CommentSortType.OrderInDocument, label: t("Order in doc") }, | ||
{ | ||
divider: true, | ||
value: "resolved", | ||
label: t("Resolved"), | ||
}, | ||
]} | ||
/> | ||
); | ||
}; | ||
|
||
const Select = styled(InputSelect)` | ||
color: ${s("textSecondary")}; | ||
`; | ||
|
||
export default CommentSortMenu; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.