Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.
Go dockerfossgomarkdownmemomicroblognote-takingnotesopen-sourceown-your-datareactself-hostedsqlitetimeline
fix: heatmap data (#394)
boojack006cb56d28dd
diff --git a/server/acl.go b/server/acl.goindex b9b765368..5d8f97745 100644--- a/server/acl.go+++ b/server/acl.go@@ -104,11 +104,11 @@ func aclMiddleware(s *Server, next echo.HandlerFunc) echo.HandlerFunc {}}- if common.HasPrefixes(path, "/api/memo/all", "/api/memo/:memoId", "/api/memo/amount", "/api/memo/stats") && c.Request().Method == http.MethodGet {+ if common.HasPrefixes(path, "/api/memo/all", "/api/memo/:memoId", "/api/memo/amount") && c.Request().Method == http.MethodGet {return next(c)}- if common.HasPrefixes(path, "/api/memo", "/api/tag", "/api/shortcut") && c.Request().Method == http.MethodGet {+ if common.HasPrefixes(path, "/api/memo", "/api/tag", "/api/shortcut", "/api/memo/stats") && c.Request().Method == http.MethodGet {if _, err := strconv.Atoi(c.QueryParam("creatorId")); err == nil {return next(c)}diff --git a/server/memo.go b/server/memo.goindex 7eff75b46..0a987c35c 100644--- a/server/memo.go+++ b/server/memo.go@@ -257,33 +257,24 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {memoFind := &api.MemoFind{RowStatus: &normalStatus,}- if userID, err := strconv.Atoi(c.QueryParam("userId")); err == nil {- memoFind.CreatorID = &userID+ if creatorID, err := strconv.Atoi(c.QueryParam("creatorId")); err == nil {+ memoFind.CreatorID = &creatorID+ }+ if memoFind.CreatorID == nil {+ return echo.NewHTTPError(http.StatusBadRequest, "Missing user id to find memo")}currentUserID, ok := c.Get(getUserIDContextKey()).(int)if !ok {- if memoFind.CreatorID == nil {- return echo.NewHTTPError(http.StatusBadRequest, "Missing user id to find memo")- }memoFind.VisibilityList = []api.Visibility{api.Public}} else {- if memoFind.CreatorID == nil {- memoFind.CreatorID = ¤tUserID- } else {+ if *memoFind.CreatorID != currentUserID {memoFind.VisibilityList = []api.Visibility{api.Public, api.Protected}+ } else {+ memoFind.VisibilityList = []api.Visibility{api.Public, api.Protected, api.Privite}}}- visibilitListStr := c.QueryParam("visibility")- if visibilitListStr != "" {- visibilityList := []api.Visibility{}- for _, visibility := range strings.Split(visibilitListStr, ",") {- visibilityList = append(visibilityList, api.Visibility(visibility))- }- memoFind.VisibilityList = visibilityList- }-list, err := s.Store.FindMemoList(ctx, memoFind)if err != nil {return echo.NewHTTPError(http.StatusInternalServerError, "Failed to fetch memo list").SetInternal(err)diff --git a/web/src/components/UsageHeatMap.tsx b/web/src/components/UsageHeatMap.tsxindex 0a650bf83..35ae752f2 100644--- a/web/src/components/UsageHeatMap.tsx+++ b/web/src/components/UsageHeatMap.tsx@@ -28,16 +28,17 @@ interface DailyUsageStat {}const UsageHeatMap = () => {- const { memos } = useAppSelector((state) => state.memo);- const [allStat, setAllStat] = useState<DailyUsageStat[]>([]);- const [currentStat, setCurrentStat] = useState<DailyUsageStat | null>(null);- const containerElRef = useRef<HTMLDivElement>(null);const todayTimeStamp = utils.getDateStampByDate(Date.now());const todayDay = new Date(todayTimeStamp).getDay() + 1;const nullCell = new Array(7 - todayDay).fill(0);const usedDaysAmount = (tableConfig.width - 1) * tableConfig.height + todayDay;const beginDayTimestemp = todayTimeStamp - usedDaysAmount * DAILY_TIMESTAMP;+ const { memos } = useAppSelector((state) => state.memo);+ const [allStat, setAllStat] = useState<DailyUsageStat[]>(getInitialUsageStat(usedDaysAmount, beginDayTimestemp));+ const [currentStat, setCurrentStat] = useState<DailyUsageStat | null>(null);+ const containerElRef = useRef<HTMLDivElement>(null);+useEffect(() => {getMemoStats(userService.getCurrentUserId()).then(({ data: { data } }) => {@@ -97,12 +98,12 @@ const UsageHeatMap = () => {count <= 0? "": count <= 1- ? "stat-day-L1-bg"+ ? "stat-day-l1-bg": count <= 2- ? "stat-day-L2-bg"+ ? "stat-day-l2-bg": count <= 4- ? "stat-day-L3-bg"- : "stat-day-L4-bg";+ ? "stat-day-l3-bg"+ : "stat-day-l4-bg";return (<divdiff --git a/web/src/helpers/api.ts b/web/src/helpers/api.tsindex 0988de8f8..c5951257f 100644--- a/web/src/helpers/api.ts+++ b/web/src/helpers/api.ts@@ -91,7 +91,7 @@ export function getMemoList(memoFind?: MemoFind) {}export function getMemoStats(userId: UserId) {- return axios.get<ResponseObject<number[]>>(`/api/memo/stats?userId=${userId}`);+ return axios.get<ResponseObject<number[]>>(`/api/memo/stats?creatorId=${userId}`);}export function getMemoById(id: MemoId) {diff --git a/web/src/less/usage-heat-map.less b/web/src/less/usage-heat-map.lessindex e31abc92b..c46145abe 100644--- a/web/src/less/usage-heat-map.less+++ b/web/src/less/usage-heat-map.less@@ -1,10 +1,5 @@@import "./mixin.less";-@stat-day-L1-bg: #9be9a8;-@stat-day-L2-bg: #40c463;-@stat-day-L3-bg: #30a14e;-@stat-day-L4-bg: #216e39;-.usage-heat-map-wrapper {@apply flex flex-row justify-start items-center w-full h-32 flex-wrap pr-6 pb-3 shrink-0;@@ -25,33 +20,32 @@> .stat-wrapper {> .stat-container {- @apply block rounded-sm;+ @apply block rounded-sm bg-gray-200;width: 14px;height: 14px;- background-color: @bg-lightgray;&.null {- @apply bg-transparent;+ @apply bg-gray-200;}- &.stat-day-L1-bg {- background-color: @stat-day-L1-bg !important;+ &.stat-day-l1-bg {+ @apply bg-green-400;}- &.stat-day-L2-bg {- background-color: @stat-day-L2-bg !important;+ &.stat-day-l2-bg {+ @apply bg-green-500;}- &.stat-day-L3-bg {- background-color: @stat-day-L3-bg !important;+ &.stat-day-l3-bg {+ @apply bg-green-600;}- &.stat-day-L4-bg {- background-color: @stat-day-L4-bg !important;+ &.stat-day-l4-bg {+ @apply bg-green-700;}&.today {- border: 1px solid black;+ @apply border border-black;}}}