Skip to content

Commit 37fb35b

Browse files
authored
feat: add Edit to file listing context menu (#97)
1 parent 3c5cb22 commit 37fb35b

2 files changed

Lines changed: 31 additions & 10 deletions

File tree

frontend/src/utils/auth.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
logoutPage,
1010
authLogoutURL,
1111
} from "./constants";
12-
import { StatusError } from "@/api/utils";
12+
import { fetchURL, StatusError } from "@/api/utils";
1313
import { setSafeTimeout } from "@/api/utils";
1414

1515
export function parseToken(token: string) {
@@ -122,20 +122,15 @@ export async function signup(username: string, password: string) {
122122
}
123123

124124
export function logout(reason?: string) {
125-
document.cookie = "auth=; Max-Age=0; Path=/; SameSite=Strict;";
126-
127125
if (authMethod === "proxy" && authLogoutURL !== "") {
128126
// Hostinger specific
129-
fetch(authLogoutURL, {
130-
method: "POST",
131-
headers: {
132-
"Content-Type": "application/json",
133-
},
134-
}).catch(() => {
127+
fetchURL(authLogoutURL, { method: "POST" }).catch(() => {
135128
console.error("Failed to logout using proxy auth");
136129
});
137130
}
138131

132+
document.cookie = "auth=; Max-Age=0; Path=/; SameSite=Strict;";
133+
139134
const authStore = useAuthStore();
140135
authStore.clearUser();
141136

frontend/src/views/files/FileListing.vue

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,13 @@
292292
:label="t('buttons.share')"
293293
show="share"
294294
/>
295+
<action
296+
v-if="editAvailable"
297+
id="edit-button"
298+
icon="mode_edit"
299+
:label="t('buttons.edit')"
300+
@action="openSelectedFile"
301+
/>
295302
<action
296303
v-if="headerButtons.rename"
297304
icon="mode_edit"
@@ -413,7 +420,7 @@ import {
413420
toRef,
414421
watch,
415422
} from "vue";
416-
import { useRoute, onBeforeRouteUpdate } from "vue-router";
423+
import { useRoute, useRouter, onBeforeRouteUpdate } from "vue-router";
417424
import { useI18n } from "vue-i18n";
418425
import { removePrefix } from "@/api/utils";
419426

@@ -438,6 +445,7 @@ const route = useRoute();
438445
onBeforeRouteUpdate(() => {
439446
hideContextMenu();
440447
});
448+
const router = useRouter();
441449

442450
const { t } = useI18n();
443451

@@ -1162,6 +1170,24 @@ const handleEmptyAreaClick = (e: MouseEvent) => {
11621170

11631171
fileStore.selected = [];
11641172
};
1173+
1174+
const editAvailable = computed((): boolean => {
1175+
return (
1176+
fileStore.selectedCount === 1 &&
1177+
fileStore.req !== null &&
1178+
!fileStore.req.items[fileStore.selected[0]].isDir
1179+
);
1180+
});
1181+
1182+
const openSelectedFile = () => {
1183+
if (
1184+
fileStore.selectedCount === 1 &&
1185+
fileStore.req !== null &&
1186+
!fileStore.req.items[fileStore.selected[0]].isDir
1187+
) {
1188+
router.push({ path: fileStore.req.items[fileStore.selected[0]].url });
1189+
}
1190+
};
11651191
</script>
11661192
<style scoped>
11671193
#listing {

0 commit comments

Comments
 (0)