Skip to content

feat: reset editor files #314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,16 @@ const refreshPreview = () => {
replRef.value?.reload()
}

const resetFiles = () => {
store.resetFiles()
}

watch(autoSave, setAutoSaveState)
</script>

<template>
<div v-if="!loading" antialiased>
<Header :store="store" @refresh="refreshPreview" />
<Header :store="store" @refresh="refreshPreview" @reset="resetFiles" />
<Repl
ref="replRef"
v-model="autoSave"
Expand Down
1 change: 1 addition & 0 deletions src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export {}
/* prettier-ignore */
declare module 'vue' {
export interface GlobalComponents {
ElButton: typeof import('element-plus/es')['ElButton']
ElCheckbox: typeof import('element-plus/es')['ElCheckbox']
ElForm: typeof import('element-plus/es')['ElForm']
ElFormItem: typeof import('element-plus/es')['ElFormItem']
Expand Down
26 changes: 26 additions & 0 deletions src/components/Header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ const replVersion = import.meta.env.REPL_VERSION

const emit = defineEmits<{
(e: 'refresh'): void
(e: 'reset'): void
}>()
const nightly = ref(false)
const showReset = ref(false)
const dark = useDark()
const toggleDark = useToggle(dark)

Expand Down Expand Up @@ -65,6 +67,10 @@ async function copyLink() {
function refreshView() {
emit('refresh')
}
function resetFiles() {
showReset.value = false
emit('reset')
}
</script>

<template>
Expand Down Expand Up @@ -140,6 +146,26 @@ function refreshView() {
</div>

<div flex="~ gap-4" text-lg>
<el-popover
v-model:visible="showReset"
popper-class="flex flex-col gap-1"
trigger="click"
width="200px"
>
<div flex justify-center>Want to reset the editor ?</div>
<el-button
flex
self-end
size="small"
type="primary"
@click="resetFiles"
>
Yes
</el-button>
<template #reference>
<button i-ri-delete-bin-line hover:color-primary />
</template>
</el-popover>
<button
i-ri-refresh-line
title="Refresh sandbox"
Expand Down
15 changes: 15 additions & 0 deletions src/composables/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,28 @@ export const useStore = (initial: Initial) => {
}
}

const resetFiles = () => {
const { files, addFile } = store

const isRandomFile = (filename: string) =>
![MAIN_FILE, TSCONFIG, IMPORT_MAP, ELEMENT_PLUS_FILE].includes(
filename,
)
for (const filename in files)
if (isRandomFile(filename)) delete files[filename]

const appFile = new File(APP_FILE, welcomeCode, false)
addFile(appFile)
}

const utils = {
versions,
pr,
setVersion,
toggleNightly,
serialize,
init,
resetFiles,
}
Object.assign(store, utils)

Expand Down