mirror of
https://github.com/decaf-dev/obsidian-vault-explorer.git
synced 2026-07-22 10:10:31 +00:00
feat: remove timestamp filter
This commit is contained in:
parent
63772acbdb
commit
6dc0ff05c1
7 changed files with 1 additions and 180 deletions
|
|
@ -22,10 +22,6 @@ export const DEFAULT_SETTINGS: VaultExplorerPluginSettings = {
|
|||
isEnabled: true,
|
||||
value: "",
|
||||
},
|
||||
timestamp: {
|
||||
isEnabled: true,
|
||||
value: "all",
|
||||
},
|
||||
sort: {
|
||||
isEnabled: true,
|
||||
value: "file-name-asc",
|
||||
|
|
|
|||
|
|
@ -136,21 +136,6 @@ export default class VaultExplorerSettingsTab extends PluginSettingTab {
|
|||
})
|
||||
);
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName("Timestamp filter")
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(this.plugin.settings.filters.timestamp.isEnabled)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.filters.timestamp.isEnabled =
|
||||
value;
|
||||
await this.plugin.saveSettings();
|
||||
EventManager.getInstance().emit(
|
||||
PluginEvent.FILTER_TOGGLE_SETTING_CHANGE
|
||||
);
|
||||
})
|
||||
);
|
||||
|
||||
new Setting(containerEl).setName("Sort filter").addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(this.plugin.settings.filters.sort.isEnabled)
|
||||
|
|
|
|||
|
|
@ -1,67 +0,0 @@
|
|||
<script lang="ts">
|
||||
import { Menu } from "obsidian";
|
||||
import IconButton from "src/svelte/shared/components/icon-button.svelte";
|
||||
import { TimestampFilterOption } from "src/types";
|
||||
import { createEventDispatcher } from "svelte";
|
||||
|
||||
export let value: TimestampFilterOption;
|
||||
|
||||
const dispatch = createEventDispatcher();
|
||||
|
||||
function handleValueChange(value: TimestampFilterOption) {
|
||||
dispatch("change", { value });
|
||||
}
|
||||
|
||||
function handleButtonClick(e: CustomEvent) {
|
||||
const nativeEvent = e.detail.nativeEvent as MouseEvent;
|
||||
|
||||
const menu = new Menu();
|
||||
menu.setUseNativeMenu(true);
|
||||
|
||||
menu.addItem((item) => {
|
||||
item.setTitle("All");
|
||||
item.setChecked(value === "all");
|
||||
item.onClick(() => handleValueChange("all"));
|
||||
});
|
||||
menu.addSeparator();
|
||||
menu.addItem((item) => {
|
||||
item.setTitle("Modified today");
|
||||
item.setChecked(value === "modified-today");
|
||||
item.onClick(() => handleValueChange("modified-today"));
|
||||
});
|
||||
menu.addItem((item) => {
|
||||
item.setTitle("Created today");
|
||||
item.setChecked(value === "created-today");
|
||||
item.onClick(() => handleValueChange("created-today"));
|
||||
});
|
||||
menu.addSeparator();
|
||||
menu.addItem((item) => {
|
||||
item.setTitle("Modifed this week");
|
||||
item.setChecked(value === "modified-this-week");
|
||||
item.onClick(() => handleValueChange("modified-this-week"));
|
||||
});
|
||||
menu.addItem((item) => {
|
||||
item.setTitle("Created this week");
|
||||
item.setChecked(value === "created-this-week");
|
||||
item.onClick(() => handleValueChange("created-this-week"));
|
||||
});
|
||||
menu.addSeparator();
|
||||
menu.addItem((item) => {
|
||||
item.setTitle("Modifed 2 weeks");
|
||||
item.setChecked(value === "modified-2-weeks");
|
||||
item.onClick(() => handleValueChange("modified-2-weeks"));
|
||||
});
|
||||
menu.addItem((item) => {
|
||||
item.setTitle("Created 2 weeks");
|
||||
item.setChecked(value === "created-2-weeks");
|
||||
item.onClick(() => handleValueChange("created-2-weeks"));
|
||||
});
|
||||
menu.showAtMouseEvent(nativeEvent);
|
||||
}
|
||||
</script>
|
||||
|
||||
<IconButton
|
||||
ariaLabel="Change timestamp filter"
|
||||
iconId="clock"
|
||||
on:click={handleButtonClick}
|
||||
/>
|
||||
|
|
@ -11,7 +11,6 @@
|
|||
TCustomFilter,
|
||||
TSearchFilter,
|
||||
TSortFilter,
|
||||
TTimestampFilter,
|
||||
TExplorerView,
|
||||
CoverImageFit,
|
||||
} from "src/types";
|
||||
|
|
@ -20,7 +19,6 @@
|
|||
import GridView from "./components/grid-view.svelte";
|
||||
import ListView from "./components/list-view.svelte";
|
||||
import { filterBySearch } from "./services/filters/search-filter";
|
||||
import { filterByTimestamp } from "./services/filters/timestamp-filter";
|
||||
import { filterByGroups } from "./services/filters/custom/filter-by-groups";
|
||||
import { formatFileDataForRender } from "./services/render-data";
|
||||
import _ from "lodash";
|
||||
|
|
@ -35,7 +33,6 @@
|
|||
import { FileRenderData } from "./types";
|
||||
import Logger from "js-logger";
|
||||
import SearchFilter from "./components/search-filter.svelte";
|
||||
import TimestampFilter from "./components/timestamp-filter.svelte";
|
||||
import SortFilter from "./components/sort-filter.svelte";
|
||||
import { DEBOUNCE_INPUT_TIME, SCREEN_SIZE_MD } from "./constants";
|
||||
import FeedView from "./components/feed-view.svelte";
|
||||
|
|
@ -79,10 +76,6 @@
|
|||
isEnabled: true,
|
||||
value: "",
|
||||
};
|
||||
let timestampFilter: TTimestampFilter = {
|
||||
isEnabled: true,
|
||||
value: "all",
|
||||
};
|
||||
let sortFilter: TSortFilter = {
|
||||
isEnabled: true,
|
||||
value: "file-name-asc",
|
||||
|
|
@ -140,7 +133,6 @@
|
|||
pageSize = settings.pageSize;
|
||||
searchFilter = settings.filters.search;
|
||||
sortFilter = settings.filters.sort;
|
||||
timestampFilter = settings.filters.timestamp;
|
||||
currentView = settings.currentView;
|
||||
customFilter = settings.filters.custom;
|
||||
viewOrder = settings.viewOrder;
|
||||
|
|
@ -164,7 +156,6 @@
|
|||
|
||||
searchFilter = plugin.settings.filters.search;
|
||||
sortFilter = plugin.settings.filters.sort;
|
||||
timestampFilter = plugin.settings.filters.timestamp;
|
||||
customFilter = plugin.settings.filters.custom;
|
||||
}
|
||||
|
||||
|
|
@ -606,7 +597,6 @@
|
|||
async function saveSettings() {
|
||||
plugin.settings.filters.search = searchFilter;
|
||||
plugin.settings.filters.sort = sortFilter;
|
||||
plugin.settings.filters.timestamp = timestampFilter;
|
||||
plugin.settings.currentView = currentView;
|
||||
plugin.settings.filters.custom = customFilter;
|
||||
plugin.settings.viewOrder = viewOrder;
|
||||
|
|
@ -663,11 +653,6 @@
|
|||
nativeEvent.preventDefault();
|
||||
}
|
||||
|
||||
function handleTimestampFilterChange(e: CustomEvent) {
|
||||
const { value } = e.detail;
|
||||
timestampFilter.value = value;
|
||||
}
|
||||
|
||||
function handleViewDragStart(e: CustomEvent, id: string) {
|
||||
const { nativeEvent } = e.detail;
|
||||
nativeEvent.dataTransfer.setData("text", id);
|
||||
|
|
@ -891,19 +876,7 @@
|
|||
return true;
|
||||
});
|
||||
|
||||
$: filteredTimestamp = filteredSearch.filter((file) => {
|
||||
const { modifiedMillis, createdMillis } = file;
|
||||
return filterByTimestamp({
|
||||
value: timestampFilter.value,
|
||||
createdMillis,
|
||||
modifiedMillis,
|
||||
startOfTodayMillis,
|
||||
startOfThisWeekMillis,
|
||||
startOfLastWeekMillis,
|
||||
});
|
||||
});
|
||||
|
||||
$: renderData = [...filteredTimestamp].sort((a, b) => {
|
||||
$: renderData = [...filteredSearch].sort((a, b) => {
|
||||
const { value } = sortFilter;
|
||||
if (value === "file-name-asc") {
|
||||
return a.displayName
|
||||
|
|
@ -932,7 +905,6 @@
|
|||
//and save the settings again
|
||||
$: searchFilter,
|
||||
sortFilter,
|
||||
timestampFilter,
|
||||
currentView,
|
||||
customFilter,
|
||||
viewOrder,
|
||||
|
|
@ -1012,12 +984,6 @@
|
|||
<!-- </Stack> -->
|
||||
</div>
|
||||
<Flex>
|
||||
{#if timestampFilter.isEnabled}
|
||||
<TimestampFilter
|
||||
value={timestampFilter.value}
|
||||
on:change={handleTimestampFilterChange}
|
||||
/>
|
||||
{/if}
|
||||
{#if sortFilter.isEnabled}
|
||||
<SortFilter
|
||||
value={sortFilter.value}
|
||||
|
|
|
|||
|
|
@ -1,34 +0,0 @@
|
|||
import { TimestampFilterOption } from "src/types";
|
||||
|
||||
interface FilterByTimestampParams {
|
||||
value: TimestampFilterOption;
|
||||
createdMillis: number;
|
||||
modifiedMillis: number;
|
||||
startOfTodayMillis: number;
|
||||
startOfThisWeekMillis: number;
|
||||
startOfLastWeekMillis: number;
|
||||
}
|
||||
|
||||
export const filterByTimestamp = ({
|
||||
value,
|
||||
createdMillis,
|
||||
modifiedMillis,
|
||||
startOfTodayMillis,
|
||||
startOfThisWeekMillis,
|
||||
startOfLastWeekMillis,
|
||||
}: FilterByTimestampParams) => {
|
||||
if (value === "modified-this-week") {
|
||||
return modifiedMillis > startOfThisWeekMillis;
|
||||
} else if (value === "created-this-week") {
|
||||
return createdMillis > startOfThisWeekMillis;
|
||||
} else if (value === "modified-2-weeks") {
|
||||
return modifiedMillis > startOfLastWeekMillis;
|
||||
} else if (value === "created-2-weeks") {
|
||||
return createdMillis > startOfLastWeekMillis;
|
||||
} else if (value === "modified-today") {
|
||||
return modifiedMillis > startOfTodayMillis;
|
||||
} else if (value === "created-today") {
|
||||
return createdMillis > startOfTodayMillis;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
@ -39,17 +39,6 @@ export function isVaultExplorerPluginSettings(obj: unknown): obj is VaultExplore
|
|||
typedObj["filters"]["sort"]["value"] === "modified-asc" ||
|
||||
typedObj["filters"]["sort"]["value"] === "modified-desc" ||
|
||||
typedObj["filters"]["sort"]["value"] === "random") &&
|
||||
(typedObj["filters"]["timestamp"] !== null &&
|
||||
typeof typedObj["filters"]["timestamp"] === "object" ||
|
||||
typeof typedObj["filters"]["timestamp"] === "function") &&
|
||||
typeof typedObj["filters"]["timestamp"]["isEnabled"] === "boolean" &&
|
||||
(typedObj["filters"]["timestamp"]["value"] === "created-today" ||
|
||||
typedObj["filters"]["timestamp"]["value"] === "modified-today" ||
|
||||
typedObj["filters"]["timestamp"]["value"] === "created-this-week" ||
|
||||
typedObj["filters"]["timestamp"]["value"] === "modified-this-week" ||
|
||||
typedObj["filters"]["timestamp"]["value"] === "created-2-weeks" ||
|
||||
typedObj["filters"]["timestamp"]["value"] === "modified-2-weeks" ||
|
||||
typedObj["filters"]["timestamp"]["value"] === "all") &&
|
||||
(typedObj["filters"]["custom"] !== null &&
|
||||
typeof typedObj["filters"]["custom"] === "object" ||
|
||||
typeof typedObj["filters"]["custom"] === "function") &&
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ export interface VaultExplorerPluginSettings {
|
|||
filters: {
|
||||
search: TSearchFilter;
|
||||
sort: TSortFilter;
|
||||
timestamp: TTimestampFilter;
|
||||
custom: TCustomFilter;
|
||||
};
|
||||
views: {
|
||||
|
|
@ -100,24 +99,11 @@ export interface TSortFilter extends BaseFilter {
|
|||
value: SortFilterOption;
|
||||
}
|
||||
|
||||
export interface TTimestampFilter extends BaseFilter {
|
||||
value: TimestampFilterOption;
|
||||
}
|
||||
|
||||
export interface TCustomFilter extends BaseFilter {
|
||||
selectedGroupId: string;
|
||||
groups: TFilterGroup[];
|
||||
}
|
||||
|
||||
export type TimestampFilterOption =
|
||||
| "created-today"
|
||||
| "modified-today"
|
||||
| "created-this-week"
|
||||
| "modified-this-week"
|
||||
| "created-2-weeks"
|
||||
| "modified-2-weeks"
|
||||
| "all";
|
||||
|
||||
export type SortFilterOption =
|
||||
| "file-name-asc"
|
||||
| "file-name-desc"
|
||||
|
|
|
|||
Loading…
Reference in a new issue