Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

mobile: fix attachment recheck ui

Ammar Ahmed0d7f32bdd079
diff --git a/apps/mobile/app/components/attachments/attachment-item.tsx b/apps/mobile/app/components/attachments/attachment-item.tsx
index 44edb2d1f..5cdd1e93c 100644
--- a/apps/mobile/app/components/attachments/attachment-item.tsx
+++ b/apps/mobile/app/components/attachments/attachment-item.tsx
@@ -86,7 +86,8 @@ export const AttachmentItem = ({
style={{
flexShrink: 1,
flexDirection: "row",
- alignItems: "center"
+ alignItems: "center",
+ gap: 10
}}
>
<View
@@ -97,7 +98,7 @@ export const AttachmentItem = ({
borderWidth: 1,
borderColor: colors.secondary.border,
paddingHorizontal: 2,
- minWidth: 20,
+ width: 30,
height: 30,
borderRadius: 5
}}
@@ -107,7 +108,7 @@ export const AttachmentItem = ({
size={8}
color={colors.secondary.paragraph}
style={{
- maxWidth: 20
+ maxWidth: 30
}}
numberOfLines={1}
>
@@ -118,8 +119,7 @@ export const AttachmentItem = ({
<View
style={{
- flexShrink: 1,
- marginLeft: 10
+ flexShrink: 1
}}
>
<Paragraph
@@ -135,7 +135,7 @@ export const AttachmentItem = ({
</Paragraph>
{!hideWhenNotDownloading ? (
- <Paragraph color={colors.secondary.paragraph} size={SIZE.xs}>
+ <Paragraph color={colors.secondary.paragraph} size={SIZE.xxs}>
File size: {formatBytes(attachment.size)}
</Paragraph>
) : null}
diff --git a/apps/mobile/app/components/attachments/index.tsx b/apps/mobile/app/components/attachments/index.tsx
index 83acdfbaf..b5b312303 100644
--- a/apps/mobile/app/components/attachments/index.tsx
+++ b/apps/mobile/app/components/attachments/index.tsx
@@ -60,6 +60,7 @@ type RecheckerProgress = {
passed: number;
isWorking: boolean;
shown: boolean;
+ filter: string;
};
interface RecheckerState extends State {
@@ -67,6 +68,7 @@ interface RecheckerState extends State {
[key: string]: RecheckerProgress;
};
setProgress: (key: string, progress: RecheckerProgress) => void;
+ currentFilter: string;
}
const useRechecker = create<RecheckerState>((set) => ({
@@ -75,11 +77,11 @@ const useRechecker = create<RecheckerState>((set) => ({
failed: 0,
passed: 0,
isWorking: false,
- shown: false
+ shown: false,
+ filter: "all"
}
- } as {
- [key: string]: RecheckerProgress;
},
+ currentFilter: "all",
setProgress: (key: string, progress: RecheckerProgress) => {
set((state) => ({
progress: {
@@ -136,11 +138,17 @@ export const AttachmentDialog = ({
const searchTimer = useRef<NodeJS.Timeout>();
const [currentFilter, setCurrentFilter] = useState("all");
const rechecker = useRechecker((state) =>
- note ? state.progress[note.id] : state.progress.all
+ note ? state.progress[note.id] || {} : state.progress.all
);
const currentFilterRef = useRef(currentFilter);
currentFilterRef.current = currentFilter;
+ useEffect(() => {
+ useRechecker.setState({
+ currentFilter: currentFilter
+ });
+ }, [currentFilter]);
+
const refresh = React.useCallback(() => {
if (note) {
db.attachments
@@ -209,15 +217,21 @@ export const AttachmentDialog = ({
...getState(),
...state
});
+
if (!attachments || getState().isWorking) return;
setState({
isWorking: true,
failed: 0,
passed: 0,
- shown: true
+ shown: true,
+ filter: currentFilterRef.current
});
+ const filter = currentFilterRef.current;
+ const filteredAttachments = await filterAttachments(
+ currentFilterRef.current
+ );
- for (let i = 0; i < attachments.placeholders.length; i++) {
+ for (let i = 0; i < filteredAttachments.placeholders.length; i++) {
if (!getState().isWorking) {
ToastManager.show({
message: "Attachment recheck cancelled",
@@ -244,7 +258,9 @@ export const AttachmentDialog = ({
await db.attachments.markAsFailed(attachment.id);
}
}
- setAttachments(await filterAttachments(currentFilter));
+ if (filter === useRechecker.getState().currentFilter) {
+ setAttachments(await filterAttachments(currentFilter));
+ }
setState({
isWorking: false
@@ -422,21 +438,26 @@ export const AttachmentDialog = ({
<View
style={{
flexDirection: "row",
- gap: 12
+ gap: 12,
+ alignItems: "center"
}}
>
{rechecker.isWorking ? (
<ActivityIndicator color={colors.primary.accent} />
) : (
- <Icon name="check" size={30} color={colors.primary.accent} />
+ <Icon
+ name="file-check"
+ size={30}
+ color={colors.primary.accent}
+ />
)}
<View>
<Paragraph>
{rechecker.isWorking
? note
- ? `Checking ${currentFilter.toLowerCase()} note attachments`
- : `Checking ${currentFilter.toLowerCase()} attachments`
+ ? `Checking ${rechecker.filter.toLowerCase()} note attachments`
+ : `Checking ${rechecker.filter.toLowerCase()} attachments`
: "Attachments recheck complete"}
</Paragraph>
<Paragraph>
@@ -448,10 +469,12 @@ export const AttachmentDialog = ({
</View>
<IconButton
- type="errorShade"
- name="close"
+ type={rechecker.isWorking ? "errorShade" : "plain"}
+ name={rechecker.isWorking ? "close" : "check"}
size={SIZE.lg}
- color={colors.error.icon}
+ color={
+ rechecker.isWorking ? colors.error.icon : colors.primary.accent
+ }
onPress={() => {
useRechecker.getState().setProgress(note?.id || "all", {
...useRechecker.getState().progress[note?.id || "all"],
@@ -472,8 +495,7 @@ export const AttachmentDialog = ({
paddingVertical: 12
}}
contentContainerStyle={{
- alignItems: "center",
- paddingRight: 50
+ alignItems: "center"
}}
horizontal
>