-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Sync settings and stock per-project
- Loading branch information
Showing
34 changed files
with
347 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,48 @@ | ||
<script lang="ts" setup> | ||
import { StockMatrix } from '@aklinker1/cutlist'; | ||
import { z } from 'zod'; | ||
import YAML from 'js-yaml'; | ||
import { reduceStockMatrix } from '@aklinker1/cutlist'; | ||
const model = defineModel<StockMatrix[]>(); | ||
const value = defineModel<string>({ required: true }); | ||
const getModelString = () => | ||
YAML.dump(model.value, { indent: 2, flowLevel: 2 }); | ||
const text = ref(getModelString()); | ||
const internalValue = ref(value.value); | ||
onMounted(() => { | ||
internalValue.value = value.value; | ||
}); | ||
const textModel = computed<string>({ | ||
get() { | ||
return text.value; | ||
}, | ||
set(value) { | ||
const parseStock = useParseStock(); | ||
const err = ref<unknown>(); | ||
watchThrottled( | ||
internalValue, | ||
(internalValue) => { | ||
try { | ||
text.value = value; | ||
model.value = z.array(StockMatrix).parse(YAML.load(value)); | ||
error.value = undefined; | ||
} catch (err) { | ||
error.value = err; | ||
console.log(1); | ||
const stock = reduceStockMatrix(parseStock(internalValue)); | ||
console.log(2, stock); | ||
value.value = internalValue; | ||
err.value = undefined; | ||
} catch (error) { | ||
err.value = error; | ||
console.error(error); | ||
} | ||
}, | ||
}); | ||
const error = ref<unknown>(); | ||
{ | ||
throttle: 500, | ||
leading: false, | ||
trailing: true, | ||
}, | ||
); | ||
</script> | ||
|
||
<template> | ||
<div class="absolute inset-0 flex flex-col p-4 overlfow-auto gap-4"> | ||
<textarea | ||
v-model="textModel" | ||
class="font-mono flex-1 resize-none bg-white dark:bg-gray-900 border border-gray-300 dark:border-gray-700 p-4 outline-none rounded-lg whitespace-pre" | ||
/> | ||
<div | ||
v-if="error" | ||
class="bg-red-900 shrink-0 p-4 rounded-lg border border-red-600" | ||
> | ||
<p class="text-white whitespace-pre-wrap"> | ||
{{ error }} | ||
</p> | ||
</div> | ||
<textarea | ||
v-model="internalValue" | ||
class="font-mono flex-1 resize-none bg-white dark:bg-gray-900 border border-gray-300 dark:border-gray-700 p-4 outline-none rounded-lg whitespace-pre" | ||
/> | ||
<div | ||
v-if="err" | ||
class="bg-red-900 shrink-0 p-4 rounded-lg border border-red-600" | ||
> | ||
<p class="text-white whitespace-pre-wrap"> | ||
{{ err }} | ||
</p> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,33 @@ | ||
<script lang="ts" setup> | ||
const { data } = useBoardLayoutsQuery(); | ||
const { stock, resetStock } = useProjectSettings(); | ||
const stock = useStock(); | ||
const projectId = useProjectId(); | ||
const { mutate: _save, isPending: isSaving } = useSetSettingsMutation(); | ||
function save() { | ||
console.log('SAVING...'); | ||
_save({ | ||
projectId: projectId.value, | ||
changes: { stock: stock.value }, | ||
}); | ||
} | ||
const { mutate: _reset, isPending: isResetting } = useDeleteSettingsMutation(); | ||
function reset() { | ||
_reset(projectId.value, { | ||
onSettled: () => resetStock(), | ||
}); | ||
} | ||
</script> | ||
|
||
<template> | ||
<StockMatrixInput v-model="stock" /> | ||
<div class="absolute inset-0 flex flex-col p-4 gap-4"> | ||
<StockMatrixInput v-if="stock != null" v-model="stock" /> | ||
|
||
<div class="shrink-0 flex flex-row-reverse gap-4"> | ||
<UButton type="submit" :loading="isSaving" @click="save">Save</UButton> | ||
<UButton color="gray" :loading="isResetting" @click="reset" | ||
>Reset</UButton | ||
> | ||
</div> | ||
</div> | ||
</template> |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { useMutation, useQueryClient } from '@tanstack/vue-query'; | ||
|
||
export default function () { | ||
const accountService = useAccountService(); | ||
const client = useQueryClient(); | ||
|
||
return useMutation({ | ||
mutationFn(projectId: string | undefined) { | ||
return accountService.value.deleteSettings(projectId); | ||
}, | ||
onSettled() { | ||
client.invalidateQueries({ | ||
queryKey: ['settings'], | ||
}); | ||
}, | ||
}); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.