fix: header flickering in list container

This commit is contained in:
thecodrr
2021-09-02 16:32:20 +05:00
parent 3a2e5102a1
commit 360258fd8c
7 changed files with 51 additions and 28 deletions

View File

@@ -69,7 +69,8 @@ export const Reminders = {
}; };
export async function resetReminders() { export async function resetReminders() {
appStore.set((state) => (state.reminders = [])); const reminders = [];
if (await shouldAddBackupReminder()) { if (await shouldAddBackupReminder()) {
if (isDesktop()) { if (isDesktop()) {
const { data, filename, ext } = await createBackup(false); const { data, filename, ext } = await createBackup(false);
@@ -79,16 +80,17 @@ export async function resetReminders() {
); );
saveFile(`${directory}/${filename}.${ext}`, data); saveFile(`${directory}/${filename}.${ext}`, data);
} else { } else {
appStore.addReminder("backup", "high"); reminders.push({ type: "backup", priority: "high" });
} }
} }
if (await shouldAddLoginReminder()) { if (await shouldAddLoginReminder()) {
appStore.addReminder("login", "low"); reminders.push({ type: "login", priority: "low" });
} }
if (await shouldAddConfirmEmailReminder()) { if (await shouldAddConfirmEmailReminder()) {
appStore.addReminder("email", "high"); reminders.push({ type: "email", priority: "high" });
} }
if (await shouldAddRecoveryKeyBackupReminder()) { if (await shouldAddRecoveryKeyBackupReminder()) {
appStore.addReminder("recoverykey", "high"); reminders.push({ type: "recoverykey", priority: "high" });
} }
appStore.get().setReminders(...reminders);
} }

View File

@@ -177,3 +177,5 @@ export const MailCheck = createIcon(Icons.mdiEmailCheckOutline);
export const Discord = createIcon(Icons.mdiDiscord); export const Discord = createIcon(Icons.mdiDiscord);
export const Twitter = createIcon(Icons.mdiTwitter); export const Twitter = createIcon(Icons.mdiTwitter);
export const Reddit = createIcon(Icons.mdiReddit); export const Reddit = createIcon(Icons.mdiReddit);
export const Dismiss = createIcon(Icons.mdiClose);

View File

@@ -66,16 +66,6 @@ function ListContainer(props) {
) : ( ) : (
<ReminderBar /> <ReminderBar />
), ),
Footer: () => (
<Text
textAlign="center"
color="fontTertiary"
variant="body"
py={2}
>
End reached
</Text>
),
}} }}
itemContent={(index, item) => { itemContent={(index, item) => {
if (!item) return null; if (!item) return null;

View File

@@ -80,6 +80,7 @@ function Note(props) {
if (!tagItem) return null; if (!tagItem) return null;
return ( return (
<IconTag <IconTag
key={tagItem.id}
text={tagItem.alias || tagItem.title} text={tagItem.alias || tagItem.title}
icon={Icon.Tag} icon={Icon.Tag}
onClick={() => { onClick={() => {

View File

@@ -1,11 +1,12 @@
import React, { useMemo } from "react"; import React, { useMemo } from "react";
import { Flex, Text } from "rebass"; import { Button, Flex, Text } from "rebass";
import { useStore as useAppStore } from "../../stores/app-store"; import { useStore as useAppStore } from "../../stores/app-store";
import { Reminders } from "../../common/reminders"; import { Reminders } from "../../common/reminders";
import * as Icon from "../icons"; import * as Icon from "../icons";
function ReminderBar() { function ReminderBar() {
const reminders = useAppStore((store) => store.reminders); const reminders = useAppStore((store) => store.reminders);
const dismissReminders = useAppStore((store) => store.dismissReminders);
const reminder = useMemo(() => { const reminder = useMemo(() => {
if (!reminders) return null; if (!reminders) return null;
@@ -14,21 +15,21 @@ function ReminderBar() {
if (!reminder) return; if (!reminder) return;
return Reminders[reminder.type]; return Reminders[reminder.type];
}, [reminders]); }, [reminders]);
if (!reminder) return null; if (!reminder) return null;
return ( return (
<Flex <Flex
alignItems="center" alignItems="center"
justifyContent="space-between"
sx={{ sx={{
cursor: "pointer", cursor: "pointer",
borderRadius: "default", borderRadius: "default",
":hover": { bg: "hover" }, ":hover": { bg: "hover" },
}} }}
p={1}
onClick={reminder?.action} onClick={reminder?.action}
mx={1} mx={1}
p={1}
> >
<Flex alignItems="center"> <Flex alignItems="center" flex={1}>
<reminder.icon <reminder.icon
size={18} size={18}
color="primary" color="primary"
@@ -43,7 +44,22 @@ function ReminderBar() {
</Text> </Text>
</Flex> </Flex>
</Flex> </Flex>
<Icon.ChevronRight size={20} color="primary" /> <Button
onClick={(e) => {
e.stopPropagation();
dismissReminders(reminder);
}}
sx={{
borderRadius: 50,
p: 1,
mr: 1,
bg: "transparent",
":hover": { backgroundColor: "shade" },
}}
variant="tool"
>
<Icon.Dismiss size={20} color="primary" />
</Button>
</Flex> </Flex>
); );
} }

View File

@@ -77,13 +77,25 @@ class AppStore extends BaseStore {
* @param {string} detail * @param {string} detail
* @param {"high"|"medium"|"low"} priority * @param {"high"|"medium"|"low"} priority
*/ */
addReminder = (type, priority) => { setReminders = (...reminders) => {
this.set((state) => this.set((state) => {
state.reminders.push({ state.reminders = [];
type, for (let reminder of reminders) {
priority: priority === "high" ? 1 : priority === "medium" ? 2 : 1, const { priority, type } = reminder;
}) state.reminders.push({
); type,
priority: priority === "high" ? 1 : priority === "medium" ? 2 : 1,
});
}
});
};
dismissReminders = (...reminders) => {
this.set((state) => {
for (let reminder of reminders) {
state.reminders.splice(state.reminders.indexOf(reminder), 1);
}
});
}; };
pinItemToMenu = async (item) => { pinItemToMenu = async (item) => {

View File

@@ -8731,7 +8731,7 @@ normalize-url@^3.0.0:
"notes-core@git+https://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:x-oauth-basic@github.com/streetwriters/notesnook-core.git": "notes-core@git+https://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:x-oauth-basic@github.com/streetwriters/notesnook-core.git":
version "6.8.4" version "6.8.4"
resolved "git+https://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:x-oauth-basic@github.com/streetwriters/notesnook-core.git#9573ab115600117146f9d53b7fefba0ca89d03d8" resolved "git+https://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:x-oauth-basic@github.com/streetwriters/notesnook-core.git#18b05fecdcab12278eb4e2e83e20e1f2d2cc97d0"
dependencies: dependencies:
"@stablelib/blake2s" "^1.0.1" "@stablelib/blake2s" "^1.0.1"
dayjs "^1.10.6" dayjs "^1.10.6"